pub struct Model { /* private fields */ }
Expand description
Implementation of a hmm::Model
with emission values from discrete distributions and an optional declared end state.
Log-scale probabilities are used for numeric stability.
In Rabiner’s tutorial, a discrete emission value HMM has N
states and M
output symbols.
The state transition matrix with dimensions NxN
is A
, the observation probability
distribution is the matrix B
with dimensions NxM
and the initial state distribution pi
has length N
. We also included a silent end state ε
with vector length N
that do not emit symbols for
modelling the end of sequences. It’s optional to supply the end probabilities at the creation of the model.
If this happens, we’ll create a dummy end state to simulate as if the end state has not been included.
Implementations
sourceimpl Model
impl Model
sourcepub fn new(
transition: RefCell<Array2<LogProb>>,
observation: RefCell<Array2<LogProb>>,
initial: RefCell<Array1<LogProb>>,
end: RefCell<Array1<LogProb>>,
has_end_state: bool
) -> Result<Self>
pub fn new(
transition: RefCell<Array2<LogProb>>,
observation: RefCell<Array2<LogProb>>,
initial: RefCell<Array1<LogProb>>,
end: RefCell<Array1<LogProb>>,
has_end_state: bool
) -> Result<Self>
Construct new Hidden MarkovModel with the given transition, observation, and initial state matrices and vectors already in log-probability space.
Trait Implementations
sourceimpl Model<usize> for Model
impl Model<usize> for Model
sourcefn num_states(&self) -> usize
fn num_states(&self) -> usize
The number of states in the model.
sourcefn states(&self) -> StateIterⓘNotable traits for StateIterimpl Iterator for StateIter type Item = State;
fn states(&self) -> StateIterⓘNotable traits for StateIterimpl Iterator for StateIter type Item = State;
Return iterator over the states of an HMM.
sourcefn transitions(&self) -> StateTransitionIterⓘNotable traits for StateTransitionIterimpl Iterator for StateTransitionIter type Item = StateTransition;
fn transitions(&self) -> StateTransitionIterⓘNotable traits for StateTransitionIterimpl Iterator for StateTransitionIter type Item = StateTransition;
Returns an iterator of all transitions.
sourcefn transition_prob(&self, from: State, to: State) -> LogProb
fn transition_prob(&self, from: State, to: State) -> LogProb
Transition probability between two states from
and to
.
sourcefn initial_prob(&self, state: State) -> LogProb
fn initial_prob(&self, state: State) -> LogProb
Initial probability given the HMM state
.
sourcefn observation_prob(&self, state: State, observation: &usize) -> LogProb
fn observation_prob(&self, state: State, observation: &usize) -> LogProb
Probability for the given observation in the given state.
fn has_end_state(&self) -> bool
sourceimpl Trainable<usize> for Model
impl Trainable<usize> for Model
impl StructuralPartialEq for Model
Auto Trait Implementations
impl !RefUnwindSafe for Model
impl Send for Model
impl !Sync for Model
impl Unpin for Model
impl UnwindSafe for Model
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.