#[non_exhaustive]pub struct RcfConfig {
pub num_trees: usize,
pub sample_size: usize,
pub time_decay: f64,
pub seed: Option<u64>,
pub num_threads: Option<usize>,
pub initial_accept_fraction: f64,
pub feature_scales: Option<Vec<f64>>,
}Expand description
Validated forest hyperparameters (dimension is encoded separately at the type level).
§Examples
use anomstream_core::{ForestBuilder, RcfConfig};
let builder = ForestBuilder::<4>::new()
.num_trees(50)
.sample_size(64);
let cfg: &RcfConfig = builder.config();
assert_eq!(cfg.num_trees, 50);
cfg.validate().unwrap();Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.num_trees: usizeNumber of trees in the forest (num_trees).
sample_size: usizeMaximum reservoir size per tree (num_samples_per_tree).
time_decay: f64Time-decay factor applied to reservoir sampling weights. A
value of 0.0 restores strict uniform sampling; positive
values bias the reservoir toward recent points. Default
resolved by ForestBuilder is 0.1 / sample_size, matching
the AWS Java CompactSampler reference.
seed: Option<u64>Optional deterministic seed; None falls back to entropy.
num_threads: Option<usize>Optional dedicated rayon thread pool size for the parallel
cargo feature. None means “use rayon’s global pool”
(configurable via the RAYON_NUM_THREADS env var). Some(n)
builds a per-forest rayon::ThreadPool of n workers so
callers can isolate this forest from the rest of the
application’s rayon workload. Ignored without parallel.
initial_accept_fraction: f64Warmup admission fraction forwarded to every per-tree
crate::ReservoirSampler. See that type’s module-level docs
for semantics. 1.0 disables the gate; smaller values ramp
admission during the cold-start period so the reservoir is
less dominated by the first few stream entries.
feature_scales: Option<Vec<f64>>Optional per-dimension multiplicative weights applied to every
point before it reaches the forest’s hot paths (update,
score, attribution, bootstrap, delete_by_value). Length
must match the forest’s compile-time dimension D.
Intended for per-feature scale normalisation: when different
input dimensions have wildly different dynamic ranges
(packet-rate in [10², 10⁶], protocol-mix ratios in [0, 1],
entropy in [0, 8] bits), a naive random cut weights each
dimension by its raw range. Pre-scaling with 1 / stddev[d]
recovers a unit-variance input space where every dim pulls
its weight. For full z-score normalisation the caller should
still mean-centre upstream — feature_scales is a weight, not
a full affine transform.
None keeps the classic “forest sees the raw caller point”
behaviour. The field is #[serde(default)] so old snapshots
deserialise without migration.
Implementations§
Source§impl RcfConfig
impl RcfConfig
Sourcepub fn validate(&self) -> RcfResult<()>
pub fn validate(&self) -> RcfResult<()>
Validate the configuration against the AWS hyperparameter
bounds. The forest’s compile-time dimension D is checked
separately via Self::validate_dimension so non-const
callers can apply the AWS bounds without instantiating a
generic.
§Errors
Returns RcfError::InvalidConfig with the offending
parameter when any bound is violated.
Sourcepub fn validate_feature_scales_dimension(&self, d: usize) -> RcfResult<()>
pub fn validate_feature_scales_dimension(&self, d: usize) -> RcfResult<()>
Validate the declared RcfConfig::feature_scales against a
target per-point dimension d. When feature_scales is
None, the check is a no-op.
§Errors
Returns RcfError::DimensionMismatch when the scales vector
length does not equal d.
Sourcepub fn validate_dimension(dimension: usize) -> RcfResult<()>
pub fn validate_dimension(dimension: usize) -> RcfResult<()>
Validate the compile-time dimension D against the AWS
feature_dim bounds. Called by ForestBuilder::build so
every user-facing entry point gates on the AWS limits.
§Errors
Returns RcfError::InvalidConfig when D is outside
[MIN_DIMENSION, MAX_DIMENSION].
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RcfConfig
impl<'de> Deserialize<'de> for RcfConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for RcfConfig
Auto Trait Implementations§
impl Freeze for RcfConfig
impl RefUnwindSafe for RcfConfig
impl Send for RcfConfig
impl Sync for RcfConfig
impl Unpin for RcfConfig
impl UnsafeUnpin for RcfConfig
impl UnwindSafe for RcfConfig
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