Fitting variogram dataΒΆ

The model class comes with a routine to fit the model-parameters to given variogram data. In the following we will use the self defined stable model from a previous example.

import numpy as np
import gstools as gs


class Stab(gs.CovModel):
    def default_opt_arg(self):
        return {"alpha": 1.5}

    def cor(self, h):
        return np.exp(-h ** self.alpha)


# Exemplary variogram data (e.g. estimated from field observations)
bins = [1.0, 3.0, 5.0, 7.0, 9.0, 11.0]
est_vario = [0.2, 0.5, 0.6, 0.8, 0.8, 0.9]
# fitting model
model = Stab(dim=2)
# we have to provide boundaries for the parameters
model.set_arg_bounds(alpha=[0, 3])
results, pcov = model.fit_variogram(bins, est_vario, nugget=False)
print("Results:", results)

Out:

Results: {'var': 1.0245756934625878, 'len_scale': 5.081619778184886, 'nugget': 0.0, 'alpha': 0.9067052602178444}
ax = model.plot()
ax.scatter(bins, est_vario, color="k", label="sample variogram")
ax.legend()
../../_images/sphx_glr_06_fitting_para_ranges_001.png

As you can see, we have to provide boundaries for the parameters. As a default, the following bounds are set:

  • additional parameters: [-np.inf, np.inf]
  • variance: [0.0, np.inf]
  • len_scale: [0.0, np.inf]
  • nugget: [0.0, np.inf]

Also, you can deselect parameters from fitting, so their predefined values will be kept. In our case, we fixed a nugget of 0.0, which was set by default. You can deselect any standard or optional argument of the covariance model. The second return value pcov is the estimated covariance of popt from the used scipy routine scipy.optimize.curve_fit.

You can use the following methods to manipulate the used bounds:

CovModel.default_opt_arg_bounds(self) Provide default boundaries for optional arguments.
CovModel.default_arg_bounds(self) Provide default boundaries for arguments.
CovModel.set_arg_bounds(self, \*\*kwargs) Set bounds for the parameters of the model.
CovModel.check_arg_bounds(self) Check arguments to be within the given bounds.

You can override the CovModel.default_opt_arg_bounds to provide standard bounds for your additional parameters.

To access the bounds you can use:

CovModel.var_bounds Bounds for the variance.
CovModel.len_scale_bounds Bounds for the lenght scale.
CovModel.nugget_bounds Bounds for the nugget.
CovModel.opt_arg_bounds Bounds for the optional arguments.
CovModel.arg_bounds Bounds for all parameters.

Total running time of the script: ( 0 minutes 0.134 seconds)

Gallery generated by Sphinx-Gallery