compute_ev() error
Closed this issue · 1 comments
rfarouni commented
Hi Natalia,
Thanks for making the code publicly available! I was trying it out on my dataset and I noticed that the function throws an error when best_numCC is smaller than the number of observations.
cca.best_numCC
Out[10]: 4
cca.compute_ev(beta_dsc)
Computing explained variance for component #1
Computing explained variance for component #2
Computing explained variance for component #3
Computing explained variance for component #4
Computing explained variance for component #5
Traceback (most recent call last):
File "<ipython-input-9-9680903395ab>", line 1, in <module>
cca.compute_ev(beta_dsc)
File "rcca.py", line 53, in compute_ev
preds, corrs = predict(data, [w[:, ccs-1:ccs] for w in self.ws], self.cutoff)
File "rcca.py", line 172, in predict
iws = [np.linalg.pinv(w.T, rcond = cutoff) for w in ws]
File "/home/rick/anaconda/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 1583, in pinv
_assertNoEmpty2d(a)
File "/home/rick/anaconda/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 222, in _assertNoEmpty2d
raise LinAlgError("Arrays cannot be empty")
LinAlgError: Arrays cannot be empty
I was able to get it to work by replacing this line
self.numCC = nT if self.numCC is None else self.numCC
with
self.numCC = self.best_numCC
But I am not sure if that is a satisfactory fix given the rest of the code.
Best,
Rick
nbilenko commented
Hi Rick,
Thank you for using the code and for catching the bug! It is now fixed (I apologize for the delay). Your fix should be fine as well.
Cheers,
Natalia