.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/02_cov_model/06_fitting_para_ranges.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_02_cov_model_06_fitting_para_ranges.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 9-33 .. code-block:: Python 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) .. rst-class:: sphx-glr-script-out .. code-block:: none Results: {'var': np.float64(1.024573980819835), 'len_scale': np.float64(5.081592149596026), 'nugget': 0.0, 'alpha': np.float64(0.9067040924530624)} .. GENERATED FROM PYTHON SOURCE LINES 34-40 .. code-block:: Python ax = model.plot() ax.scatter(bins, est_vario, color="k", label="sample variogram") ax.legend() .. image-sg:: /examples/02_cov_model/images/sphx_glr_06_fitting_para_ranges_001.png :alt: 06 fitting para ranges :srcset: /examples/02_cov_model/images/sphx_glr_06_fitting_para_ranges_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-77 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 :any:`scipy.optimize.curve_fit`. You can use the following methods to manipulate the used bounds: .. currentmodule:: gstools.covmodel .. autosummary:: CovModel.default_opt_arg_bounds CovModel.default_arg_bounds CovModel.set_arg_bounds CovModel.check_arg_bounds You can override the :any:`CovModel.default_opt_arg_bounds` to provide standard bounds for your additional parameters. To access the bounds you can use: .. autosummary:: CovModel.var_bounds CovModel.len_scale_bounds CovModel.nugget_bounds CovModel.opt_arg_bounds CovModel.arg_bounds .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.083 seconds) .. _sphx_glr_download_examples_02_cov_model_06_fitting_para_ranges.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 06_fitting_para_ranges.ipynb <06_fitting_para_ranges.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 06_fitting_para_ranges.py <06_fitting_para_ranges.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 06_fitting_para_ranges.zip <06_fitting_para_ranges.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_