[mlpack-svn] r17276 - mlpack/trunk/src/mlpack/methods/hmm
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Sun Nov 2 12:45:22 EST 2014
Author: michaelfox99
Date: Sun Nov 2 12:45:22 2014
New Revision: 17276
Log:
Added Smooth and Filter functions
Modified:
mlpack/trunk/src/mlpack/methods/hmm/hmm_impl.hpp
Modified: mlpack/trunk/src/mlpack/methods/hmm/hmm_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/hmm/hmm_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/hmm/hmm_impl.hpp Sun Nov 2 12:45:22 2014
@@ -436,6 +436,53 @@
}
/**
+ * HMM filtering.
+ */
+template<typename Distribution>
+void HMM<Distribution>::Filter(const arma::mat& dataSeq,
+ arma::mat& filterSeq,
+ size_t ahead) const
+{
+ // First run the forward algorithm
+ arma::mat forwardProb;
+ arma::vec scales;
+ Forward(dataSeq, scales, forwardProb);
+
+ // Propagate state ahead
+ if(ahead != 0) {
+ forwardProb = pow(transition, ahead)*forwardProb;
+ }
+
+ // Compute expected emissions.
+ // Will not work for distributions without a Mean() function.
+ filterSeq.zeros(dimensionality, dataSeq.n_cols);
+ for(size_t i = 0; i < emission.size(); i++)
+ {
+ filterSeq = filterSeq + (emission[i].Mean())*(forwardProb.row(i));
+ }
+}
+
+/**
+ * HMM smoothing.
+ */
+template<typename Distribution>
+void HMM<Distribution>::Smooth(const arma::mat& dataSeq,
+ arma::mat& smoothSeq) const
+{
+ // First run the forward algorithm
+ arma::mat stateProb;
+ Estimate(dataSeq, stateProb);
+
+ // Compute expected emissions.
+ // Will not work for distributions without a Mean() function.
+ smoothSeq.zeros(dimensionality, dataSeq.n_cols);
+ for(size_t i = 0; i < emission.size(); i++)
+ {
+ smoothSeq = smoothSeq + (emission[i].Mean())*(stateProb.row(i));
+ }
+}
+
+/**
* The Forward procedure (part of the Forward-Backward algorithm).
*/
template<typename Distribution>
More information about the mlpack-svn
mailing list