mlpack  master
hmm_regression.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_HMM_HMM_REGRESSION_HPP
13 #define MLPACK_METHODS_HMM_HMM_REGRESSION_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 #include "hmm.hpp"
18 
19 namespace mlpack {
20 namespace hmm {
21 
69 class HMMRegression : public HMM<distribution::RegressionDistribution>
70 {
71  public:
89  HMMRegression(const size_t states,
91  const double tolerance = 1e-5) :
92  HMM<distribution::RegressionDistribution>(states, emissions, tolerance)
93  { /* nothing to do */ }
94 
119  HMMRegression(const arma::vec& initial,
120  const arma::mat& transition,
121  const std::vector<distribution::RegressionDistribution>& emission,
122  const double tolerance = 1e-5) :
123  HMM<distribution::RegressionDistribution>(initial, transition, emission,
124  tolerance)
125  { /* nothing to do */ }
126 
127 
128 
158  void Train(const std::vector<arma::mat>& predictors,
159  const std::vector<arma::vec>& responses);
160 
180  void Train(const std::vector<arma::mat>& predictors,
181  const std::vector<arma::vec>& responses,
182  const std::vector<arma::Row<size_t> >& stateSeq);
183 
203  double Estimate(const arma::mat& predictors,
204  const arma::vec& responses,
205  arma::mat& stateProb,
206  arma::mat& forwardProb,
207  arma::mat& backwardProb,
208  arma::vec& scales) const;
209 
222  double Estimate(const arma::mat& predictors,
223  const arma::vec& responses,
224  arma::mat& stateProb) const;
225 
237  double Predict(const arma::mat& predictors,
238  const arma::vec& responses,
239  arma::Row<size_t>& stateSeq) const;
240 
248  double LogLikelihood(const arma::mat& predictors,
249  const arma::vec& responses) const;
264  void Filter(const arma::mat& predictors,
265  const arma::vec& responses,
266  arma::vec& filterSeq,
267  size_t ahead = 0) const;
268 
282  void Smooth(const arma::mat& predictors,
283  const arma::vec& responses,
284  arma::vec& smoothSeq) const;
285 
286  private:
290  void StackData(const std::vector<arma::mat>& predictors,
291  const std::vector<arma::vec>& responses,
292  std::vector<arma::mat>& dataSeq) const;
293 
294  void StackData(const arma::mat& predictors,
295  const arma::vec& responses,
296  arma::mat& dataSeq) const;
297 
309  void Forward(const arma::mat& predictors,
310  const arma::vec& responses,
311  arma::vec& scales,
312  arma::mat& forwardProb) const;
313 
326  void Backward(const arma::mat& predictors,
327  const arma::vec& responses,
328  const arma::vec& scales,
329  arma::mat& backwardProb) const;
330 
331 
332 };
333 
334 } // namespace hmm
335 } // namespace mlpack
336 
337 // Include implementation.
338 #include "hmm_regression_impl.hpp"
339 
340 #endif
double Estimate(const arma::mat &predictors, const arma::vec &responses, 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...
std::vector< distribution::RegressionDistribution > emission
Set of emission probability distributions; one for each state.
Definition: hmm.hpp:363
HMMRegression(const arma::vec &initial, const arma::mat &transition, const std::vector< distribution::RegressionDistribution > &emission, const double tolerance=1e-5)
Create the Hidden Markov Model Regression with the given initial probability vector, the given transition matrix, and the given regression emission distributions.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
void StackData(const std::vector< arma::mat > &predictors, const std::vector< arma::vec > &responses, std::vector< arma::mat > &dataSeq) const
Utility functions to facilitate the use of the HMM class for HMMR.
The core includes that mlpack expects; standard C++ includes and Armadillo.
A class that represents a Hidden Markov Model Regression (HMMR).
double tolerance
Tolerance of Baum-Welch algorithm.
Definition: hmm.hpp:376
arma::vec initial
Initial state probability vector.
Definition: hmm.hpp:370
A class that represents a univariate conditionally Gaussian distribution.
double LogLikelihood(const arma::mat &predictors, const arma::vec &responses) const
Compute the log-likelihood of the given predictors and responses.
A class that represents a Hidden Markov Model with an arbitrary type of emission distribution.
Definition: hmm.hpp:85
void Backward(const arma::mat &predictors, const arma::vec &responses, const arma::vec &scales, arma::mat &backwardProb) const
The Backward algorithm (part of the Forward-Backward algorithm).
void Forward(const arma::mat &predictors, const arma::vec &responses, arma::vec &scales, arma::mat &forwardProb) const
The Forward algorithm (part of the Forward-Backward algorithm).
HMMRegression(const size_t states, const distribution::RegressionDistribution emissions, const double tolerance=1e-5)
Create the Hidden Markov Model Regression with the given number of hidden states and the given defaul...
void Train(const std::vector< arma::mat > &predictors, const std::vector< arma::vec > &responses)
Train the model using the Baum-Welch algorithm, with only the given predictors and responses...
double Predict(const arma::mat &predictors, const arma::vec &responses, arma::Row< size_t > &stateSeq) const
Compute the most probable hidden state sequence for the given predictors and responses, using the Viterbi algorithm, returning the log-likelihood of the most likely state sequence.
void Filter(const arma::mat &predictors, const arma::vec &responses, arma::vec &filterSeq, size_t ahead=0) const
HMMR filtering.
void Smooth(const arma::mat &predictors, const arma::vec &responses, arma::vec &smoothSeq) const
HMM smoothing.
arma::mat transition
Transition probability matrix.
Definition: hmm.hpp:366