procrustes icon indicating copy to clipboard operation
procrustes copied to clipboard

pinv2 deprecated

Open dannyrichy opened this issue 3 years ago • 12 comments

Hello, Since scipy 1.9.0 , the function pinv2 has been subsumed in pinv, is it possible to remove it's use in generic.py

P.S Attaching link to the release notes https://docs.scipy.org/doc/scipy/release.1.9.0.html?highlight=pinv2

dannyrichy avatar Nov 05 '22 13:11 dannyrichy

Hi! Thank you for your interest in our package. @the-nihilist-ninja If you install the latest version of our package from the source, pinv2 has been replaced by pinv.

I am going to close this issue for now. But please feel free to reopen this issue or create a new one if needed.

FanwangM avatar Nov 05 '22 15:11 FanwangM

Thanks for the tips. Would that be possible to update it on pypi?

lgrcia avatar Mar 18 '23 18:03 lgrcia

Updating on pypi should be possible with cardboardlint.

PaulWAyers avatar Mar 20 '23 03:03 PaulWAyers

We are again having issues here. I think we need to remove the pinv2 functionality.

The issue with Moore-Penrose pseudoinverses not working still exists, however, although it rarely occurs. (It is a shame that scipy and numpy do not give more transparent method control in linear algebra routines.) A hack that works is to add a little bit of random noise when the matrix is ill conditioned. Something like the following should work in almost all cases.

try:
    Minv = np.linalg.pinv(M)
except np.linalg.LinAlgError:
     M = 2e-14*np.random.random_sample((t1.shape[0],t1.shape[1])) - 1e-14
    M= np.linalg.pinv(M)

PaulWAyers avatar May 09 '23 10:05 PaulWAyers

Do you mean getting an error when using pinv2? If so, I would assume that people installed our package from PyPI instead of the latest codes in the master branch. The pinv2 function has been replaced with pinv function already. If not, the way you proposed makes sense and I can make a change soon. @PaulWAyers

FanwangM avatar May 10 '23 15:05 FanwangM

Yep, we can resolve this by requiring old versions of scipy, which is fine. But probably better to evolve to the newest versions of scipy anyway.

PaulWAyers avatar May 10 '23 15:05 PaulWAyers

Can you (or who encountered the problem) provide an example showing the problem of using pinv function? I will add this as a test in the fix. Thanks.

@PaulWAyers

FanwangM avatar May 11 '23 04:05 FanwangM

The issue showed up in gopt, but I remembered that the same issue appears here. @Moham21 should have an example of a matrix that's problematic.

PaulWAyers avatar May 11 '23 11:05 PaulWAyers

@moham21 can you give an example of a matrix whre scipy.pinv doesn't work but scipy.pinv2 does work?

PaulWAyers avatar Aug 02 '23 16:08 PaulWAyers

@Moham21 can you give an example of a matrix whre scipy.pinv doesn't work but scipy.pinv2 does work?

I checked the test errors that I had so far and I didn't come across an inverse problem, but rather an eigenvalue conversion. And we have decided to try numpy and except scipy and that helped for the most part.

Moham21 avatar Aug 02 '23 20:08 Moham21

Do you still have a matrix example to show how the pinv2 failed? This would be useful for me to build a test. Thank you. @Moham21

FanwangM avatar Aug 06 '23 20:08 FanwangM

I talked to @Moham21 and the examples she had were from the eigenvalue problem. She was constructing a generalized inverse, but doing it "by hand" using the eigenvalues.

As I recall, the examples that failed where ones where the matrix had several rows and/or columns of zeros. I think a nilpotent matrix might be a good example, but I did not confirm this.

PaulWAyers avatar Aug 08 '23 15:08 PaulWAyers