Trait bio::stats::hmm::Model

source ·
pub trait Model<Observation> {
    fn num_states(&self) -> usize;
    fn states(&self) -> StateIter ;
    fn transitions(&self) -> StateTransitionIter ;
    fn transition_prob(&self, from: State, to: State) -> LogProb;
    fn initial_prob(&self, state: State) -> LogProb;
    fn observation_prob(&self, state: State, observation: &Observation) -> LogProb;

    fn transition_prob_idx(
        &self,
        from: State,
        to: State,
        _to_idx: usize
    ) -> LogProb { ... } }
Expand description

A trait for Hidden Markov Models (HMM) with generic Observation type.

Rabiner (1989) defines a Hidden Markov Model λ as the tiple (A, B, π) of transition matrix A, emission probabilities B, and initial state distribution π. This has been generalized in Model such that you implement transition_prob(), observation_prob(), and initial_prob() (and the other methods; implementation of transition_prob_idx() can optionally be implemented and your implementation of transition_prob() can then panic).

The inference algorithm implementations viterbi(), forward(), and backward() will work with any implementation.

Consequently, this allows for the implementation of HMMs with both discrete and continuous emission distributions.

Required Methods

The number of states in the model.

Return iterator over the states of an HMM.

Returns an iterator of all transitions.

Transition probability between two states from and to.

Initial probability given the HMM state.

Probability for the given observation in the given state.

Provided Methods

Transition probability between two states from and to for observation with index _to_idx (index of to).

This feature comes in handy in several applications of HMMs to biological sequences. One prominent one is how XHMM by Fromer et al. (2014) uses the distance between target regions for adjusting the transition probabilities.

The default implementation return the result of the position-independent transition_prob().

Implementors