Skip to content

Commit

Permalink
FIX MGD component reinitialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jmschrei committed Sep 20, 2016
1 parent dbc3bb4 commit 2c5c075
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pomegranate/distributions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2195,14 +2195,15 @@ cdef class MultivariateGaussianDistribution( MultivariateDistribution ):
memset( pair_sum, 0, d*d*sizeof(double) )
self.w_sum = 0.0

_, self._log_det = numpy.linalg.slogdet(self.cov)

try:
chol = scipy.linalg.cholesky(self.cov, lower=True)
except:
# Taken from sklearn.gmm, it's possible there are not enough observations
# to get a good measurement, so reinitialize this component.
chol = scipy.linalg.cholesky(self.cov + min_covar*numpy.eye(d), lower=True)
self.cov += min_covar * numpy.eye(d)
chol = scipy.linalg.cholesky(self.cov, lower=True)

_, self._log_det = numpy.linalg.slogdet(self.cov)

self.inv_cov = scipy.linalg.solve_triangular(chol, numpy.eye(d),
lower=True).T
Expand Down

0 comments on commit 2c5c075

Please sign in to comment.