[mlpack-svn] r12063 - mlpack/trunk/src/mlpack/methods/gmm
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Mar 27 12:08:40 EDT 2012
Author: rcurtin
Date: 2012-03-27 12:08:40 -0400 (Tue, 27 Mar 2012)
New Revision: 12063
Modified:
mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp
mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
Log:
Add GMM::Probability(arma::vec, size_t) as part of #212.
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp 2012-03-27 14:25:47 UTC (rev 12062)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp 2012-03-27 16:08:40 UTC (rev 12063)
@@ -15,6 +15,9 @@
using namespace mlpack::gmm;
using namespace mlpack::kmeans;
+/**
+ * Return the probability of the given observation being from this GMM.
+ */
double GMM::Probability(const arma::vec& observation) const
{
// Sum the probability for each Gaussian in our mixture (and we have to
@@ -27,6 +30,19 @@
}
/**
+ * Return the probability of the given observation being from the given
+ * component in the mixture.
+ */
+double GMM::Probability(const arma::vec& observation,
+ const size_t component) const
+{
+ // We are only considering one Gaussian component -- so we only need to call
+ // phi() once. We do consider the prior probability!
+ return weights[component] *
+ phi(observation, means[component], covariances[component]);
+}
+
+/**
* Return a randomly generated observation according to the probability
* distribution defined by this object.
*/
@@ -173,7 +189,7 @@
// as our trained model.
for (size_t iter = 0; iter < 10; iter++)
{
- InitialClustering(k, observations, meansTrial, covariancesTrial,
+ InitialClustering(k, observations, meansTrial, covariancesTrial,
weightsTrial);
l = Loglikelihood(observations, meansTrial, covariancesTrial, weightsTrial);
@@ -235,7 +251,7 @@
// Update values of l; calculate new log-likelihood.
lOld = l;
- l = Loglikelihood(observations, meansTrial,
+ l = Loglikelihood(observations, meansTrial,
covariancesTrial, weightsTrial);
iteration++;
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp 2012-03-27 14:25:47 UTC (rev 12062)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp 2012-03-27 16:08:40 UTC (rev 12063)
@@ -126,6 +126,16 @@
double Probability(const arma::vec& observation) const;
/**
+ * Return the probability that the given observation came from the given
+ * Gaussian component in this distribution.
+ *
+ * @param observation Observation to evaluate the probability of.
+ * @param component Index of the component of the GMM to be considered.
+ */
+ double Probability(const arma::vec& observation,
+ const size_t component) const;
+
+ /**
* Return a randomly generated observation according to the probability
* distribution defined by this object.
*
More information about the mlpack-svn
mailing list