Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sum of models and custom models #160

Merged
merged 31 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7232c43
Add _custom_model class attribute, exception in fit and p0 and bounds…
rhugonnet Aug 11, 2023
5247cd4
Add tests on custom model definition and fitting
rhugonnet Aug 11, 2023
7b3cd22
Add to DirectionalVariogram and rename _custom_model to _is_model_cus…
rhugonnet Aug 11, 2023
20749fc
Build sum of models from string name
rhugonnet Aug 21, 2023
c93ed9a
Add self._model_name attribute, and logic for sum of models in descri…
rhugonnet Aug 21, 2023
daf6eda
Add more tests and correct bugs
rhugonnet Aug 21, 2023
2df8592
Remove static typing, move to description
rhugonnet Aug 21, 2023
5d37015
Fix instantiation and fix tests
rhugonnet Aug 21, 2023
66aff87
Add tests for plotting
rhugonnet Aug 21, 2023
82fa559
Document fit_bounds and fit_p0, and add tests
rhugonnet Aug 22, 2023
4185c75
Update model argument description
rhugonnet Aug 22, 2023
bc4e170
Fix random test and inf bound check
rhugonnet Aug 22, 2023
aa2d7ed
Fix warnings in test_variogram
rhugonnet Aug 22, 2023
ce9aa85
Fix typo in description
rhugonnet Aug 22, 2023
de3a948
Fix floating precision error
rhugonnet Sep 21, 2023
2e31741
Add example in user guide
rhugonnet Sep 21, 2023
6985339
Make nugget consistent for a sum of models
rhugonnet Sep 21, 2023
fbff110
Finalize nugget for sum and add tests
rhugonnet Sep 21, 2023
f4d33f1
Rerun tests with scipy 1.11.3
rhugonnet Oct 2, 2023
34388c6
Force SciPy versions to before 1.11.1
rhugonnet Oct 5, 2023
d357c1a
Try with NumPy version before 1.25
rhugonnet Oct 5, 2023
56127e2
Try with 1.24
rhugonnet Oct 5, 2023
7d5d287
Try 1.24.1
rhugonnet Oct 5, 2023
591ae37
Try 1.24.1
rhugonnet Oct 5, 2023
d0bb82d
Try 1.24.2
rhugonnet Oct 5, 2023
9a76ae7
Try 1.24.3
rhugonnet Oct 5, 2023
35903f8
Try 1.25.0
rhugonnet Oct 5, 2023
9ada1f4
Remove NumPy version fixing
rhugonnet Oct 9, 2023
59781f1
Change stable entropy bin test precision to 0 decimals
rhugonnet Oct 9, 2023
5f67e4e
Merge branch 'main' into combine_models
mmaelicke Oct 13, 2023
9690d39
Linting
rhugonnet Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions docs/userguide/variogram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,53 @@ variogram is rather showing a Gaussian or exponential behavior.
If you would like to export a Variogram instance to gstools, the smoothness parameter
may not be smaller than ``0.2``.

Sum of models
~~~~~~~~~~~~~

All the above models can be combined into a sum of models, in order to fit more complex empirical variograms that might
capture signals with multiple correlations ranges.
To fit with a sum of models, simply add a "+" between any number of models:

.. ipython:: python
:okwarning:

# Fit a sum of two spherical models
V.model = "spherical+spherical"

@savefig sum_of_models.png width=8in
V.plot();

Custom model
~~~~~~~~~~~~

Additionally, any custom model can be passed to the model argument to fit a specific function to the empirical
variogram. This model needs to be built with the ``@variogram`` decorator, which requires the lag argument
(typically, ``h``) to be listed first in the custom function.

.. caution::

When using a custom model, it is highly recommended to define the parameter bounds as these cannot be derived
logically by SciKit-GStat as for other models. This is done by passing either ``fit_bounds`` to ``Variogram()``
at instantiation or ``bounds`` to ``Variogram.fit()``.


.. ipython:: python
:okwarning:

# Build a custom model by applying the @variogram decorator (here adding a linear term to a spherical model)
from skgstat.models import variogram, spherical
@variogram
def custom_model(h, r1, c1, a):
return spherical(h, r1, c1) + h * a
V.model = custom_model

# We define the bounds for r1, c1 and a
bounds_custom = [(0, 0, 0), (np.max(V.bins), np.max(V.experimental), 2)]
V.fit(bounds=bounds_custom)

@savefig custom_model.png width=8in
V.plot();

When direction matters
======================

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scipy
scipy<=1.11.1
numpy
pandas
matplotlib
Expand Down
1 change: 1 addition & 0 deletions skgstat/DirectionalVariogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def __init__(self,

# set the directional model
self._directional_model = None
self._is_model_custom = False
self.set_directional_model(model_name=directional_model)

# the binning settings
Expand Down
Loading
Loading