Skip to main content

HmmFitControl

Struct HmmFitControl 

Source
pub struct HmmFitControl {
    pub seed: u64,
    pub max_iterations: usize,
    pub tolerance: f64,
    pub max_work: u64,
    pub probability_floor: f64,
}
Expand description

Deterministic initialization, convergence, and work policy for Baum-Welch.

Fields§

§seed: u64

Caller-owned deterministic initialization seed.

§max_iterations: usize

Hard maximum number of accepted Baum-Welch updates.

§tolerance: f64

Relative log-likelihood convergence tolerance.

§max_work: u64

Hard maximum charged state-transition work.

§probability_floor: f64

Probability floor used while normalizing fitted rows.

Implementations§

Source§

impl HmmFitControl

Source

pub fn new( seed: u64, max_iterations: usize, tolerance: f64, max_work: u64, probability_floor: f64, ) -> Result<Self, HmmError>

Builds checked fitting control.

Examples found in repository?
examples/bounded_sequence_inference.rs (line 49)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let policy = QuantilePolicy::new(0.02, 8, 256)?;
8    let mut left = QuantileSketch::new(policy.clone())?;
9    let mut right = QuantileSketch::new(policy)?;
10    for value in 0..100 {
11        if value % 2 == 0 {
12            left.insert(value as f64)?;
13        } else {
14            right.insert(value as f64)?;
15        }
16    }
17    left.merge(&right)?;
18    let median = left.estimate(0.5)?;
19    println!(
20        "quantile value={} rank=[{:.3},{:.3}] retained={} exact={}",
21        median.value, median.rank_lower, median.rank_upper, median.retained_entries, median.exact
22    );
23
24    let model = HiddenMarkovModel::discrete(
25        vec!["quiet", "active"],
26        vec![0.6, 0.4],
27        vec![vec![0.8, 0.2], vec![0.3, 0.7]],
28        vec![vec![0.9, 0.1], vec![0.2, 0.8]],
29    )?;
30    let observations = [0, 0, 1, 1];
31    let inference = forward_backward(&model, &observations)?;
32    let path = viterbi(&model, &observations)?;
33    println!(
34        "inference log-likelihood={:.6} path={:?} repairs={}",
35        inference.evidence.log_likelihood, path.states, inference.evidence.numerical_repairs
36    );
37
38    let data = [
39        Sequence::Discrete(vec![0, 0, 1, 1, 1, 0]),
40        Sequence::Discrete(vec![0, 1, 1, 0, 0, 0]),
41    ];
42    let report = fit_hmm(
43        &data,
44        HmmSpec::Discrete {
45            states: 2,
46            symbols: 2,
47            additive_smoothing: 1.0e-6,
48        },
49        HmmFitControl::new(23, 6, 1.0e-7, 10_000, 1.0e-12)?,
50    )?;
51    println!(
52        "fit likelihood={:.6} iterations={} converged={} repairs={} work={} termination={:?} seed={}",
53        report.evidence.log_likelihood,
54        report.evidence.iterations,
55        report.evidence.converged,
56        report.evidence.numerical_repairs,
57        report.evidence.work,
58        report.evidence.termination,
59        report.evidence.seed
60    );
61    Ok(())
62}

Trait Implementations§

Source§

impl Clone for HmmFitControl

Source§

fn clone(&self) -> HmmFitControl

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for HmmFitControl

Source§

impl Debug for HmmFitControl

Source§

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

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

impl PartialEq for HmmFitControl

Source§

fn eq(&self, other: &HmmFitControl) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HmmFitControl

Auto Trait Implementations§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.