Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

GMM fitting with full covariance crashes unexpectedly unlike sklearn GMM fitting #20

@MacDaddio

Description

@MacDaddio

I was trying to fit a GMM on data and kept getting the same error (with variying numbers for the batch and order):

_LinAlgError: torch.linalg_cholesky: (Batch element 3): The factorization could not be completed because the input is not positive-definite (the leading minor of order 941 is not positive-definite).

I made a minimal working example to show when this comes up in practice. I compared to sklearn and somehow sklearn is able to avoid this problem. This issue happens both on CPU and GPU. I have PyCave 3.1.3 and sklearn 0.24.2. Do you have any idea what could be the issue?

Minimum working example:

from pycave.bayes import GaussianMixture
import torch
import numpy as np
from sklearn import mixture

#Set seed
seed = 0
np.random.seed(seed)
torch.manual_seed(seed)

#Inputs
n = 5000
p = 2000
k = 10

#Make some non-Gaussian data
X = np.random.randn(n,p)
X = torch.Tensor(X)
X = torch.nn.ReLU()(X-1)

#Fit Sklearn GMM
gmm_sk = mixture.GaussianMixture(n_components=k,
covariance_type='full',
init_params='kmeans')
gmm_sk.fit(X.numpy())

#Fit PyCave GMM
gmm = GaussianMixture(num_components=k,
covariance_type='full',
init_strategy='kmeans')
gmm.fit(X)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions