[mlpack-svn] r10574 - mlpack/trunk/src/mlpack/methods/gmm
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Dec 6 03:38:53 EST 2011
Author: rcurtin
Date: 2011-12-06 03:38:53 -0500 (Tue, 06 Dec 2011)
New Revision: 10574
Modified:
mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp
Log:
It helps when you actually implement the stupid function instead of being an
idiot and thinking "well I'll just do it later but actually I'll forget that I
didn't do it and then not get to go to sleep instead".
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp 2011-12-06 06:52:33 UTC (rev 10573)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp 2011-12-06 08:38:53 UTC (rev 10574)
@@ -32,7 +32,23 @@
*/
arma::vec GMM::Random() const
{
- return "0 0";
+ // Determine which Gaussian it will be coming from.
+ double gaussRand = (double) rand() / (double) RAND_MAX;
+ size_t gaussian;
+
+ double sumProb = 0;
+ for (size_t g = 0; g < gaussians; g++)
+ {
+ sumProb += weights(g);
+ if (gaussRand <= sumProb)
+ {
+ gaussian = g;
+ break;
+ }
+ }
+
+ return trans(chol(covariances[gaussian])) *
+ arma::randn<arma::vec>(dimensionality) + means[gaussian];
}
void GMM::Estimate(const arma::mat& data)
More information about the mlpack-svn
mailing list