[mlpack-svn] r14132 - mlpack/trunk/src/mlpack/methods/gmm
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Jan 18 13:15:01 EST 2013
Author: rcurtin
Date: 2013-01-18 13:15:00 -0500 (Fri, 18 Jan 2013)
New Revision: 14132
Modified:
mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
mlpack/trunk/src/mlpack/methods/gmm/gmm_impl.hpp
mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp
Log:
Make GMM::Estimate() return double.
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp 2013-01-17 22:33:47 UTC (rev 14131)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp 2013-01-18 18:15:00 UTC (rev 14132)
@@ -264,16 +264,17 @@
*
* The fitting will be performed 'trials' times; from these trials, the model
* with the greatest log-likelihood will be selected. By default, only one
- * trial is performed.
+ * trial is performed. The log-likelihood of the best fitting is returned.
*
* @tparam FittingType The type of fitting method which should be used
* (EMFit<> is suggested).
* @param observations Observations of the model.
* @param trials Number of trials to perform; the model in these trials with
* the greatest log-likelihood will be selected.
+ * @return The log-likelihood of the best fit.
*/
- void Estimate(const arma::mat& observations,
- const size_t trials = 1);
+ double Estimate(const arma::mat& observations,
+ const size_t trials = 1);
/**
* Estimate the probability distribution directly from the given observations,
@@ -283,17 +284,18 @@
*
* The fitting will be performed 'trials' times; from these trials, the model
* with the greatest log-likelihood will be selected. By default, only one
- * trial is performed.
+ * trial is performed. The log-likelihood of the best fitting is returned.
*
* @param observations Observations of the model.
* @param probabilities Probability of each observation being from this
* distribution.
* @param trials Number of trials to perform; the model in these trials with
* the greatest log-likelihood will be selected.
+ * @return The log-likelihood of the best fit.
*/
- void Estimate(const arma::mat& observations,
- const arma::vec& probabilities,
- const size_t trials = 1);
+ double Estimate(const arma::mat& observations,
+ const arma::vec& probabilities,
+ const size_t trials = 1);
/**
* Classify the given observations as being from an individual component in
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm_impl.hpp 2013-01-17 22:33:47 UTC (rev 14131)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm_impl.hpp 2013-01-18 18:15:00 UTC (rev 14132)
@@ -123,8 +123,8 @@
* Fit the GMM to the given observations.
*/
template<typename FittingType>
-void GMM<FittingType>::Estimate(const arma::mat& observations,
- const size_t trials)
+double GMM<FittingType>::Estimate(const arma::mat& observations,
+ const size_t trials)
{
double bestLikelihood; // This will be reported later.
@@ -140,7 +140,7 @@
else
{
if (trials == 0)
- return; // It's what they asked for...
+ return -DBL_MAX; // It's what they asked for...
// We need to keep temporary copies. We'll do the first training into the
// actual model position, so that if it's the best we don't need to copy it.
@@ -180,9 +180,10 @@
}
}
- // Report final log-likelihood.
+ // Report final log-likelihood and return it.
Log::Info << "GMM::Estimate(): log-likelihood of trained GMM is "
<< bestLikelihood << "." << std::endl;
+ return bestLikelihood;
}
/**
@@ -190,9 +191,9 @@
* probability of being from this distribution.
*/
template<typename FittingType>
-void GMM<FittingType>::Estimate(const arma::mat& observations,
- const arma::vec& probabilities,
- const size_t trials)
+double GMM<FittingType>::Estimate(const arma::mat& observations,
+ const arma::vec& probabilities,
+ const size_t trials)
{
double bestLikelihood; // This will be reported later.
@@ -208,7 +209,7 @@
else
{
if (trials == 0)
- return; // It's what they asked for...
+ return -DBL_MAX; // It's what they asked for...
// We need to keep temporary copies. We'll do the first training into the
// actual model position, so that if it's the best we don't need to copy it.
@@ -248,9 +249,10 @@
}
}
- // Report final log-likelihood.
+ // Report final log-likelihood and return it.
Log::Info << "GMM::Estimate(): log-likelihood of trained GMM is "
<< bestLikelihood << "." << std::endl;
+ return bestLikelihood;
}
/**
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp 2013-01-17 22:33:47 UTC (rev 14131)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp 2013-01-18 18:15:00 UTC (rev 14132)
@@ -49,9 +49,11 @@
////// Computing the parameters of the model using the EM algorithm //////
Timer::Start("em");
- gmm.Estimate(dataPoints);
+ double likelihood = gmm.Estimate(dataPoints);
Timer::Stop("em");
+ Log::Info << "Log-likelihood of estimate: " << likelihood << ".\n";
+
////// OUTPUT RESULTS //////
SaveRestoreUtility save;
save.SaveParameter(gmm.Gaussians(), "gaussians");
More information about the mlpack-svn
mailing list