<p>Hey Davud,</p>

<p>Sorry for the slow response; I was out of town for a while too. :)</p>

<p>I did some digging, and I think I've solved the issue in <a href="https://github.com/mlpack/mlpack/commit/c5050982ef63d3122098b51b58c43a5b9ae73eec" class="commit-link"><tt>c505098</tt></a>.  Here is what I think was happening:</p>

<p>During training, some Gaussians end up having particularly small covariances.  This happens in part because many of the points in your dataset are identical.  A very small covariance for a Gaussian means that the probability of a point centered at the mean will be extremely large; for sufficiently small covariances, this results in the probability being represented as inf on the machine.  Then, later in the EM fitting process, normalization of probabilities turns this inf into a NaN, which ends up propagating to the covariance, which will end up full of NaNs.  When the covariance is full of NaNs, the "Adding perturbation" step will continue forever, because no matter how large a number you add to a matrix full of NaNs, it still won't be positive definite.</p>

<p>So, what I've done is modified the positive definiteness constraint to also enforce a minimum diagonal covariance element of 1e-50 (very small), thus restricting how small a single Gaussian's PDF can get.  This means that the probability of a point at the mean is bounded within the range of numbers representable by the machine, so there is no inf, and there aren't NaNs later.</p>

<p>But, it's possible that I did not properly solve the issue, so please reopen if you still have issues.  I am more than happy to help work out issues like this. :)</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/issues/496#issuecomment-171446246">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFGKY1ZAyllkSstJ8i5ZNc9ClBT9Qks5pZr0cgaJpZM4G1xqM.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/issues/496#issuecomment-171446246"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>