[mlpack-git] master: Added Smooth and Filter functions (4d10e7f)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:01:55 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 4d10e7f32ed98dd488ad2a4b8a9eeeb57ec7904b
Author: michaelfox99 <michaelfox99 at gmail.com>
Date:   Sun Nov 2 17:45:22 2014 +0000

    Added Smooth and Filter functions


>---------------------------------------------------------------

4d10e7f32ed98dd488ad2a4b8a9eeeb57ec7904b
 src/mlpack/methods/hmm/hmm_impl.hpp | 47 +++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/src/mlpack/methods/hmm/hmm_impl.hpp b/src/mlpack/methods/hmm/hmm_impl.hpp
index 8d70346..8e45479 100644
--- a/src/mlpack/methods/hmm/hmm_impl.hpp
+++ b/src/mlpack/methods/hmm/hmm_impl.hpp
@@ -436,6 +436,53 @@ double HMM<Distribution>::LogLikelihood(const arma::mat& dataSeq) const
 }
 
 /**
+ * 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-git mailing list