[mlpack-svn] r17179 - mlpack/trunk/src/mlpack/core/dists
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Sat Sep 13 11:21:10 EDT 2014
Author: michaelfox99
Date: Sat Sep 13 11:21:09 2014
New Revision: 17179
Log:
Implementation of HMM Regression
Added:
mlpack/trunk/src/mlpack/core/dists/hmm_regression_impl.hpp
Added: mlpack/trunk/src/mlpack/core/dists/hmm_regression_impl.hpp
==============================================================================
--- (empty file)
+++ mlpack/trunk/src/mlpack/core/dists/hmm_regression_impl.hpp Sat Sep 13 11:21:09 2014
@@ -0,0 +1,64 @@
+/**
+ * @file hmm_regression_impl.hpp
+ * @author Michael Fox
+ *
+ * Implementation of conditional Gaussian distribution for HMM regression (HMMR)
+ */
+#ifndef __MLPACK_METHODS_HMM_DISTRIBUTIONS_CONDITIONAL_GAUSSIAN_DISTRIBUTION_IMPL_HPP
+#define __MLPACK_METHODS_HMM_DISTRIBUTIONS_CONDITIONAL_GAUSSIAN_DISTRIBUTION_IMPL_HPP
+
+#include "hmm_regression.hpp"
+
+using namespace mlpack;
+using namespace mlpack::distribution;
+
+/**
+ * Returns a string representation of this object.
+ */
+std::string HMMRegression::ToString()
+ const
+{
+ std::ostringstream convert;
+ convert << "HMMRegression [" << this << "]" << std::endl;
+
+ // Secondary ostringstream so things can be indented right.
+ std::ostringstream data;
+ data << "Conditional mean function: " << std::endl << rf.ToString();
+ data << "Parameters: " << std::endl << rf.Parameters();
+ data << "Error distribution: " << std::endl << err.ToString();
+
+ convert << util::Indent(data.str());
+ return convert.str();
+}
+
+/**
+* Estimate parameters using provided observation weights
+*
+* @param weights probability that given observation is from distribution
+*/
+void HMMRegression::Estimate(const arma::mat& observations,
+ const arma::vec& weights)
+{
+ regression::LinearRegression lr(observations.rows(1, observations.n_rows-1),
+ (observations.row(0)).t(), 0, true, weights);
+ rf = lr;
+ arma::vec fitted;
+ lr.Predict(observations.rows(1, observations.n_rows-1), fitted);
+ err.Estimate(observations.row(0)-fitted.t(), weights);
+}
+
+/**
+* Evaluate probability density function of given observation
+*
+* @param observation point to evaluate probability at
+*/
+double HMMRegression::Probability(const arma::vec& observation) const
+{
+ arma::vec fitted;
+ rf.Predict(observation.rows(1, observation.n_rows-1), fitted);
+ return err.Probability(observation(0)-fitted);
+}
+
+
+
+#endif
\ No newline at end of file
More information about the mlpack-svn
mailing list