From ee78b8e298f4cc42d7f0a6191aeb5e0dba9dee03 Mon Sep 17 00:00:00 2001 From: Adil Zouitine Date: Sat, 21 Oct 2023 18:09:58 +0200 Subject: [PATCH] Add max score normalisation --- src/anomaly/half_space_tree.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/anomaly/half_space_tree.rs b/src/anomaly/half_space_tree.rs index 2701fed..bbdae3b 100644 --- a/src/anomaly/half_space_tree.rs +++ b/src/anomaly/half_space_tree.rs @@ -192,6 +192,7 @@ impl H } } if do_score { + score = F::one() - (score / self.max_score()); return Some(score); } return None; @@ -202,4 +203,9 @@ impl H pub fn score_one(&mut self, observation: &Observation) -> Option { self.update(observation, true, false) } + fn max_score(&self) -> F { + F::from(self.n_trees).unwrap() + * F::from(self.window_size).unwrap() + * (F::from(2.).unwrap().powi(self.height as i32 + 1) - F::one()) + } }