Skip to main content

ForestBuilder

Struct ForestBuilder 

Source
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>

Source

pub fn new() -> Self

Start a new builder for D-dimensional points.

Source

pub fn num_trees(self, n: usize) -> Self

Override the number of trees.

Source

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.

Source

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.

Source

pub fn seed(self, seed: u64) -> Self

Pin the RNG seed for reproducible runs.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn config(&self) -> &RcfConfig

Read-only access to the config under construction.

Source

pub const fn dimension(&self) -> usize

Per-point dimensionality (compile-time D).

Source

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>

Source§

fn clone(&self) -> ForestBuilder<D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const D: usize> Debug for ForestBuilder<D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const D: usize> Default for ForestBuilder<D>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V