pmelchior / pygmmis

Gaussian mixture model for incomplete (missing or truncated) and noisy data
MIT License
98 stars 22 forks source link

numpy.linalg.linalg.LinAlgError: Singular matrix #6

Closed ravi0912 closed 6 years ago

ravi0912 commented 6 years ago

Hi, I'm using this library and restricting the mean update. I had initialized the gmm.mean, amp and covar. My data is 1d and integer. I'm trying to fit gmm curve in this data. This is the error I'm getting : LinAlgError: Singular matrix

gmm = pygmmis.GMM(K=3, D=1) # K components, D dimensions gmm.amp = np.array([0.33,0.33,0.33]) gmm.mean = np.array([[7],[14],[30]]) gmm.covar = np.array([[[2]],[[3]],[[5]]]) logL, U = pygmmis.fit(gmm, t_data,init_method='none',frozen={"amp":[],"mean":[0,1,2],"covar":[]})

pmelchior commented 6 years ago

I just checked your code with random integer test data, and it works. Singular matrices can arise, depending on your data, if one or multiple components have their covariances go to zero. This is more of a concern for integer data, so I suggest that you add the parameter w=1 (or some other suitable number) to provide a lower bound on the diagonal elements of the covariance matrix.

ravi0912 commented 6 years ago

Thanks, it is really helpful.. Solved my problem.