[mlpack-svn] r10426 - mlpack/trunk/src/mlpack/methods/gmm
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Sun Nov 27 01:32:33 EST 2011
Author: rcurtin
Date: 2011-11-27 01:32:33 -0500 (Sun, 27 Nov 2011)
New Revision: 10426
Modified:
mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp
Log:
A better way of calculating the covariance, more akin to arma::cov.
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp 2011-11-27 06:32:16 UTC (rev 10425)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm.cpp 2011-11-27 06:32:33 UTC (rev 10426)
@@ -75,21 +75,22 @@
// Add this to the relevant mean.
means_trial[cluster] += data.col(i);
- // And add it to the relative covariance matrix.
+ // Add this to the relevant covariance.
covariances_trial[cluster] += data.col(i) * trans(data.col(i));
// Now add one to the weights (we will normalize).
weights_trial[cluster]++;
}
- // Now normalize the means, covariances, and weights.
+ // Now normalize the mean and covariance.
for (size_t i = 0; i < gaussians; i++)
{
- // Normalize mean.
+ covariances_trial[i] -= means_trial[i] * trans(means_trial[i]) /
+ weights_trial[i];
+
means_trial[i] /= weights_trial[i];
- // Normalize covariance (use unbiased estimator).
- covariances_trial[i] /= (weights_trial[i] - 1);
+ covariances_trial[i] /= (weights_trial[i] > 1) ? weights_trial[i] : 1;
}
// Finally, normalize weights.
More information about the mlpack-svn
mailing list