GeoStat-Framework / PyKrige

Kriging Toolkit for Python
https://pykrige.readthedocs.io
BSD 3-Clause "New" or "Revised" License
759 stars 188 forks source link

LinAlgError: singular matrix Error #150

Closed NikhilMunna closed 2 years ago

NikhilMunna commented 4 years ago

I got this error while using Ordinary kriging. Is there any workaround for this?

MuellerSeb commented 4 years ago

This is related to https://github.com/GeoStat-Framework/GSTools/issues/89 and https://github.com/GeoStat-Framework/GSTools/issues/79#issuecomment-615843518

We will use the pseudo inverse in the future to calculate the kriging weight by a least-square approach, if the system is singular.

At the moment, the only thing you could try is to reduce the number of conditional points, so the kriging matrix is invertible.

MuellerSeb commented 4 years ago

You could try PyKrige from this branch: https://github.com/GeoStat-Framework/PyKrige/tree/pseudo_inv

You can directly install it with pip:

pip install git+https://github.com/GeoStat-Framework/PyKrige.git@pseudo_inv

be sure to provide cython beforehand.

In this branch, the inverse is calculated by the pseudo-inverse.

MuellerSeb commented 4 years ago

This should be fixed with v1.5.1 that will be released tomorrow. Closing for now. Feel free to re-open, if you have further questions.

WuJunxu commented 3 years ago

I also encounter this bug with pykrige==1.60 and 1.51, python==3.9, how could I solve this problem? With approximately 700 interp points, two Group 1 succeccfuly interpolated, but Group 2 failed with 'LinAlgError: singular matrix'.

MuellerSeb commented 3 years ago

Did you use the speudo inverse?

WuJunxu commented 3 years ago

Did you use the speudo inverse?

I am sorry. What is speudo inverse?

MuellerSeb commented 3 years ago

https://geostat-framework.readthedocs.io/projects/pykrige/en/stable/generated/pykrige.ok.OrdinaryKriging.html#pykrige.ok.OrdinaryKriging

You can set pseudo_inv=True in all kriging routines to solve the kriging system with more robust numerical approaches.

MuellerSeb commented 2 years ago

Closing due to inactivity. Open a discussion for further questions.