pub struct ForestBuilder<const D: usize> { /* private fields */ }Expand description
Fluent builder for RandomCutForest.
Defaults: num_trees = 100, sample_size = 256,
time_decay = 0.1 / sample_size (matches AWS Java
CompactSampler; call Self::time_decay with 0.0 to recover
strict uniform sampling), RNG seeded from entropy.
D is the per-point dimensionality. Callers pin it at construction
via turbofish: ForestBuilder::<4>::new().
§Examples
use anomstream_core::ForestBuilder;
let mut forest = ForestBuilder::<4>::new()
.num_trees(50)
.sample_size(64)
.seed(42)
.build()
.expect("AWS-conformant config");
forest.update([0.0, 0.0, 0.0, 0.0]).expect("dim matches");Implementations§
Source§impl<const D: usize> ForestBuilder<D>
impl<const D: usize> ForestBuilder<D>
Sourcepub fn sample_size(self, s: usize) -> Self
pub fn sample_size(self, s: usize) -> Self
Override the per-tree reservoir size. When time_decay has
not been explicitly set via Self::time_decay, the default
0.1 / sample_size is re-resolved against the new value so
the effective recency bias stays consistent with AWS’s
CompactSampler formula.
Sourcepub fn time_decay(self, d: f64) -> Self
pub fn time_decay(self, d: f64) -> Self
Override the sampler time-decay factor. Pass 0.0 to disable
recency bias and recover strict uniform reservoir sampling.
Once called, the builder stops auto-resolving time_decay
from subsequent Self::sample_size changes — the caller’s
choice wins.
Sourcepub fn num_threads(self, n: usize) -> Self
pub fn num_threads(self, n: usize) -> Self
Build a dedicated rayon thread pool of size n for this
forest’s parallel score / attribution / update paths.
Requires the parallel cargo feature. When unset (default)
rayon’s global pool is used.
Sourcepub fn initial_accept_fraction(self, f: f64) -> Self
pub fn initial_accept_fraction(self, f: f64) -> Self
Override the warmup admission fraction forwarded to each
per-tree reservoir. See
crate::ReservoirSampler module-level docs for semantics.
1.0 (the default) disables the gate; AWS’s CompactSampler
uses 0.125.
Sourcepub fn feature_scales(self, scales: [f64; D]) -> Self
pub fn feature_scales(self, scales: [f64; D]) -> Self
Set per-dimension multiplicative weights applied to every
point before it reaches the forest’s hot paths. See
RcfConfig::feature_scales for semantics. Pass the exact
[f64; D] array — length is checked against the builder’s
compile-time D at Self::build time, contents are
checked for finiteness and positivity by
RcfConfig::validate.
Sourcepub fn clear_feature_scales(self) -> Self
pub fn clear_feature_scales(self) -> Self
Drop any previously-set feature_scales — returns the builder
to the unweighted state. Useful for tests that want to clear a
shared template’s scale vector before building a specialised
forest.
Sourcepub fn build(self) -> RcfResult<RandomCutForest<D>>
pub fn build(self) -> RcfResult<RandomCutForest<D>>
Validate the config and instantiate the forest.
§Errors
Forwards RcfConfig::validate errors and propagates any
failure from the underlying RandomCutForest constructor.
Trait Implementations§
Source§impl<const D: usize> Clone for ForestBuilder<D>
impl<const D: usize> Clone for ForestBuilder<D>
Source§fn clone(&self) -> ForestBuilder<D>
fn clone(&self) -> ForestBuilder<D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const D: usize> Debug for ForestBuilder<D>
impl<const D: usize> Debug for ForestBuilder<D>
Auto Trait Implementations§
impl<const D: usize> Freeze for ForestBuilder<D>
impl<const D: usize> RefUnwindSafe for ForestBuilder<D>
impl<const D: usize> Send for ForestBuilder<D>
impl<const D: usize> Sync for ForestBuilder<D>
impl<const D: usize> Unpin for ForestBuilder<D>
impl<const D: usize> UnsafeUnpin for ForestBuilder<D>
impl<const D: usize> UnwindSafe for ForestBuilder<D>
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> 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