I’m trying to solve a problem related to geology using kriging.js
. As you know, creating a prediction surface with kriging involve variogram (experimental semivariogram and its model) to estimate the spatial autocorrelation of the data. However, the selected model fails to accurately fit the experimental semivariogram (sometimes not displayed). Your help would be greatly appreciated.
Here is my code to plot the variogram models :
// Variogram models
sphericalModel(h, nugget, range, sill) {
if (h > range) return nugget + sill;
return nugget + sill * (1.5 * (h / range) - 0.5 * (h / range) ** 3);
}
exponentialModel(h, nugget, range, sill) {
return nugget + sill * (1 - Math.exp(-h / range));
}
gaussianModel(h, nugget, range, sill) {
return nugget + sill * (1 - Math.exp(-((h ** 2) / (range ** 2))));
}
fitVariogramModel(model = 'spherical') {
const { distances, semivariances } = this.gamma;
const nugget = 0;
const sill = Math.max(...semivariances);
const range = Math.max(...distances);
const modelFunction = model === 'spherical' ? this.sphericalModel :
model === 'exponential' ? this.exponentialModel :
this.gaussianModel;
const errorFunction = (params) => {
const [nugget, range, sill] = params;
return distances.reduce((sum, h, i) => {
return sum + (semivariances[i] - modelFunction(h, nugget, range, sill)) ** 2;
}, 0);
};
// Use a simple optimization method (e.g., Nelder-Mead) to minimize errorFunction
// For simplicity, we'll assume the fitting parameters (this can be replaced with an optimization routine)
this.model = { modelFunction, params: [nugget, range, sill] };
}
Full code : https://jsfiddle.net/qLdayvsr/8/
Expected results :