[mlpack-svn] r14884 - mlpack/trunk/src/mlpack/methods/gmm
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Apr 9 14:49:01 EDT 2013
Author: rcurtin
Date: 2013-04-09 14:49:01 -0400 (Tue, 09 Apr 2013)
New Revision: 14884
Modified:
mlpack/trunk/src/mlpack/methods/gmm/em_fit_impl.hpp
Log:
Zeroes in any element of a diagonal of a covariance matrix can cause problems.
Modified: mlpack/trunk/src/mlpack/methods/gmm/em_fit_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/em_fit_impl.hpp 2013-04-09 18:05:52 UTC (rev 14883)
+++ mlpack/trunk/src/mlpack/methods/gmm/em_fit_impl.hpp 2013-04-09 18:49:01 UTC (rev 14884)
@@ -70,11 +70,14 @@
covariances[i] = (tmp * trans(tmpB)) / probRowSums[i];
- if (accu(covariances[i]) == 0)
+ for (size_t d = 0; d < covariances[i].n_rows; ++d)
{
- Log::Debug << "Covariance " << i << " sums to zero! Adding "
- << " perturbation." << std::endl;
- covariances[i].diag() += 1e-50;
+ if (covariances[i](d, d) == 0.0)
+ {
+ Log::Debug << "Covariance " << i << " has zero in diagonal element "
+ << d << "! Adding perturbation." << std::endl;
+ covariances[i](d, d) += 1e-50;
+ }
}
}
@@ -153,11 +156,14 @@
covariances[i] = (tmp * trans(tmpB)) / probRowSums[i];
- if (accu(covariances[i]) == 0)
+ for (size_t d = 0; d < covariances[i].n_rows; ++d)
{
- Log::Debug << "Covariance " << i << " sums to zero! Adding "
- << " perturbation." << std::endl;
- covariances[i].diag() += 1e-50;
+ if (covariances[i](d, d) == 0.0)
+ {
+ Log::Debug << "Covariance " << i << " has zero in diagonal element "
+ << d << "! Adding perturbation." << std::endl;
+ covariances[i](d, d) += 1e-50;
+ }
}
}
@@ -218,12 +224,14 @@
means[i] /= weights[i];
covariances[i] /= (weights[i] > 1) ? weights[i] : 1;
- if (accu(covariances[i]) == 0)
+ for (size_t d = 0; d < covariances[i].n_rows; ++d)
{
- Log::Debug << "Covariance " << i << " sums to zero! Adding perturbation."
- << std::endl;
- covariances[i].diag() += 1e-50;
- Log::Debug << covariances[i];
+ if (covariances[i](d, d) == 0.0)
+ {
+ Log::Debug << "Covariance " << i << " has zero in diagonal element "
+ << d << "! Adding perturbation." << std::endl;
+ covariances[i](d, d) += 1e-50;
+ }
}
}
More information about the mlpack-svn
mailing list