gallantlab / pyrcca

Regularized kernel canonical correlation analysis in Python
Other
239 stars 72 forks source link

LinAlgError: the leading minor of order 299 of 'b' is not positive definite. The factorization of ' b' could not be completed and no eigenvalues or eigenvectors were computed. #15

Open Char-Aznable opened 4 years ago

Char-Aznable commented 4 years ago

Hi, I am trying to perform CCA on my 2 data sets, both of which are of shape 6030 samples by 499 features. I am using

cca = rcca.CCA(kernelcca = False, reg = 0., numCC = nCCA)
cca.train([x1, x2])

and get this error:

Training CCA, kernel = None, regularization = 0.0000, 3 components                                 
---------------------------------------------------------------------------                        
LinAlgError                               Traceback (most recent call last)                        
<ipython-input-144-4470a9a5f17c> in <module>
----> 1 cca.train([x1, x2])

/home/aznb/pyrcca/rcca.py in train(self, data)
    239 
    240     def train(self, data):
--> 241         return super(CCA, self).train(data)
    242 
    243 

/home/aznb/pyrcca/rcca.py in train(self, data)
     37         comps = kcca(data, self.reg, self.numCC, kernelcca=self.kernelcca,
     38                      ktype=self.ktype, gausigma=self.gausigma,
---> 39                      degree=self.degree)
     40         self.cancorrs, self.ws, self.comps = recon(data, comps,
     41                                                    kernelcca=self.kernelcca)

/home/aznb/pyrcca/rcca.py in kcca(data, reg, numCC, kernelcca, ktype, gausigma, degree)
    299 
    300     maxCC = LH.shape[0]
--> 301     r, Vs = eigh(LH, RH, eigvals=(maxCC - numCC, maxCC - 1))
    302     r[np.isnan(r)] = 0
    303     rindex = np.argsort(r)[::-1]

~/.linuxbrew/opt/python/lib/python3.7/site-packages/scipy/linalg/decomp.py in eigh(a, b, lower, eig
vals_only, overwrite_a, overwrite_b, turbo, eigvals, type, check_finite)
    491                           " factorization of 'b' could not be completed"
    492                           " and no eigenvalues or eigenvectors were"
--> 493                           " computed." % (info-b1.shape[0]))
    494 
    495 

LinAlgError: the leading minor of order 299 of 'b' is not positive definite. The factorization of '
b' could not be completed and no eigenvalues or eigenvectors were computed.

On the other hand, Scikit-learn's CCA does give results without error. Any clue where I should look into what happened?

Char-Aznable commented 4 years ago

I also tried eliminating the all-zeros columns but that didn't help

pinouche commented 4 years ago

Try to add some regularisation instead of setting it to 0

kavishgandhi commented 2 years ago

I am facing a similar problem, I have 2 datasets of size 512x8 on which I am trying to do cca. can someone suggest to me what regularization and numCC I should use?