jfpower / anfis-pytorch

Implementation of ANFIS using the pyTorch framework
MIT License
121 stars 44 forks source link

Use torch.linalg.lstsq instead of torch.lstsq #6

Open KrzysiekDD opened 11 months ago

KrzysiekDD commented 11 months ago

In line 226 of the anfis.py, a runtime error arises:

RuntimeError: This function was deprecated since version 1.9 and is now removed. `torch.lstsq` is deprecated in favor of `torch.linalg.lstsq`.
`torch.linalg.lstsq` has reversed arguments and does not return the QR decomposition in the returned tuple (although it returns other information about the problem).

This is an issue that arises when swapping .gels with lstsq, which fixes the original deprecation, however with torch > 1.9 torch.linalg.lstsq is needed because another deprecation arises.

Swapping: coeff_2d, _ = torch.lstsq(y_actual_2d, weighted_x_2d) for: coeff_2d = torch.linalg.lstsq(weighted_x_2d, y_actual_2d).solution fixes the problem.