[mlpack-svn] r14235 - mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Feb 8 15:27:12 EST 2013


Author: rcurtin
Date: 2013-02-08 15:27:12 -0500 (Fri, 08 Feb 2013)
New Revision: 14235

Modified:
   mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/
   mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm.hpp
   mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_impl.hpp
   mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_main.cpp
Log:
Propagate change for #266.



Property changes on: mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm
___________________________________________________________________
Added: svn:mergeinfo
   + /mlpack/trunk/src/mlpack/methods/gmm:13981-14234

Modified: mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm.hpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm.hpp	2013-02-08 20:26:03 UTC (rev 14234)
+++ mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm.hpp	2013-02-08 20:27:12 UTC (rev 14235)
@@ -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/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_impl.hpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_impl.hpp	2013-02-08 20:26:03 UTC (rev 14234)
+++ mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_impl.hpp	2013-02-08 20:27:12 UTC (rev 14235)
@@ -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/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_main.cpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_main.cpp	2013-02-08 20:26:03 UTC (rev 14234)
+++ mlpack/branches/mlpack-1.x/src/mlpack/methods/gmm/gmm_main.cpp	2013-02-08 20:27:12 UTC (rev 14235)
@@ -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