JuliaEarth / GeoStats.jl

An extensible framework for geospatial data science and geostatistical modeling fully written in Julia
https://juliaearth.github.io/GeoStatsDocs/stable/
MIT License
497 stars 60 forks source link

Problem with Kriging using Gaussian Variogram #29

Closed tianzeliu closed 5 years ago

tianzeliu commented 5 years ago

I was testing Kriging my data with different variograms and found that Gaussian variogram seems to be constantly producing problems. When I used Matern (and also other types such as Spherical) variograms the results I got looked normal (see MaternExample.png). However, when I used Gaussian variogram, the results looked awful with patches of very extreme values (see GaussianExample.png ). The specific variograms I used for the two examples are: γtheo = MaternVariogram(sill=1.35, range=175.0, nugget=0.15, distance=Haversine(6371)) γtheo = GaussianVariogram(sill=1.2, range=300.0, nugget=0.15, distance=Haversine(6371)) I am also attaching my dataset in (lon,lat,val) format. Thanks a lot!

gaussianexample maternexample StnRes_label.txt

juliohm commented 5 years ago

Thank you @tianzeliu for reporting the issue. I encountered similar problems in the past (#12) and delayed the resolution for too long. The problem with the Gaussian variogram is known in the literature. This variogram has a behavior at the origin (it is very flat) that leads to quite ill-conditioned covariance matrices. Other software such as SGeMS and GSLIB add a small positive term to the diagonal of the Kriging system to improve the condition number, and I think I will do the same here in GeoStats.jl

I was trying to avoid the solution described above because this type of preconditioning inhibits the interpolation property of Kriging. But because the implementation in GeoStats.jl never touches locations with data, this shouldn't be an issue. I will use your data set to debug the problem further, thank you.

juliohm commented 5 years ago

@tianzeliu could you please provide a minimum example so that I can reproduce the exact same plot?

Thank you for reporting the issue again.

juliohm commented 5 years ago

I am happy to say that this longstanding issue is now solved. Thank you for reporting it again, otherwise I would have delayed the investigation further.

There was a very subtle bug in the theoretical variogram expressions where the discontinuity jump at the origin was not being applied. I fixed all the variogram models accordingly as shown here: https://github.com/juliohm/Variography.jl/commit/84b540c1dbfa478bc26826487efa7580d3af4329

I have tested with your data set again, and the solution looks correct now. As a general rule, when you find ill-conditioned systems in the future, the solution is to add a nugget effect as you did above. This is equivalent to adding a positive term to the diagonal of the covariance which improves the condition number.

The new release of Variography.jl should come out soon and you can get it by updating with the Julia package manager.

Marking as solved. :+1: