Skip to main content

viterbi_path

pub fn viterbi_path(
    log_initial: &[f64],
    steps: usize,
    log_transition: impl Fn(usize, usize) -> f64,
    log_emission: impl Fn(usize, usize) -> f64,
) -> (Vec<usize>, f64)
Expand description

The most likely state path through a trellis, by dynamic programming in log space.

log_initial[s] scores starting in state s; log_transition(from, to) scores a step; log_emission(state, t) scores state state explaining observation t. Use f64::NEG_INFINITY for impossible events. Returns the best path of length steps and its total log score (-inf if every path is impossible, in which case the path is all zeros).