pub struct ContextTree {
pub contexts: HashMap<Vec<String>, ContextNode>,
pub max_order: usize,
}Expand description
Context tree for storing variable-order Markov chain contexts
Fields§
§contexts: HashMap<Vec<String>, ContextNode>Map from context sequences to context nodes
max_order: usizeMaximum context order (length)
Implementations§
Source§impl ContextTree
impl ContextTree
Sourcepub fn new(max_order: usize) -> AnomalyGridResult<Self>
pub fn new(max_order: usize) -> AnomalyGridResult<Self>
Create a new context tree with specified maximum order
Sourcepub fn build_from_sequence(
&mut self,
sequence: &[String],
config: &AnomalyGridConfig,
) -> AnomalyGridResult<()>
pub fn build_from_sequence( &mut self, sequence: &[String], config: &AnomalyGridConfig, ) -> AnomalyGridResult<()>
Sourcepub fn get_transition_probability(
&self,
context: &[String],
next_state: &str,
) -> Option<f64>
pub fn get_transition_probability( &self, context: &[String], next_state: &str, ) -> Option<f64>
Get the transition probability for a given context and next state
Sourcepub fn get_context_node(&self, context: &[String]) -> Option<&ContextNode>
pub fn get_context_node(&self, context: &[String]) -> Option<&ContextNode>
Get a context node for the given context
Sourcepub fn get_contexts_of_order(&self, order: usize) -> Vec<&Vec<String>>
pub fn get_contexts_of_order(&self, order: usize) -> Vec<&Vec<String>>
Get all contexts of a specific order
Sourcepub fn context_count(&self) -> usize
pub fn context_count(&self) -> usize
Get the number of contexts stored
Source§impl ContextTree
Context pruning for memory optimization
impl ContextTree
Context pruning for memory optimization
Sourcepub fn prune_low_frequency_contexts(&mut self, min_count: usize) -> usize
pub fn prune_low_frequency_contexts(&mut self, min_count: usize) -> usize
Remove low-frequency contexts to reduce memory usage
This removes contexts that have been observed fewer than min_count times,
which can significantly reduce memory usage for large alphabets.
Sourcepub fn prune_low_entropy_contexts(&mut self, min_entropy: f64) -> usize
pub fn prune_low_entropy_contexts(&mut self, min_entropy: f64) -> usize
Remove contexts with low entropy (deterministic contexts)
Contexts with very low entropy provide little information and can be pruned to reduce memory usage while maintaining detection accuracy.
Sourcepub fn keep_top_contexts(&mut self, max_contexts: usize) -> usize
pub fn keep_top_contexts(&mut self, max_contexts: usize) -> usize
Keep only the most frequent contexts up to a maximum count
This is useful for memory-constrained environments where you want to keep only the most important contexts.
Sourcepub fn estimate_memory_usage(&self) -> usize
pub fn estimate_memory_usage(&self) -> usize
Estimate memory usage of the context tree
Sourcepub fn get_context_statistics(&self) -> ContextStatistics
pub fn get_context_statistics(&self) -> ContextStatistics
Get context statistics for analysis
Trait Implementations§
Source§impl Clone for ContextTree
impl Clone for ContextTree
Source§fn clone(&self) -> ContextTree
fn clone(&self) -> ContextTree
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 ContextTree
impl RefUnwindSafe for ContextTree
impl Send for ContextTree
impl Sync for ContextTree
impl Unpin for ContextTree
impl UnwindSafe for ContextTree
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