pub struct HalfSpaceTree { /* private fields */ }Expand description
A Half-Space Trees ensemble for streaming anomaly detection.
§Example
use irithyll::anomaly::hst::{HalfSpaceTree, HSTConfig};
let config = HSTConfig::new(3).n_trees(25).window_size(100);
let mut hst = HalfSpaceTree::new(config);
// Feed normal data to build a reference profile
for i in 0..200 {
let features = vec![i as f64 * 0.01, 0.5, 0.3];
hst.update(&features);
}
// Score a point
let result = hst.score(&[0.5, 0.5, 0.3]);
println!("anomaly score: {:.3}, is_anomaly: {}", result.score, result.is_anomaly);Implementations§
Source§impl HalfSpaceTree
impl HalfSpaceTree
Sourcepub fn with_ranges(config: HSTConfig, ranges: &[(f64, f64)]) -> Self
pub fn with_ranges(config: HSTConfig, ranges: &[(f64, f64)]) -> Self
Create a new ensemble with explicit working ranges per feature.
ranges should contain (min, max) for each feature dimension.
This improves partitioning quality when feature ranges are known.
Sourcepub fn update(&mut self, features: &[f64])
pub fn update(&mut self, features: &[f64])
Feed a sample to the ensemble, updating mass profiles.
When window_size samples have been seen, the latest profile
rotates to become the reference and counting restarts.
Sourcepub fn score(&self, features: &[f64]) -> AnomalyScore
pub fn score(&self, features: &[f64]) -> AnomalyScore
Score a sample for anomalousness.
Returns an AnomalyScore with a normalized score in [0, 1]
(inverted so higher = more anomalous) and an is_anomaly flag.
Sourcepub fn score_and_update(&mut self, features: &[f64]) -> AnomalyScore
pub fn score_and_update(&mut self, features: &[f64]) -> AnomalyScore
Combined update + score in one pass.
The sample is scored BEFORE being incorporated into the mass profile, so the score reflects how anomalous it is relative to past data.
Sourcepub fn samples_seen(&self) -> u64
pub fn samples_seen(&self) -> u64
Total samples processed.
Sourcepub fn windows_completed(&self) -> u64
pub fn windows_completed(&self) -> u64
Number of complete window rotations performed.
Trait Implementations§
Source§impl Clone for HalfSpaceTree
impl Clone for HalfSpaceTree
Source§fn clone(&self) -> HalfSpaceTree
fn clone(&self) -> HalfSpaceTree
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for HalfSpaceTree
impl RefUnwindSafe for HalfSpaceTree
impl Send for HalfSpaceTree
impl Sync for HalfSpaceTree
impl Unpin for HalfSpaceTree
impl UnsafeUnpin for HalfSpaceTree
impl UnwindSafe for HalfSpaceTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more