16 #ifndef __MLPACK_METHODS_HMM_HMM_HPP 17 #define __MLPACK_METHODS_HMM_HMM_HPP 85 template<
typename Distribution = distribution::DiscreteDistribution>
106 HMM(
const size_t states = 0,
107 const Distribution emissions = Distribution(),
139 const std::vector<Distribution>&
emission,
170 void Train(
const std::vector<arma::mat>& dataSeq);
193 void Train(
const std::vector<arma::mat>& dataSeq,
194 const std::vector<arma::Row<size_t> >& stateSeq);
214 double Estimate(
const arma::mat& dataSeq,
215 arma::mat& stateProb,
216 arma::mat& forwardProb,
217 arma::mat& backwardProb,
218 arma::vec& scales)
const;
231 double Estimate(
const arma::mat& dataSeq,
232 arma::mat& stateProb)
const;
246 arma::mat& dataSequence,
247 arma::Row<size_t>& stateSequence,
248 const size_t startState = 0)
const;
260 double Predict(
const arma::mat& dataSeq,
261 arma::Row<size_t>& stateSeq)
const;
283 void Filter(
const arma::mat& dataSeq,
284 arma::mat& filterSeq,
285 size_t ahead = 0)
const;
298 void Smooth(
const arma::mat& dataSeq,
299 arma::mat& smoothSeq)
const;
329 template<
typename Archive>
330 void Serialize(Archive& ar,
const unsigned int version);
344 void Forward(
const arma::mat& dataSeq,
346 arma::mat& forwardProb)
const;
359 void Backward(
const arma::mat& dataSeq,
360 const arma::vec& scales,
361 arma::mat& backwardProb)
const;
384 #include "hmm_impl.hpp" const arma::vec & Initial() const
Return the vector of initial state probabilities.
arma::vec & Initial()
Modify the vector of initial state probabilities.
const arma::mat & Transition() const
Return the transition matrix.
std::vector< Distribution > emission
Set of emission probability distributions; one for each state.
double Estimate(const arma::mat &dataSeq, arma::mat &stateProb, arma::mat &forwardProb, arma::mat &backwardProb, arma::vec &scales) const
Estimate the probabilities of each hidden state at each time step for each given data observation...
Linear algebra utility functions, generally performed on matrices or vectors.
size_t Dimensionality() const
Get the dimensionality of observations.
void Forward(const arma::mat &dataSeq, arma::vec &scales, arma::mat &forwardProb) const
The Forward algorithm (part of the Forward-Backward algorithm).
size_t & Dimensionality()
Set the dimensionality of observations.
std::vector< Distribution > & Emission()
Return a modifiable emission probability matrix reference.
double Predict(const arma::mat &dataSeq, arma::Row< size_t > &stateSeq) const
Compute the most probable hidden state sequence for the given data sequence, using the Viterbi algori...
double tolerance
Tolerance of Baum-Welch algorithm.
arma::vec initial
Initial state probability vector.
double & Tolerance()
Modify the tolerance of the Baum-Welch algorithm.
double LogLikelihood(const arma::mat &dataSeq) const
Compute the log-likelihood of the given data sequence.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
A class that represents a Hidden Markov Model with an arbitrary type of emission distribution.
void Train(const std::vector< arma::mat > &dataSeq)
Train the model using the Baum-Welch algorithm, with only the given unlabeled observations.
void Backward(const arma::mat &dataSeq, const arma::vec &scales, arma::mat &backwardProb) const
The Backward algorithm (part of the Forward-Backward algorithm).
size_t dimensionality
Dimensionality of observations.
void Smooth(const arma::mat &dataSeq, arma::mat &smoothSeq) const
HMM smoothing.
arma::mat & Transition()
Return a modifiable transition matrix reference.
void Serialize(Archive &ar, const unsigned int version)
Serialize the object.
void Filter(const arma::mat &dataSeq, arma::mat &filterSeq, size_t ahead=0) const
HMM filtering.
const std::vector< Distribution > & Emission() const
Return the emission distributions.
HMM(const size_t states=0, const Distribution emissions=Distribution(), const double tolerance=1e-5)
Create the Hidden Markov Model with the given number of hidden states and the given default distribut...
double Tolerance() const
Get the tolerance of the Baum-Welch algorithm.
void Generate(const size_t length, arma::mat &dataSequence, arma::Row< size_t > &stateSequence, const size_t startState=0) const
Generate a random data sequence of the given length.
arma::mat transition
Transition probability matrix.