pub struct TransitionCounter<S: Eq + Hash + Clone> { /* private fields */ }Expand description
In-memory frequency matrix for (from, to) transition counting.
Generic over state type S (typically String for screen IDs).
Implementations§
Source§impl<S: Eq + Hash + Clone> TransitionCounter<S>
impl<S: Eq + Hash + Clone> TransitionCounter<S>
Sourcepub fn with_config(smoothing_alpha: f64, prune_threshold: f64) -> Self
pub fn with_config(smoothing_alpha: f64, prune_threshold: f64) -> Self
Create a counter with custom smoothing alpha and prune threshold.
Sourcepub fn record(&mut self, from: S, to: S)
pub fn record(&mut self, from: S, to: S)
Record a single transition from from to to (increments by 1.0).
Sourcepub fn record_with_count(&mut self, from: S, to: S, count: f64)
pub fn record_with_count(&mut self, from: S, to: S, count: f64)
Record a transition with an explicit count (used by persistence layer).
Sourcepub fn total_from(&self, from: &S) -> f64
pub fn total_from(&self, from: &S) -> f64
Get the total transitions originating from from.
Sourcepub fn probability(&self, from: &S, to: &S) -> f64
pub fn probability(&self, from: &S, to: &S) -> f64
Compute the probability of transitioning from from to to.
Uses Laplace (additive) smoothing:
P(to|from) = (count(from,to) + alpha) / (total_from(from) + alpha * N)
where N is the number of known target states from from.
Returns a uniform estimate if from has no recorded transitions.
Sourcepub fn all_targets_ranked(&self, from: &S) -> Vec<(S, f64)>
pub fn all_targets_ranked(&self, from: &S) -> Vec<(S, f64)>
Return all known targets from from, ranked by probability (descending).
Sourcepub fn merge(&mut self, other: &TransitionCounter<S>)
pub fn merge(&mut self, other: &TransitionCounter<S>)
Merge another counter into this one (additive).
Trait Implementations§
Source§impl<S: Clone + Eq + Hash + Clone> Clone for TransitionCounter<S>
impl<S: Clone + Eq + Hash + Clone> Clone for TransitionCounter<S>
Source§fn clone(&self) -> TransitionCounter<S>
fn clone(&self) -> TransitionCounter<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more