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

CovModel: Update and Refactoring #109

Merged
merged 70 commits into from
Nov 18, 2020
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
50e51cd
CovModel: add 'rescale' argument to rescale the len_scale
MuellerSeb Nov 10, 2020
f9ec092
Cleanup: remove doctest calls
MuellerSeb Nov 10, 2020
333321b
covmodel: add attribute 'len_rescaled' which is the rescaled len_scale
MuellerSeb Nov 10, 2020
474e71a
CovModel: rewrite Gaussian covmodel to use 'cor' and 'rescale'
MuellerSeb Nov 10, 2020
60c92aa
CovModel: move **opt_arg doc to main class
MuellerSeb Nov 10, 2020
795b3d2
CovModel: rewrite Exponential covmodel to use 'cor' and 'rescale'
MuellerSeb Nov 10, 2020
d9daac6
CovModel: rewrite Rational and Stable covmodel to use 'cor' and 'resc…
MuellerSeb Nov 10, 2020
b34c372
CovModel: rewrite Matern covmodel to use 'cor' and 'rescale'
MuellerSeb Nov 11, 2020
f324d2a
CovModel: rewrite Linear, Circular and Spherical covmodel to use 'cor…
MuellerSeb Nov 11, 2020
6722f63
CovModel: replace the 'Intersection' model with the 'HyperSpherical' …
MuellerSeb Nov 11, 2020
a1b0b2a
CovModel: replace the 'Intersection' model with the 'HyperSpherical' …
MuellerSeb Nov 11, 2020
a03a2e5
covmodel: comment update
MuellerSeb Nov 11, 2020
7392ea0
CovModel: add the Super-Spherical model
MuellerSeb Nov 11, 2020
fb28c33
SuperSpherical: doc fix
MuellerSeb Nov 11, 2020
61bdee2
CovModel: add the JBessel hole model
MuellerSeb Nov 11, 2020
97c3487
TPLmodels: refactor to use 'cor' and 'rescale'; use a new base-class …
MuellerSeb Nov 11, 2020
b3e6c77
Doc: minor fixes
MuellerSeb Nov 11, 2020
550e02e
TPLCovModel: tweak base class to provide cor and correlation like der…
MuellerSeb Nov 11, 2020
df9fa0e
Merge branch 'develop' of github.com:GeoStat-Framework/GSTools into c…
MuellerSeb Nov 11, 2020
64017b3
CovModel: add TPLSimple model
MuellerSeb Nov 11, 2020
82ab29c
field: unify rotation and anisotropy; simplify code
MuellerSeb Nov 13, 2020
5b29c37
CovModel: add [an]isometrize method; simplify code
MuellerSeb Nov 13, 2020
b31bc8a
tests: adopt tests: don't allow high-dim input in lower dimensions in…
MuellerSeb Nov 13, 2020
5481b17
CovModel: more details in documentation
MuellerSeb Nov 13, 2020
ec7ba70
Tools: add rotated_main_axes routine to determine axes from rotation …
MuellerSeb Nov 13, 2020
b552859
CovModel: simplify Rational model
MuellerSeb Nov 13, 2020
305a0d4
Tools: make use of rotated_main_axes in CovModel and Examples
MuellerSeb Nov 13, 2020
43278f0
CovModel: Fitting anisotropy to directional empirical variograms; var…
MuellerSeb Nov 14, 2020
92287fe
CovModel: update plotting routines: add axis routines; forward kwargs
MuellerSeb Nov 14, 2020
bcd984e
Examples: demonstrate fitting of anisotropy
MuellerSeb Nov 14, 2020
4bdceca
CovModel: fitting with weights respects directional variogram now; re…
MuellerSeb Nov 14, 2020
316ca18
CovModel: always use floats for 'angles' and 'anis'
MuellerSeb Nov 14, 2020
2bea823
CovModel: always use floats for 'len_scale'
MuellerSeb Nov 14, 2020
2fd07e3
Tools: add a string formatter to pretty-print lists of floats
MuellerSeb Nov 14, 2020
b844397
CovModel: always use floats for opt_args; better formatting of CovMod…
MuellerSeb Nov 14, 2020
621db8a
Examples: demonstrate using bin-counts as weights during variogram fi…
MuellerSeb Nov 14, 2020
933aea0
tools/misc: f-string not working in py35; use format
MuellerSeb Nov 14, 2020
916867e
CovModel: use precision as privat attribute to set printing format
MuellerSeb Nov 14, 2020
373251d
Examples: pimp variogram plot
MuellerSeb Nov 14, 2020
24b4f83
Field: better printing format
MuellerSeb Nov 14, 2020
3f1c0ba
CovModel.check_arg_in_bounds: allow checking lists
MuellerSeb Nov 14, 2020
602a90a
CovModel: add bounds for 'anis' since we can fit it now
MuellerSeb Nov 15, 2020
3e2680f
CovModel: add arg_list attribute to get list of values; also for isot…
MuellerSeb Nov 15, 2020
d9ad2e7
CovModel.fit: better handling of bounds for anis when fitting directi…
MuellerSeb Nov 15, 2020
c4e629c
Examples: add overview gallery to tutorials page in Docs
MuellerSeb Nov 16, 2020
49589e7
Docs: remove Overview gallery again: TOC-tree struggles
MuellerSeb Nov 16, 2020
c605cd2
Doc: resolve minor problems
MuellerSeb Nov 16, 2020
f660a48
Fix some typos
LSchueler Nov 16, 2020
5d6815b
CovModel: add routine 'check_dim'
MuellerSeb Nov 17, 2020
0045cb3
CovModel: skip bound checking, when no bounds present (e.g. during in…
MuellerSeb Nov 17, 2020
cd93f0c
CovModels: add dim checks to the linear, circular and spherical model
MuellerSeb Nov 17, 2020
88c6496
CovModel: move spectral_rad_pdf to tools
MuellerSeb Nov 18, 2020
cf14a5f
CovModel: outsource percentile_scale to tools
MuellerSeb Nov 18, 2020
b7462f6
CovModel: add 'set_opt_arg' routine to tools to shrink __init__
MuellerSeb Nov 18, 2020
e805f37
CovModel: move '[set/check]_arg_bounds' routines to tools
MuellerSeb Nov 18, 2020
ce6b8f4
CovModel: add 'set_dim' to tools
MuellerSeb Nov 18, 2020
f40769b
CovModel: add '_init_subclass' to tools
MuellerSeb Nov 18, 2020
791147a
CovModel: add more tests for class functionality
MuellerSeb Nov 18, 2020
38426da
CovModel: minor simplifications for TPL models
MuellerSeb Nov 18, 2020
97f9b44
Tests: covmodel.tools to 100% coverage
MuellerSeb Nov 18, 2020
6e1b0fa
CovModel: test *_axis methods and cor_spatial
MuellerSeb Nov 18, 2020
def555e
CovModel: better testing TPL models
MuellerSeb Nov 18, 2020
ae2ff57
CovModel: check special models; better check-case for TPL vario fitting
MuellerSeb Nov 18, 2020
55d41fd
CovModel: further testing of properties; default_opt_args always empt…
MuellerSeb Nov 18, 2020
d47d74f
CovModel: test all axis specific routines
MuellerSeb Nov 18, 2020
bc2fb16
CovModel.fit: remove redundant 'dict' option for init_guess
MuellerSeb Nov 18, 2020
c4001bf
CovModel.fit: more testing
MuellerSeb Nov 18, 2020
66943a5
CovModel.fit: weights testing
MuellerSeb Nov 18, 2020
4409059
Tests: used model method for main_axes
MuellerSeb Nov 18, 2020
9e83384
Docs: remove overview gallery hack again
MuellerSeb Nov 18, 2020
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
Prev Previous commit
Next Next commit
TPLmodels: refactor to use 'cor' and 'rescale'; use a new base-class …
…for TPL models derived from super-positioning
  • Loading branch information
MuellerSeb committed Nov 11, 2020
commit 97c3487ec0e7bc7998a40a0984b70d6b534a060b
275 changes: 87 additions & 188 deletions gstools/covmodel/tpl_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,45 @@
__all__ = ["TPLGaussian", "TPLExponential", "TPLStable"]


class TPLCovModel(CovModel):
"""Truncated-Power-Law Covariance Model base class for super-position."""

@property
def len_up(self):
""":class:`float`: Upper length scale truncation of the model.

* ``len_up = len_low + len_scale``
"""
return self.len_low + self.len_scale

@property
def len_up_rescaled(self):
""":class:`float`: Upper length scale truncation rescaled.

* ``len_up_rescaled = (len_low + len_scale) / rescale``
"""
return (self.len_low + self.len_scale) / self.rescale

@property
def len_low_rescaled(self):
""":class:`float`: Lower length scale truncation rescaled.

* ``len_low_rescaled = len_low / rescale``
"""
return self.len_low / self.rescale

def var_factor(self):
"""Factor for C (intensity of variation) to result in variance."""
return (
self.len_up_rescaled ** (2 * self.hurst)
- self.len_low_rescaled ** (2 * self.hurst)
) / (2 * self.hurst)


# Truncated power law #########################################################


class TPLGaussian(CovModel):
class TPLGaussian(TPLCovModel):
r"""Truncated-Power-Law with Gaussian modes.

Notes
Expand Down Expand Up @@ -77,9 +112,10 @@ class TPLGaussian(CovModel):
If you want to define an upper scale truncation, you should set ``len_low``
and ``len_scale`` accordingly.

The following Parameters occure:
The following Parameters occur:

* :math:`C>0` : scaling factor from the Power-Law
* :math:`C>0` :
scaling factor from the Power-Law (intensity of variation)
This parameter will be calculated internally by the given variance.
You can access C directly by ``model.var_raw``
* :math:`0<H<1` : hurst coefficient (``model.hurst``)
Expand All @@ -98,8 +134,6 @@ class TPLGaussian(CovModel):

Other Parameters
----------------
**opt_arg
The following parameters are covered by these keyword arguments
hurst : :class:`float`, optional
Hurst coefficient of the power law.
Standard range: ``(0, 1)``.
Expand All @@ -110,32 +144,6 @@ class TPLGaussian(CovModel):
Default: ``0.0``
"""

@property
def len_up(self):
""":class:`float`: Upper length scale truncation of the model.

* ``len_up = len_low + len_scale``
"""
return self.len_low + self.len_scale

def var_factor(self):
r"""Factor for C (Power-Law factor) to result in variance.

This is used to result in the right variance, which is depending
on the hurst coefficient and the length-scale extents

.. math::
\frac{\ell_{\mathrm{up}}^{2H} - \ell_{\mathrm{low}}^{2H}}{2H}

Returns
-------
:class:`float`
factor
"""
return (
self.len_up ** (2 * self.hurst) - self.len_low ** (2 * self.hurst)
) / (2 * self.hurst)

def default_opt_arg(self):
"""Defaults for the optional arguments.

Expand All @@ -160,51 +168,32 @@ def default_opt_arg_bounds(self):
"""
return {"hurst": (0.1, 1, "oo"), "len_low": (0.0, np.inf, "co")}

def cor(self, h):
"""TPL with Gaussian modes - normalized correlation function."""
return tplstable_cor(h, 1.0, self.hurst, 2)

def correlation(self, r):
r"""Truncated-Power-Law with Gaussian modes - correlation function.

If ``len_low=0`` we have a simple representation:

.. math::
\rho(r) =
H \cdot
E_{1+H}
\left[
\left(\frac{r}{\ell}\right)^{2}
\right]

The general case:

.. math::
\rho(r) =
H \cdot
\frac{\ell_{\mathrm{up}}^{2H} \cdot
E_{1+H}
\left[\left(\frac{r}{\ell_{\mathrm{up}}}\right)^{2}\right]
- \ell_{\mathrm{low}}^{2H} \cdot
E_{1+H}
\left[\left(\frac{r}{\ell_{\mathrm{low}}}\right)^{2}\right]}
{\ell_{\mathrm{up}}^{2H}-\ell_{\mathrm{low}}^{2H}}
"""
"""TPL with Gaussian modes - correlation function."""
# if lower limit is 0 we use the simplified version (faster)
if np.isclose(self.len_low, 0.0):
return tplstable_cor(r, self.len_scale, self.hurst, 2)
if np.isclose(self.len_low_rescaled, 0.0):
return tplstable_cor(r, self.len_rescaled, self.hurst, 2)
return (
self.len_up ** (2 * self.hurst)
* tplstable_cor(r, self.len_up, self.hurst, 2)
- self.len_low ** (2 * self.hurst)
* tplstable_cor(r, self.len_low, self.hurst, 2)
self.len_up_rescaled ** (2 * self.hurst)
* tplstable_cor(r, self.len_up_rescaled, self.hurst, 2)
- self.len_low_rescaled ** (2 * self.hurst)
* tplstable_cor(r, self.len_low_rescaled, self.hurst, 2)
) / (
self.len_up ** (2 * self.hurst) - self.len_low ** (2 * self.hurst)
self.len_up_rescaled ** (2 * self.hurst)
- self.len_low_rescaled ** (2 * self.hurst)
)

def spectral_density(self, k): # noqa: D102
return tpl_gau_spec_dens(
k, self.dim, self.len_scale, self.hurst, self.len_low
k, self.dim, self.len_rescaled, self.hurst, self.len_low_rescaled
)


class TPLExponential(CovModel):
class TPLExponential(TPLCovModel):
r"""Truncated-Power-Law with Exponential modes.

Notes
Expand Down Expand Up @@ -250,9 +239,10 @@ class TPLExponential(CovModel):
If you want to define an upper scale truncation, you should set ``len_low``
and ``len_scale`` accordingly.

The following Parameters occure:
The following Parameters occur:

* :math:`C>0` : scaling factor from the Power-Law
* :math:`C>0` :
scaling factor from the Power-Law (intensity of variation)
This parameter will be calculated internally by the given variance.
You can access C directly by ``model.var_raw``
* :math:`0<H<\frac{1}{2}` : hurst coefficient (``model.hurst``)
Expand All @@ -271,8 +261,6 @@ class TPLExponential(CovModel):

Other Parameters
----------------
**opt_arg
The following parameters are covered by these keyword arguments
hurst : :class:`float`, optional
Hurst coefficient of the power law.
Standard range: ``(0, 1)``.
Expand All @@ -283,32 +271,6 @@ class TPLExponential(CovModel):
Default: ``0.0``
"""

@property
def len_up(self):
""":class:`float`: Upper length scale truncation of the model.

* ``len_up = len_low + len_scale``
"""
return self.len_low + self.len_scale

def var_factor(self):
r"""Factor for C (Power-Law factor) to result in variance.

This is used to result in the right variance, which is depending
on the hurst coefficient and the length-scale extents

.. math::
\frac{\ell_{\mathrm{up}}^{2H} - \ell_{\mathrm{low}}^{2H}}{2H}

Returns
-------
:class:`float`
factor
"""
return (
self.len_up ** (2 * self.hurst) - self.len_low ** (2 * self.hurst)
) / (2 * self.hurst)

def default_opt_arg(self):
"""Defaults for the optional arguments.

Expand All @@ -333,45 +295,28 @@ def default_opt_arg_bounds(self):
"""
return {"hurst": (0.1, 1, "oo"), "len_low": (0.0, np.inf, "co")}

def cor(self, h):
"""TPL with Exponential modes - normalized correlation function."""
return tplstable_cor(h, 1.0, self.hurst, 1)

def correlation(self, r):
r"""Truncated-Power-Law with Exponential modes - correlation function.

If ``len_low=0`` we have a simple representation:

.. math::
\rho(r) =
H \cdot
E_{1+H}
\left[
\frac{r}{\ell}
\right]

The general case:

.. math::
\rho(r) =
2H \cdot
\frac{\ell_{\mathrm{up}}^{2H} \cdot
E_{1+2H}\left[\frac{r}{\ell_{\mathrm{up}}}\right]
- \ell_{\mathrm{low}}^{2H} \cdot
E_{1+2H}\left[\frac{r}{\ell_{\mathrm{low}}}\right]}
{\ell_{\mathrm{up}}^{2H}-\ell_{\mathrm{low}}^{2H}}
"""
"""TPL with Exponential modes - correlation function."""
# if lower limit is 0 we use the simplified version (faster)
if np.isclose(self.len_low, 0.0):
return tplstable_cor(r, self.len_scale, self.hurst, 1)
if np.isclose(self.len_low_rescaled, 0.0):
return tplstable_cor(r, self.len_rescaled, self.hurst, 1)
return (
self.len_up ** (2 * self.hurst)
* tplstable_cor(r, self.len_up, self.hurst, 1)
- self.len_low ** (2 * self.hurst)
* tplstable_cor(r, self.len_low, self.hurst, 1)
self.len_up_rescaled ** (2 * self.hurst)
* tplstable_cor(r, self.len_up_rescaled, self.hurst, 1)
- self.len_low_rescaled ** (2 * self.hurst)
* tplstable_cor(r, self.len_low_rescaled, self.hurst, 1)
) / (
self.len_up ** (2 * self.hurst) - self.len_low ** (2 * self.hurst)
self.len_up_rescaled ** (2 * self.hurst)
- self.len_low_rescaled ** (2 * self.hurst)
)

def spectral_density(self, k): # noqa: D102
return tpl_exp_spec_dens(
k, self.dim, self.len_scale, self.hurst, self.len_low
k, self.dim, self.len_rescaled, self.hurst, self.len_low_rescaled
)


Expand Down Expand Up @@ -423,14 +368,15 @@ class TPLStable(CovModel):
If you want to define an upper scale truncation, you should set ``len_low``
and ``len_scale`` accordingly.

The following Parameters occure:
The following Parameters occur:

* :math:`0<\alpha\leq 2` : The shape parameter of the Stable model.

* :math:`\alpha=1` : Exponential modes
* :math:`\alpha=2` : Gaussian modes

* :math:`C>0` : scaling factor from the Power-Law
* :math:`C>0` :
scaling factor from the Power-Law (intensity of variation)
This parameter will be calculated internally by the given variance.
You can access C directly by ``model.var_raw``
* :math:`0<H<\frac{\alpha}{2}` : hurst coefficient (``model.hurst``)
Expand All @@ -449,8 +395,6 @@ class TPLStable(CovModel):

Other Parameters
----------------
**opt_arg
The following parameters are covered by these keyword arguments
hurst : :class:`float`, optional
Hurst coefficient of the power law.
Standard range: ``(0, 1)``.
Expand All @@ -465,32 +409,6 @@ class TPLStable(CovModel):
Default: ``0.0``
"""

@property
def len_up(self):
""":class:`float`: Upper length scale truncation of the model.

* ``len_up = len_low + len_scale``
"""
return self.len_low + self.len_scale

def var_factor(self):
r"""Factor for C (Power-Law factor) to result in variance.

This is used to result in the right variance, which is depending
on the hurst coefficient and the length-scale extents

.. math::
\frac{\ell_{\mathrm{up}}^{2H} - \ell_{\mathrm{low}}^{2H}}{2H}

Returns
-------
:class:`float`
factor
"""
return (
self.len_up ** (2 * self.hurst) - self.len_low ** (2 * self.hurst)
) / (2 * self.hurst)

def default_opt_arg(self):
"""Defaults for the optional arguments.

Expand Down Expand Up @@ -536,40 +454,21 @@ def check_opt_arg(self):
+ "count with unstable results"
)

def cor(self, h):
"""TPL with Stable modes - normalized correlation function."""
return tplstable_cor(h, 1.0, self.hurst, self.alpha)

def correlation(self, r):
r"""Truncated-Power-Law with Stable modes - correlation function.

If ``len_low=0`` we have a simple representation:

.. math::
\rho(r) =
\frac{2H}{\alpha} \cdot
E_{1+\frac{2H}{\alpha}}
\left[
\left(\frac{r}{\ell}\right)^{\alpha}
\right]

The general case:

.. math::
\rho(r) =
\frac{2H}{\alpha} \cdot
\frac{\ell_{\mathrm{up}}^{2H} \cdot
E_{1+\frac{2H}{\alpha}}
\left[\left(\frac{r}{\ell_{\mathrm{up}}}\right)^{\alpha}\right]
- \ell_{\mathrm{low}}^{2H} \cdot
E_{1+\frac{2H}{\alpha}}
\left[\left(\frac{r}{\ell_{\mathrm{low}}}\right)^{\alpha}\right]}
{\ell_{\mathrm{up}}^{2H}-\ell_{\mathrm{low}}^{2H}}
"""
"""TPL with Stable modes - correlation function."""
# if lower limit is 0 we use the simplified version (faster)
if np.isclose(self.len_low, 0.0):
return tplstable_cor(r, self.len_scale, self.hurst, self.alpha)
if np.isclose(self.len_low_rescaled, 0.0):
return tplstable_cor(r, self.len_rescaled, self.hurst, self.alpha)
return (
self.len_up ** (2 * self.hurst)
* tplstable_cor(r, self.len_up, self.hurst, self.alpha)
- self.len_low ** (2 * self.hurst)
* tplstable_cor(r, self.len_low, self.hurst, self.alpha)
self.len_up_rescaled ** (2 * self.hurst)
* tplstable_cor(r, self.len_up_rescaled, self.hurst, self.alpha)
- self.len_low_rescaled ** (2 * self.hurst)
* tplstable_cor(r, self.len_low_rescaled, self.hurst, self.alpha)
) / (
self.len_up ** (2 * self.hurst) - self.len_low ** (2 * self.hurst)
self.len_up_rescaled ** (2 * self.hurst)
- self.len_low_rescaled ** (2 * self.hurst)
)