pelorus 0.1.0

A high-performance GPS map-matching library for geospatial road network processing
Documentation
pub mod lattice;
pub mod solver;

pub use lattice::{HmmLattice, HmmLatticeBuilder, ViterbiLattice};
pub use solver::ViterbiSolver;

/// A state in the Viterbi lattice
pub type StateId = usize;

/// A time step in the Viterbi lattice
pub type TimeStep = usize;

/// Probability value (log probability for numerical stability)
pub type LogProbability = f64;

/// Result of Viterbi path finding
#[derive(Debug, Clone, PartialEq)]
pub struct ViterbiPath {
    /// The sequence of states in the best path
    pub states: Vec<StateId>,
    /// The log probability of the best path
    pub log_probability: LogProbability,
}

impl ViterbiPath {
    /// Create a new Viterbi path
    pub fn new(states: Vec<StateId>, log_probability: LogProbability) -> Self {
        Self {
            states,
            log_probability,
        }
    }

    /// Get the probability (not log probability) of the path
    pub fn probability(&self) -> f64 {
        self.log_probability.exp()
    }
}