borchero / pycave

Traditional Machine Learning Models for Large-Scale Datasets in PyTorch.
https://pycave.borchero.com
MIT License
126 stars 13 forks source link

How to get covariance matrix? And confused about precisions cholesky... #14

Closed mareksocha closed 2 years ago

mareksocha commented 2 years ago

Hi,

Thank you for the library!

In other posts I read that covariances are stored under gmm.gaussian.covars but I cannot find it. The only thing related to the covraiance is gmm.model_.precisions_cholesky but I don't know how to use them. I am attaching the content of fitted GaussianMixture object. Could you please tell me how to find covariances or how to calculate it using precisions_cholesky?

obraz

borchero commented 2 years ago

Sorry for getting back so late! gmm.model_.precisions_cholesky is the only property that is exposed and gives you the matrix L of the Cholesky decomposition A = L * L^T where A is the precision matrix, i.e. the inverse of the covariance matrix M. You can, thus, recover the covariance matrix rather easily.

For spherical covariance, the covariances are simply given as 1 / L^2 (where L = gmm.model_.precisions_cholesky).

Nevertheless, it probably makes sense to expose a covariances property on gmm.model_...