[mlpack] 59/149: rename hmm_regression.cpp
Barak A. Pearlmutter
barak+git at pearlmutter.net
Sat May 2 09:11:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit 2091ea6a3bc11e484b6262658029cc591ae8823d
Author: michaelfox99 <michaelfox99 at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Sun Nov 2 17:53:10 2014 +0000
rename hmm_regression.cpp
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17279 9d5b8971-822b-0410-80eb-d18c1038ef23
---
src/mlpack/core/dists/regression_distribution.cpp | 79 +++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/src/mlpack/core/dists/regression_distribution.cpp b/src/mlpack/core/dists/regression_distribution.cpp
new file mode 100644
index 0000000..32dc09b
--- /dev/null
+++ b/src/mlpack/core/dists/regression_distribution.cpp
@@ -0,0 +1,79 @@
+/**
+ * @file regression_distribution.cpp
+ * @author Michael Fox
+ *
+ * Implementation of conditional Gaussian distribution for HMM regression (HMMR)
+ */
+
+#include "regression_distribution.hpp"
+
+using namespace mlpack;
+using namespace mlpack::distribution;
+
+/**
+ * Returns a string representation of this object.
+ */
+std::string RegressionDistribution::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 observations List of observations.
+*/
+void RegressionDistribution::Estimate(const arma::mat& observations)
+{
+ regression::LinearRegression lr(observations.rows(1, observations.n_rows-1),
+ (observations.row(0)).t(), 0, true);
+ rf = lr;
+ arma::vec fitted;
+ lr.Predict(observations.rows(1, observations.n_rows-1), fitted);
+ err.Estimate(observations.row(0)-fitted.t());
+}
+
+/**
+* Estimate parameters using provided observation weights
+*
+* @param weights probability that given observation is from distribution
+*/
+void RegressionDistribution::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 RegressionDistribution::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);
+}
+
+void RegressionDistribution::Predict(const arma::mat& points,
+ arma::vec& predictions) const
+{
+ rf.Predict(points, predictions);
+}
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list