Liking cljdoc? Tell your friends :D

fastmath.kernel.variogram

Parametric semivariogram models, empirical estimators, and model fitting for geostatistical analysis.

A semivariogram describes how spatial dependence between observations decays with lag distance h. It is the primary structure function in kriging interpolation: given a set of spatially distributed observations, the empirical semivariogram is first estimated from the data, then a parametric model is fitted to it, and the fitted model is used by a kriging algorithm to derive optimal interpolation weights. Each parametric model is governed by up to four parameters: nugget (discontinuity at the origin representing micro-scale variation or measurement error), psill (partial sill; the structured spatial variance), range (the characteristic lag scale), and in some models beta (a shape or power exponent).

Parametric semivariogram models — each takes a parameter map and returns a (fn ^double [^double x]) computing semivariance at lag x:

  • Bounded models with a hard sill at range: spherical, circular, linear, cubic, pentaspherical, tpower
  • Bounded models that asymptotically approach the sill: exponential, gaussian, expower, cauchy, rational, hole
  • Unbounded models (no sill): power (valid for the exponent beta in (0, 2])
  • Generalised families with a configurable shape order, each available as a two-step creator ->name / convenience wrapper name: ->bessel / bessel, ->matern / matern, ->hyperspherical / hyperspherical, ->superspherical / superspherical, ->tplstable / tplstable
  • RBF-based model: rbf->variogram wraps any suitable RBF kernel from fastmath.kernel.rbf into a semivariogram constructor

Empirical semivariogram:

  • empirical — bins all observation pairs by lag distance and applies a chosen estimator to compute gamma per bin; returns a sequence of {:h :gamma :n} maps (:n is the number of pairs in the bin)

Estimators used by empirical to compute gamma per bin from pairwise differences:

  • matheron-estimator — classical (Matheron) estimator
  • cressie-estimator — robust Cressie estimator
  • highly-robust-estimator — Genton highly robust estimator
  • dowd-estimator — Dowd estimator
  • ->quantile-estimator — creates a quantile (Armstrong and Delfiner) estimator for a given level
  • robust-m-estimator — Gunst and Hartfield robust M-estimator

Model fitting (L-BFGS-B optimisation against the empirical semivariogram):

  • fit — fits a model and returns the semivariogram function
  • fit-params — fits a model and returns a detailed result map with the fitted parameters, weights, and loss value

Utilities:

  • variogram->covariance — converts a semivariogram function and the total sill to the covariance function
  • bounding-box-diagonal — computes the diagonal of the bounding box of spatial points; used to derive the default cutoff in empirical
  • remove-outliers-fence — removes outliers using Tukey's fences criterion
  • remove-outliers-mad — removes outliers using median absolute deviation
  • maybe-remove-outliers — applies one of the two filters (or none) to the points before empirical forms the pairs

Conventions: a model is built from a parameter map (:nugget, :psill, :range, and :beta or an order where needed), the parameters are checked once at the construction and ex-info with :type :invalid-input is thrown for a missing or invalid one. The returned semivariogram function is exactly 0.0 at lag zero (the nugget acts just after zero), the bounded models are constant beyond range, the lag is expected to be non-negative. An RBF kernel given to fit or rbf->variogram is a function of the scaled lag; a model constructor such as gaussian is not a kernel.

Parametric semivariogram models, empirical estimators, and model fitting for geostatistical analysis.

A semivariogram describes how spatial dependence between observations decays with lag
distance `h`. It is the primary structure function in kriging interpolation: given a set
of spatially distributed observations, the empirical semivariogram is first estimated
from the data, then a parametric model is fitted to it, and the fitted model is used by
a kriging algorithm to derive optimal interpolation weights. Each parametric model is
governed by up to four parameters: `nugget` (discontinuity at the origin representing
micro-scale variation or measurement error), `psill` (partial sill; the structured
spatial variance), `range` (the characteristic lag scale), and in some models `beta`
(a shape or power exponent).

Parametric semivariogram models — each takes a parameter map and returns a
`(fn ^double [^double x])` computing semivariance at lag `x`:

- Bounded models with a hard sill at `range`: `spherical`, `circular`, `linear`,
  `cubic`, `pentaspherical`, `tpower`
- Bounded models that asymptotically approach the sill: `exponential`, `gaussian`,
  `expower`, `cauchy`, `rational`, `hole`
- Unbounded models (no sill): `power` (valid for the exponent `beta` in `(0, 2]`)
- Generalised families with a configurable shape order, each available as a
  two-step creator `->name` / convenience wrapper `name`: `->bessel` / `bessel`,
  `->matern` / `matern`, `->hyperspherical` / `hyperspherical`,
  `->superspherical` / `superspherical`, `->tplstable` / `tplstable`
- RBF-based model: `rbf->variogram` wraps any suitable RBF kernel from
  `fastmath.kernel.rbf` into a semivariogram constructor

Empirical semivariogram:

- `empirical` — bins all observation pairs by lag distance and applies a chosen
  estimator to compute `gamma` per bin; returns a sequence of `{:h :gamma :n}` maps
  (`:n` is the number of pairs in the bin)

Estimators used by `empirical` to compute `gamma` per bin from pairwise differences:

- `matheron-estimator` — classical (Matheron) estimator
- `cressie-estimator` — robust Cressie estimator
- `highly-robust-estimator` — Genton highly robust estimator
- `dowd-estimator` — Dowd estimator
- `->quantile-estimator` — creates a quantile (Armstrong and Delfiner) estimator for a given level
- `robust-m-estimator` — Gunst and Hartfield robust M-estimator

Model fitting (L-BFGS-B optimisation against the empirical semivariogram):

- `fit` — fits a model and returns the semivariogram function
- `fit-params` — fits a model and returns a detailed result map with the fitted
  parameters, weights, and loss value

Utilities:

- `variogram->covariance` — converts a semivariogram function and the total sill to the covariance function
- `bounding-box-diagonal` — computes the diagonal of the bounding box of spatial points;
  used to derive the default cutoff in `empirical`
- `remove-outliers-fence` — removes outliers using Tukey's fences criterion
- `remove-outliers-mad` — removes outliers using median absolute deviation
- `maybe-remove-outliers` — applies one of the two filters (or none) to the points before `empirical` forms the pairs

Conventions: a model is built from a parameter map (`:nugget`, `:psill`, `:range`, and `:beta` or
an order where needed), the parameters are checked once at the construction and `ex-info` with
`:type :invalid-input` is thrown for a missing or invalid one. The returned semivariogram
function is exactly `0.0` at lag zero (the nugget acts just after zero), the bounded models are constant
beyond `range`, the lag is expected to be non-negative. An RBF kernel given to `fit` or `rbf->variogram`
is a function of the scaled lag; a model constructor such as `gaussian` is not a kernel.
raw docstring

->besselclj

(->bessel)
(->bessel order)

Creates a BesselJ semivariogram model constructor for a given Bessel function order.

The formula is: nugget + psill * (1 - Γ(order+1) * (2 * range / x)^order * J_order(x / range))

where Γ is the gamma function and J_order is the Bessel function of the first kind. The factor Γ(order+1) * (2 / d)^order * J_order(d), d = x / range, tends to 1.0 at the origin and is evaluated as a series for small lags (d^2 < 4 * (order + 1)), so the semivariance is finite for any order and lag (no 0 * Infinity): it tends to nugget for tiny lags, also for orders far above 100. The semivariance oscillates around nugget + psill and tends to this value for an infinite lag.

Parameters:

  • order (double, optional): the order of the Bessel function of the first kind; must be non-negative; defaults to 1.0, the same default as bessel (and the order used by fit-params for :bessel when :parameter is not given)

Returns a semivariogram model constructor (fn [params]) that accepts a map with:

  • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
  • :psill (double): the partial sill; the amplitude of the oscillation; must be non-negative
  • :range (double): the scale parameter controlling the period of oscillation; must be positive

The constructor itself returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also bessel, ->matern, hole.

Creates a BesselJ semivariogram model constructor for a given Bessel function `order`.

The formula is: `nugget + psill * (1 - Γ(order+1) * (2 * range / x)^order * J_order(x / range))`

where `Γ` is the gamma function and `J_order` is the Bessel function of the first kind. The factor
`Γ(order+1) * (2 / d)^order * J_order(d)`, `d = x / range`, tends to `1.0` at the origin and is evaluated
as a series for small lags (`d^2 < 4 * (order + 1)`), so the semivariance is finite for any order and lag (no
`0 * Infinity`): it tends to `nugget` for tiny lags, also for orders far above 100. The semivariance
oscillates around `nugget + psill` and tends to this value for an infinite lag.

Parameters:

- `order` (double, optional): the order of the Bessel function of the first kind;
  must be non-negative; defaults to `1.0`, the same default as [[bessel]] (and the order used by
  [[fit-params]] for `:bessel` when `:parameter` is not given)

Returns a semivariogram model constructor `(fn [params])` that accepts a map with:
- `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
  variation or measurement error; must be non-negative
- `:psill` (double): the partial sill; the amplitude of the oscillation; must be non-negative
- `:range` (double): the scale parameter controlling the period of oscillation; must be positive

The constructor itself returns a function `(fn ^double [^double x])` that computes the
semivariance for a given lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[bessel]], [[->matern]], [[hole]].
raw docstring

->hypersphericalclj

(->hyperspherical)
(->hyperspherical order)

Creates a hyperspherical semivariogram model constructor for a given sphere dimension order.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (h * 2F1(0.5, d, 1.5, h^2) / 2F1(0.5, d, 1.5, 1.0))
  • x > range: nugget + psill

where h = x / range, d = -0.5 * (order - 1) and 2F1 is the Gauss hypergeometric function. The denominator 2F1(0.5, d, 1.5, 1.0) is a normalisation constant ensuring the model reaches exactly psill at range.

Accuracy (measured against 100-digit mpmath, fastmath.special/hypergeometric-2F1 terminating and half-integer cases): the absolute error is below 3e-14 for the dimensions up to 121 (odd and even).

Parameters:

  • order (double, optional): the sphere dimension; must be a positive real number; 2.0 recovers circular, 3.0 recovers spherical; defaults to 2.0

Returns a semivariogram model constructor (fn [params]) that accepts a map with:

  • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
  • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
  • :range (double): the range at which the sill is reached exactly; must be positive

The constructor itself returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also hyperspherical, ->superspherical, spherical, circular.

Creates a hyperspherical semivariogram model constructor for a given sphere dimension `order`.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (h * 2F1(0.5, d, 1.5, h^2) / 2F1(0.5, d, 1.5, 1.0))`
- `x > range`: `nugget + psill`

where `h = x / range`, `d = -0.5 * (order - 1)` and `2F1` is the Gauss hypergeometric function.
The denominator `2F1(0.5, d, 1.5, 1.0)` is a normalisation constant ensuring the model
reaches exactly `psill` at `range`.

Accuracy (measured against 100-digit mpmath, `fastmath.special/hypergeometric-2F1` terminating and half-integer cases): the absolute error is below `3e-14` for the dimensions up to 121 (odd and even).

Parameters:

- `order` (double, optional): the sphere dimension; must be a positive real number;
  `2.0` recovers [[circular]], `3.0` recovers [[spherical]]; defaults to `2.0`

Returns a semivariogram model constructor `(fn [params])` that accepts a map with:
- `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
  variation or measurement error; must be non-negative
- `:psill` (double): the partial sill; the structured spatial variance above the nugget;
  must be non-negative
- `:range` (double): the range at which the sill is reached exactly; must be positive

The constructor itself returns a function `(fn ^double [^double x])` that computes the
semivariance for a given lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[hyperspherical]], [[->superspherical]], [[spherical]], [[circular]].
raw docstring

->maternclj

(->matern)
(->matern order)

Creates a Matérn semivariogram model constructor for a given smoothness order.

The formula is: nugget + psill * (1 - C(order) * (sqrt(2*order) * x / range)^order * K_order(sqrt(2*order) * x / range))

where C(order) = 2^(1-order) / Γ(order) is a normalisation constant ensuring the kernel equals 1.0 at the origin, Γ is the gamma function and K_order is the modified Bessel function of the second kind of the given order.

The scale is sqrt(2 * order) * x / range, so range is the length scale of the textbook form (Rasmussen and Williams), which differs from the gstat Mat and Ste ranges. order = 0.5 is exponential with the same range. The limit of large order is a Gaussian model with the length scale range, that is gaussian with the range range * sqrt(2) (exp(-(x / range)^2 / 2) is exp(-(x / (range * sqrt 2))^2)).

The product of the power and the Bessel function is evaluated without overflow: for order >= 20 the factor is computed from a series (small lags) or a log-domain uniform expansion, so the semivariance is finite for any order and lag and tends to nugget for tiny lags. For orders below 20 a product which is not finite (lags below about 1e-30) is replaced by its limit, so the semivariance is nugget.

Parameters:

  • order (double, optional): the smoothness order of the Matérn model; must be positive; defaults to 1.0

Returns a semivariogram model constructor (fn [params]) that accepts a map with:

  • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
  • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
  • :range (double): the range parameter controlling the horizontal scale; must be positive

The constructor itself returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also matern, ->bessel, gaussian, exponential.

Creates a Matérn semivariogram model constructor for a given smoothness `order`.

The formula is: `nugget + psill * (1 - C(order) * (sqrt(2*order) * x / range)^order * K_order(sqrt(2*order) * x / range))`

where `C(order) = 2^(1-order) / Γ(order)` is a normalisation constant ensuring the
kernel equals `1.0` at the origin, `Γ` is the gamma function and `K_order` is the
modified Bessel function of the second kind of the given order.

The scale is `sqrt(2 * order) * x / range`, so `range` is the length scale of the textbook form (Rasmussen and Williams), which differs from the gstat `Mat` and `Ste` ranges. `order = 0.5` is [[exponential]] with the same `range`. The limit of large `order` is a Gaussian model with the length scale `range`, that is [[gaussian]] with the range `range * sqrt(2)` (`exp(-(x / range)^2 / 2)` is `exp(-(x / (range * sqrt 2))^2)`).

The product of the power and the Bessel function is evaluated without overflow: for `order >= 20` the factor is computed from a series (small lags) or a log-domain uniform expansion, so the semivariance is finite for any order and lag and tends to `nugget` for tiny lags. For orders below 20 a product which is not finite (lags below about `1e-30`) is replaced by its limit, so the semivariance is `nugget`.

Parameters:

- `order` (double, optional): the smoothness order of the Matérn model; must be positive;
  defaults to `1.0`

Returns a semivariogram model constructor `(fn [params])` that accepts a map with:
- `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
  variation or measurement error; must be non-negative
- `:psill` (double): the partial sill; the maximum contribution of the structured
  spatial variance above the nugget; must be non-negative
- `:range` (double): the range parameter controlling the horizontal scale; must be positive

The constructor itself returns a function `(fn ^double [^double x])` that computes the
semivariance for a given lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[matern]], [[->bessel]], [[gaussian]], [[exponential]].
raw docstring

->quantile-estimatorclj

(->quantile-estimator p)

Creates a quantile (Armstrong and Delfiner) empirical semivariogram estimator for given p.

The estimate of the variogram is the p-quantile of the squared differences divided by the p-quantile of the chi-squared distribution with one degree of freedom.

Parameters:

  • p (double): the quantile level, must be in (0.0, 1.0)

Returns a function (fn [n diffs]) (the arguments are the number of pairs in the bin, not used, and the differences of the pair values) which returns the estimate of the variogram (twice the semivariance; empirical halves it). Throws ex-info for p outside (0.0, 1.0).

See also empirical, dowd-estimator.

Creates a quantile (Armstrong and Delfiner) empirical semivariogram estimator for given `p`.

The estimate of the variogram is the `p`-quantile of the squared differences divided by the `p`-quantile of the chi-squared distribution with one degree of freedom.

Parameters:

- `p` (double): the quantile level, must be in `(0.0, 1.0)`

Returns a function `(fn [n diffs])` (the arguments are the number of pairs in the bin, not used, and the differences of the pair values) which returns the estimate of the variogram (twice the semivariance; [[empirical]] halves it). Throws `ex-info` for `p` outside `(0.0, 1.0)`.

See also [[empirical]], [[dowd-estimator]].
raw docstring

->supersphericalclj

(->superspherical)
(->superspherical order)

Creates a superspherical semivariogram model constructor for a given order.

The superspherical model is a bounded semivariogram from the same family as ->hyperspherical, using the Gauss hypergeometric function 2F1 with d = -order instead of d = -0.5 * (order - 1). It is a compact reparametrisation of the hyperspherical family: superspherical order corresponds to hyperspherical dimension 2 * order + 1. Notable special cases are order = 0.0, which recovers the linear model, order = 0.5, which recovers the circular model, and order = 1.0 (default), which recovers the standard spherical model. Like all members of the spherical family, it reaches the sill (nugget + psill) exactly at range and remains constant beyond it.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (h * 2F1(0.5, -order, 1.5, h^2) / 2F1(0.5, -order, 1.5, 1.0))
  • x > range: nugget + psill

where h = x / range and 2F1 is the Gauss hypergeometric function. The denominator 2F1(0.5, -order, 1.5, 1.0) is a normalisation constant ensuring the model reaches exactly psill at range.

Accuracy (measured against 100-digit mpmath): the absolute error is below 6e-14 for the orders up to 90 (integer and half-integer).

Parameters:

  • order (double, optional): the shape order; must be non-negative; 0.0 gives linear, 0.5 gives circular, 1.0 gives spherical; defaults to 1.0

Returns a semivariogram model constructor (fn [params]) that accepts a map with:

  • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
  • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
  • :range (double): the range at which the sill is reached exactly; must be positive

The constructor itself returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also superspherical, ->hyperspherical, spherical, circular, linear.

Creates a superspherical semivariogram model constructor for a given `order`.

The superspherical model is a bounded semivariogram from the same family as
[[->hyperspherical]], using the Gauss hypergeometric function `2F1` with `d = -order`
instead of `d = -0.5 * (order - 1)`. It is a compact reparametrisation of the
hyperspherical family: superspherical `order` corresponds to hyperspherical dimension
`2 * order + 1`. Notable special cases are `order = 0.0`, which recovers the [[linear]]
model, `order = 0.5`, which recovers the [[circular]] model, and `order = 1.0` (default),
which recovers the standard [[spherical]] model. Like all members of the spherical family,
it reaches the sill (`nugget + psill`) exactly at `range` and remains constant beyond it.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (h * 2F1(0.5, -order, 1.5, h^2) / 2F1(0.5, -order, 1.5, 1.0))`
- `x > range`: `nugget + psill`

where `h = x / range` and `2F1` is the Gauss hypergeometric function.
The denominator `2F1(0.5, -order, 1.5, 1.0)` is a normalisation constant ensuring the
model reaches exactly `psill` at `range`.

Accuracy (measured against 100-digit mpmath): the absolute error is below `6e-14` for the orders up to 90 (integer and half-integer).

Parameters:

- `order` (double, optional): the shape order; must be non-negative; `0.0` gives [[linear]],
  `0.5` gives [[circular]], `1.0` gives [[spherical]]; defaults to `1.0`

Returns a semivariogram model constructor `(fn [params])` that accepts a map with:
- `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
  variation or measurement error; must be non-negative
- `:psill` (double): the partial sill; the structured spatial variance above the nugget;
  must be non-negative
- `:range` (double): the range at which the sill is reached exactly; must be positive

The constructor itself returns a function `(fn ^double [^double x])` that computes the
semivariance for a given lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[superspherical]], [[->hyperspherical]], [[spherical]], [[circular]], [[linear]].
raw docstring

->tplstableclj

(->tplstable)
(->tplstable H)

Creates a Truncated-Power-Law (TPL) Stable semivariogram model constructor for a given Hurst exponent H.

The TPL Stable model is a bounded (asymptotic) semivariogram that captures both short-range power-law growth and long-range correlation decay. The Hurst exponent H controls the fractal dimension and long-range dependence of the underlying spatial process; values closer to 1.0 indicate stronger long-range persistence, while values closer to 0.0 indicate stronger short-range variability. The beta parameter (provided at construction time via params) shapes the power-law growth rate similarly to power and expower. The semivariance asymptotically approaches the sill (nugget + psill) as lag distance increases.

The formula is: nugget + psill * (1 - Ha * E_{1+Ha}(h^beta))

where h = x / range, Ha = 2H / beta and E_n is the generalised exponential integral. The factor Ha * E_{1+Ha}(0) = 1 ensures the semivariance is 0.0 at the origin.

Parameters:

  • H (double, optional): the Hurst exponent controlling long-range dependence; must be in (0.0, 1.0); defaults to 0.5

Returns a semivariogram model constructor (fn [params]) that accepts a map with:

  • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
  • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
  • :range (double): the scale parameter controlling the horizontal extent; must be positive
  • :beta (double): the power exponent controlling the short-range growth rate; must be in (0.0, 2.0] for a valid conditionally negative-definite model

The constructor itself returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also tplstable, power, expower, matern.

Creates a Truncated-Power-Law (TPL) Stable semivariogram model constructor for a given Hurst exponent `H`.

The TPL Stable model is a bounded (asymptotic) semivariogram that captures both
short-range power-law growth and long-range correlation decay. The Hurst exponent `H`
controls the fractal dimension and long-range dependence of the underlying spatial
process; values closer to `1.0` indicate stronger long-range persistence, while values
closer to `0.0` indicate stronger short-range variability. The `beta` parameter (provided
at construction time via `params`) shapes the power-law growth rate similarly to [[power]]
and [[expower]]. The semivariance asymptotically approaches the sill (`nugget + psill`)
as lag distance increases.

The formula is: `nugget + psill * (1 - Ha * E_{1+Ha}(h^beta))`

where `h = x / range`, `Ha = 2H / beta` and `E_n` is the generalised exponential integral.
The factor `Ha * E_{1+Ha}(0) = 1` ensures the semivariance is `0.0` at the origin.

Parameters:

- `H` (double, optional): the Hurst exponent controlling long-range dependence;
  must be in `(0.0, 1.0)`; defaults to `0.5`

Returns a semivariogram model constructor `(fn [params])` that accepts a map with:
- `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
  variation or measurement error; must be non-negative
- `:psill` (double): the partial sill; the maximum contribution of the structured
  spatial variance above the nugget; must be non-negative
- `:range` (double): the scale parameter controlling the horizontal extent; must be positive
- `:beta` (double): the power exponent controlling the short-range growth rate;
  must be in `(0.0, 2.0]` for a valid conditionally negative-definite model

The constructor itself returns a function `(fn ^double [^double x])` that computes the
semivariance for a given lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[tplstable]], [[power]], [[expower]], [[matern]].
raw docstring

besselclj

(bessel params)

BesselJ semivariogram model.

A convenience wrapper around ->bessel that reads the Bessel function order directly from the params map. When :order is not provided, defaults to 1.0.

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the amplitude of the oscillation; must be non-negative
    • :range (double): the scale parameter controlling the period of oscillation; must be positive
    • :order (double, optional): the order of the Bessel function of the first kind; must be non-negative; defaults to 1.0

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also ->bessel, matern, hole.

BesselJ semivariogram model.

A convenience wrapper around [[->bessel]] that reads the Bessel function order directly
from the `params` map. When `:order` is not provided, defaults to `1.0`.

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the amplitude of the oscillation; must be non-negative
    - `:range` (double): the scale parameter controlling the period of oscillation; must be positive
    - `:order` (double, optional): the order of the Bessel function of the first kind;
      must be non-negative; defaults to `1.0`

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[->bessel]], [[matern]], [[hole]].
raw docstring

bounding-box-diagonalclj

(bounding-box-diagonal dist xs)

Length of the diagonal of bounding box of spatial points.

Parameters:

  • dist (function): a binary distance function (fn [x1 x2])
  • xs (sequence): the points, scalars or vectors; at least one point

Returns the distance between the points made of the minimum and the maximum coordinates. It is 0.0 for a single point.

See also empirical.

Length of the diagonal of bounding box of spatial points.

Parameters:

- `dist` (function): a binary distance function `(fn [x1 x2])`
- `xs` (sequence): the points, scalars or vectors; at least one point

Returns the distance between the points made of the minimum and the maximum coordinates. It is `0.0` for a single point.

See also [[empirical]].
raw docstring

cauchyclj

(cauchy {:keys [nugget psill range beta]})

Generalized Cauchy semivariogram model.

The formula is: nugget + psill * (1 - (1 + (x / range)^2)^(-beta))

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range parameter controlling the horizontal scale; must be positive
    • :beta (double): the decay exponent controlling the rate of convergence to the sill and the heaviness of the correlation tail; must be positive for a valid model

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also rational, gaussian, exponential, matern.

Generalized Cauchy semivariogram model.

The formula is: `nugget + psill * (1 - (1 + (x / range)^2)^(-beta))`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the maximum contribution of the structured
      spatial variance above the nugget; must be non-negative
    - `:range` (double): the range parameter controlling the horizontal scale; must be positive
    - `:beta` (double): the decay exponent controlling the rate of convergence to the sill
      and the heaviness of the correlation tail; must be positive for a valid model

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[rational]], [[gaussian]], [[exponential]], [[matern]].
raw docstring

circularclj

(circular {:keys [nugget psill range]})

Circular semivariogram model.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (2/pi) * ((x/range) * sqrt(1 - (x/range)^2) + arcsin(x/range))
  • x > range: nugget + psill

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also spherical, pentaspherical, cubic, linear.

Circular semivariogram model.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (2/pi) * ((x/range) * sqrt(1 - (x/range)^2) + arcsin(x/range))`
- `x > range`: `nugget + psill`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[spherical]], [[pentaspherical]], [[cubic]], [[linear]].
raw docstring

cressie-estimatorclj

(cressie-estimator n diffs)

Cressie and Hawkins (robust) empirical semivariogram estimator.

The estimate of the variogram is (mean(sqrt(abs(d))))^4 / (0.457 + 0.494 / N + 0.045 / N^2), where d are the differences of the pair values and N is the number of pairs. The constant is the one of Hawkins and Cressie (1984), which removes the bias of the fourth power for the Gaussian data; it is the one of scikit-gstat. The gstat and geoR packages omit the last term 0.045 / N^2: their value is larger by 4.5% for N equal 1 and by 7.4e-4 for N equal 11 (the difference vanishes for large bins).

Parameters:

  • n (long): number of pairs in the bin
  • diffs (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; empirical halves it).

See also empirical, matheron-estimator, highly-robust-estimator, dowd-estimator.

Cressie and Hawkins (robust) empirical semivariogram estimator.

The estimate of the variogram is `(mean(sqrt(abs(d))))^4 / (0.457 + 0.494 / N + 0.045 / N^2)`, where `d` are the differences of the pair values and `N` is the number of pairs. The constant is the one of Hawkins and Cressie (1984), which removes the bias of the fourth power for the Gaussian data; it is the one of scikit-gstat. The gstat and geoR packages omit the last term `0.045 / N^2`: their value is larger by 4.5% for `N` equal 1 and by 7.4e-4 for `N` equal 11 (the difference vanishes for large bins).

Parameters:

- `n` (long): number of pairs in the bin
- `diffs` (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; [[empirical]] halves it).

See also [[empirical]], [[matheron-estimator]], [[highly-robust-estimator]], [[dowd-estimator]].
raw docstring

cubicclj

(cubic {:keys [nugget psill range]})

Cubic semivariogram model.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (7*(x/range)^2 - 8.75*(x/range)^3 + 3.5*(x/range)^5 - 0.75*(x/range)^7)
  • x > range: nugget + psill

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also spherical, pentaspherical, gaussian, circular.

Cubic semivariogram model.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (7*(x/range)^2 - 8.75*(x/range)^3 + 3.5*(x/range)^5 - 0.75*(x/range)^7)`
- `x > range`: `nugget + psill`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[spherical]], [[pentaspherical]], [[gaussian]], [[circular]].
raw docstring

dowd-estimatorclj

(dowd-estimator _ diffs)

Dowd's empirical semivariogram estimator.

The estimate of the variogram is 2.198109... * (median(abs(d)))^2, where d are the differences of the pair values (Dowd 1984); the constant is the reciprocal of the median of the chi-squared distribution with one degree of freedom, so the estimate is consistent for Gaussian data. For an even number of pairs the median of the absolute differences is averaged before squaring; this is not the same as the median of the squared differences, which is what the quantile estimator ->quantile-estimator with p equal 0.5 computes.

Parameters:

  • n (long): number of pairs in the bin (not used)
  • diffs (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; empirical halves it). NaN for an empty diffs.

See also empirical, ->quantile-estimator, cressie-estimator, matheron-estimator.

Dowd's empirical semivariogram estimator.

The estimate of the variogram is `2.198109... * (median(abs(d)))^2`, where `d` are the differences of the pair values (Dowd 1984); the constant is the reciprocal of the median of the chi-squared distribution with one degree of freedom, so the estimate is consistent for Gaussian data. For an even number of pairs the median of the absolute differences is averaged before squaring; this is not the same as the median of the squared differences, which is what the quantile estimator [[->quantile-estimator]] with `p` equal `0.5` computes.

Parameters:

- `n` (long): number of pairs in the bin (not used)
- `diffs` (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; [[empirical]] halves it). `NaN` for an empty `diffs`.

See also [[empirical]], [[->quantile-estimator]], [[cressie-estimator]], [[matheron-estimator]].
raw docstring

empiricalclj

(empirical xs ys)
(empirical xs ys params)

Computes the empirical (experimental) semivariogram from spatial data.

All pairs of spatial locations are formed, filtered by the cutoff distance, and grouped into lag bins. For each bin, a chosen estimator computes the gamma value, the classical one is half the average squared difference between the paired observations. The result is the primary input to fit and fit-params for fitting a parametric semivariogram model.

The bins divide the interval (0, dmax] into :bins equal parts, where dmax is the largest distance among the pairs kept by the cutoff (not the cutoff). A bin includes its right edge and excludes the left one. This is the same as the explicit boundaries of the gstat variogram function with the same edges; the classical estimator then equals gstat (counts, mean lags and gamma), but the default bins of gstat (the cutoff divided by 15) are different.

Parameters:

  • xs (sequence): spatial positions of observations; each element may be a scalar or a vector depending on the dimensionality of the data
  • ys (sequence): observed values at positions xs; must have the same length as xs
  • params (map, optional): configuration map with the following keys (a nil value is the same as a missing key):
    • :bins (long): number of lag bins; controls the resolution of the semivariogram; defaults to 15; must be at least 1
    • :cutoff (double): maximum lag distance to include; pairs beyond this distance are excluded; defaults to the bounding box diagonal divided by :diagonal-den
    • :diagonal-den (double): divisor applied to the bounding box diagonal to derive the default cutoff; defaults to 3.0; ignored when :cutoff is provided explicitly
    • :estimator (keyword or function): the estimator used to compute gamma per bin; defaults to :classical; built-in options are:
      • :classical / :matheron - Matheron classical estimator (matheron-estimator)
      • :cressie - Cressie robust estimator (cressie-estimator)
      • :genton / :highly-robust - Genton highly robust estimator (highly-robust-estimator)
      • :dowd - Dowd estimator (dowd-estimator)
      • :quantile - Armstrong and Delfiner quantile estimator at level :quantile (->quantile-estimator)
      • :m-robust - Gunst and Hartfield robust M-estimator (robust-m-estimator)
      • a custom (fn [^long n diffs]) where n is the number of pairs in the bin and diffs is a sequence of pairwise differences; it returns the estimate of the variogram (twice the semivariance)
    • :quantile (double): quantile level used by the :quantile estimator; must be in (0.0, 1.0); defaults to 0.9
    • :remove-outliers?: whether to remove outliers from the raw data before binning; defaults to false; accepted values are:
    • :distance (function): a binary distance function (fn [x1 x2]) applied to elements of xs; defaults to fastmath.distance/euclidean

Returns a vector of maps sorted by ascending lag h, one per non-empty bin, each containing:

  • :n (long): number of point pairs in the bin (not the number of points)
  • :h (double): mean lag distance of pairs in the bin
  • :gamma (double): estimated semivariance for the bin

Pairs of points at distance zero (duplicated locations) are dropped, as pairs with NaN distance. A bin whose estimate is not finite, although all the differences of its pairs are finite, is dropped: the robust estimators highly-robust-estimator and robust-m-estimator are not defined for a bin with a single pair. A NaN in ys is not dropped: it gives a NaN gamma (which fit-params rejects).

Throws ex-info (with :type :invalid-input and the key :property) when xs and ys have different lengths, there are fewer than two points, :bins is below 1, the estimator is unknown, no pair is left within the cutoff (all the points at one location, the cutoff too small, too many outliers removed) or no bin has a finite estimate.

See also fit, fit-params, bounding-box-diagonal, matheron-estimator, cressie-estimator, highly-robust-estimator, dowd-estimator, ->quantile-estimator, robust-m-estimator.

Computes the empirical (experimental) semivariogram from spatial data.

All pairs of spatial locations are formed, filtered by the cutoff distance, and grouped
into lag bins. For each bin, a chosen estimator computes the gamma value, the classical one is
half the average squared difference between the paired observations. The result is the primary
input to [[fit]] and [[fit-params]] for fitting a parametric semivariogram model.

The bins divide the interval `(0, dmax]` into `:bins` equal parts, where `dmax` is the largest distance among the pairs kept by the cutoff (not the cutoff). A bin includes its right edge and excludes the left one. This is the same as the explicit `boundaries` of the gstat `variogram` function with the same edges; the classical estimator then equals gstat (counts, mean lags and gamma), but the default bins of gstat (the cutoff divided by 15) are different.

Parameters:

- `xs` (sequence): spatial positions of observations; each element may be a scalar or
  a vector depending on the dimensionality of the data
- `ys` (sequence): observed values at positions `xs`; must have the same length as `xs`
- `params` (map, optional): configuration map with the following keys (a `nil` value is the same as a missing key):
    - `:bins` (long): number of lag bins; controls the resolution of the semivariogram;
      defaults to `15`; must be at least `1`
    - `:cutoff` (double): maximum lag distance to include; pairs beyond this distance are
      excluded; defaults to the bounding box diagonal divided by `:diagonal-den`
    - `:diagonal-den` (double): divisor applied to the bounding box diagonal to derive
      the default cutoff; defaults to `3.0`; ignored when `:cutoff` is provided explicitly
    - `:estimator` (keyword or function): the estimator used to compute gamma per bin;
      defaults to `:classical`; built-in options are:
        - `:classical` / `:matheron` - Matheron classical estimator ([[matheron-estimator]])
        - `:cressie` - Cressie robust estimator ([[cressie-estimator]])
        - `:genton` / `:highly-robust` - Genton highly robust estimator ([[highly-robust-estimator]])
        - `:dowd` - Dowd estimator ([[dowd-estimator]])
        - `:quantile` - Armstrong and Delfiner quantile estimator at level `:quantile` ([[->quantile-estimator]])
        - `:m-robust` - Gunst and Hartfield robust M-estimator ([[robust-m-estimator]])
        - a custom `(fn [^long n diffs])` where `n` is the number of pairs in the bin and `diffs` is a
          sequence of pairwise differences; it returns the estimate of the variogram (twice the semivariance)
    - `:quantile` (double): quantile level used by the `:quantile` estimator;
      must be in `(0.0, 1.0)`; defaults to `0.9`
    - `:remove-outliers?`: whether to remove outliers from the raw data before binning;
      defaults to `false`; accepted values are:
        - `false` - no outlier removal
        - `true` - Tukey's fences criterion (IQR-based, k=1.5) via [[remove-outliers-fence]]
        - `:mad` - median absolute deviation criterion via [[remove-outliers-mad]]
      the outliers are searched in the values `ys`, not in the pair differences, see [[maybe-remove-outliers]]
    - `:distance` (function): a binary distance function `(fn [x1 x2])` applied to
      elements of `xs`; defaults to `fastmath.distance/euclidean`

Returns a vector of maps sorted by ascending lag `h`, one per non-empty bin, each containing:
- `:n` (long): number of point pairs in the bin (not the number of points)
- `:h` (double): mean lag distance of pairs in the bin
- `:gamma` (double): estimated semivariance for the bin

Pairs of points at distance zero (duplicated locations) are dropped, as pairs with `NaN` distance. A bin whose estimate is not finite, although all the differences of its pairs are finite, is dropped: the robust estimators [[highly-robust-estimator]] and [[robust-m-estimator]] are not defined for a bin with a single pair. A `NaN` in `ys` is not dropped: it gives a `NaN` gamma (which [[fit-params]] rejects).

Throws `ex-info` (with `:type :invalid-input` and the key `:property`) when `xs` and `ys` have different lengths, there are fewer than two points, `:bins` is below `1`, the estimator is unknown, no pair is left within the cutoff (all the points at one location, the cutoff too small, too many outliers removed) or no bin has a finite estimate.

See also [[fit]], [[fit-params]], [[bounding-box-diagonal]],
[[matheron-estimator]], [[cressie-estimator]], [[highly-robust-estimator]],
[[dowd-estimator]], [[->quantile-estimator]], [[robust-m-estimator]].
raw docstring

exponentialclj

(exponential {:keys [nugget psill range]})

Exponential semivariogram model.

The formula is: nugget + psill * (1 - exp(-x / range))

range is the scale of the exponential (the gstat Exp range), not the practical range: the structured part reaches 95% of psill at about 3 * range (exactly 1 - exp(-3) = 0.9502 of it at 3 * range) and never reaches the sill.

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
    • :range (double): the scale parameter controlling how fast the semivariance rises towards the sill (the sill is approached asymptotically); must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also gaussian, spherical, power, expower, hole.

Exponential semivariogram model.

The formula is: `nugget + psill * (1 - exp(-x / range))`

`range` is the scale of the exponential (the gstat `Exp` range), not the practical range: the structured part reaches 95% of `psill` at about `3 * range` (exactly `1 - exp(-3)` = 0.9502 of it at `3 * range`) and never reaches the sill.

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the maximum contribution of the structured
      spatial variance above the nugget; must be non-negative
    - `:range` (double): the scale parameter controlling how fast the semivariance
      rises towards the sill (the sill is approached asymptotically); must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[gaussian]], [[spherical]], [[power]], [[expower]], [[hole]].
raw docstring

expowerclj

(expower {:keys [nugget psill range beta]})

Exponential-power (stable) semivariogram model.

The formula is: nugget + psill * (1 - exp(-(x / range)^beta))

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range parameter controlling the horizontal scale; must be positive
    • :beta (double): the power exponent controlling the curvature near the origin; must be in (0.0, 2.0] (the valid range of the model); 1.0 is exponential, 2.0 is gaussian

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also exponential, gaussian, power, cauchy.

Exponential-power (stable) semivariogram model.

The formula is: `nugget + psill * (1 - exp(-(x / range)^beta))`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the maximum contribution of the structured
      spatial variance above the nugget; must be non-negative
    - `:range` (double): the range parameter controlling the horizontal scale; must be positive
    - `:beta` (double): the power exponent controlling the curvature near the origin;
      must be in `(0.0, 2.0]` (the valid range of the model); `1.0` is [[exponential]], `2.0` is [[gaussian]]

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[exponential]], [[gaussian]], [[power]], [[cauchy]].
raw docstring

fitclj

(fit empirical-variogram semivariogram-model)
(fit empirical-variogram semivariogram-model parameters)

Fits a parametric semivariogram model to an empirical semivariogram and returns the fitted model function.

A convenience wrapper around fit-params that returns only the fitted semivariogram function. Use fit-params directly when access to the fitted parameters, weights, or loss value is needed for diagnostics.

Parameters:

  • empirical-variogram (sequence of maps): empirical semivariogram data as returned by empirical; each map must contain :h, :gamma and :n keys
  • semivariogram-model (keyword or function): the parametric model to fit; accepted values are:
    • a keyword naming a built-in model: :linear, :spherical, :circular, :cubic, :pentaspherical, :gaussian, :exponential, :hole, :power, :tpower, :expower, :cauchy, :rational, :bessel, :matern, :hyperspherical, :superspherical, :tplstable
    • an RBF kernel function, automatically wrapped via rbf->variogram; a function is always taken as a kernel, so a model constructor such as gaussian is not accepted (use :gaussian)
  • parameters (map, optional): configuration map; all keys are described in full in fit-params; the most commonly used keys are:
    • :estimation (keyword): loss function; :sq least squares (default), :abs, :soft, :huber, :cauchy, :atan
    • :weights: per-bin weighting scheme; defaults to :n (number of pairs); accepts :n, :nh, :nh+, :nhh, :nhh+, :nexp, :nsqrt, :ngg, :ngg2, a sequence of explicit weights, or a function (fn ^double [^double h])
    • :defaults (map): fixed parameter values excluded from optimisation; keys are a subset of :nugget, :psill, :range, :beta
    • :parameter (double): order for :bessel (default 1.0), :matern, :hyperspherical, :superspherical; Hurst exponent H for :tplstable
    • :bounds (map): overrides for default parameter search bounds; keys are a subset of :nugget, :psill, :range, :beta, each mapping to a [lo hi] vector; the default bounds bind often (see the trade-off in fit-params)
    • :rng, :N: random number generator and number of the scanned starting points; a seeded generator makes the fit reproducible

Returns the fitted semivariogram function (fn ^double [^double x]).

Throws ex-info for invalid input, see fit-params.

See also fit-params, empirical, rbf->variogram.

Fits a parametric semivariogram model to an empirical semivariogram and returns the fitted model function.

A convenience wrapper around [[fit-params]] that returns only the fitted semivariogram
function. Use [[fit-params]] directly when access to the fitted parameters, weights, or
loss value is needed for diagnostics.

Parameters:

- `empirical-variogram` (sequence of maps): empirical semivariogram data as returned by
  [[empirical]]; each map must contain `:h`, `:gamma` and `:n` keys
- `semivariogram-model` (keyword or function): the parametric model to fit; accepted values are:
    - a keyword naming a built-in model: `:linear`, `:spherical`, `:circular`,
      `:cubic`, `:pentaspherical`, `:gaussian`, `:exponential`, `:hole`, `:power`,
      `:tpower`, `:expower`, `:cauchy`, `:rational`, `:bessel`, `:matern`,
      `:hyperspherical`, `:superspherical`, `:tplstable`
    - an RBF kernel function, automatically wrapped via [[rbf->variogram]]; a function is always taken as a kernel, so a model constructor such as [[gaussian]] is not accepted (use `:gaussian`)
- `parameters` (map, optional): configuration map; all keys are described in full in
  [[fit-params]]; the most commonly used keys are:
    - `:estimation` (keyword): loss function; `:sq` least squares (default), `:abs`,
      `:soft`, `:huber`, `:cauchy`, `:atan`
    - `:weights`: per-bin weighting scheme; defaults to `:n` (number of pairs); accepts
      `:n`, `:nh`, `:nh+`, `:nhh`, `:nhh+`, `:nexp`, `:nsqrt`, `:ngg`, `:ngg2`,
      a sequence of explicit weights, or a function `(fn ^double [^double h])`
    - `:defaults` (map): fixed parameter values excluded from optimisation; keys are a
      subset of `:nugget`, `:psill`, `:range`, `:beta`
    - `:parameter` (double): order for `:bessel` (default `1.0`), `:matern`, `:hyperspherical`,
      `:superspherical`; Hurst exponent `H` for `:tplstable`
    - `:bounds` (map): overrides for default parameter search bounds; keys are a subset
      of `:nugget`, `:psill`, `:range`, `:beta`, each mapping to a `[lo hi]` vector; the default
      bounds bind often (see the trade-off in [[fit-params]])
    - `:rng`, `:N`: random number generator and number of the scanned starting points; a seeded
      generator makes the fit reproducible

Returns the fitted semivariogram function `(fn ^double [^double x])`.

Throws `ex-info` for invalid input, see [[fit-params]].

See also [[fit-params]], [[empirical]], [[rbf->variogram]].
raw docstring

fit-paramsclj

(fit-params empirical-semivariogram semivariogram-model)
(fit-params empirical-semivariogram semivariogram-model params)

Fits a parametric semivariogram model to an empirical semivariogram and returns a detailed result map.

Minimises a weighted loss between the model predictions and the empirical gamma values using L-BFGS-B numerical optimisation with jitter-based multi-start via fastmath.optimization/scan-and-minimize. Parameters fixed via :defaults are excluded from the optimisation. When all parameters are fixed, no optimisation is performed. Returns a richer result than fit, including the fitted parameters, weights, and final loss value. Useful for model diagnostics and manual inspection of the fit quality.

Parameters:

  • empirical-semivariogram (sequence of maps): empirical semivariogram data as returned by empirical; each map must contain :h, :gamma and :n keys, all finite
  • semivariogram-model (keyword or function): the parametric model to fit; accepted values are:
    • a keyword naming a built-in model: :linear, :spherical, :circular, :cubic, :pentaspherical, :gaussian, :exponential, :hole, :power, :tpower, :expower, :cauchy, :rational, :bessel, :matern, :hyperspherical, :superspherical, :tplstable
    • an RBF kernel function (any function is taken as a kernel), which is automatically wrapped via rbf->variogram; a model constructor such as gaussian is a function too, but it is not a kernel and is not accepted: use its keyword
  • params (map, optional): configuration map with the following keys (a nil value is the same as a missing key, except for :weights where nil means the uniform weights):
    • :estimation (keyword): loss function used during fitting; defaults to :sq:
      • :sq - squared difference (weighted least squares, default)
      • :abs - absolute difference
      • :soft - soft L1 (pseudo-Huber)
      • :huber - Huber loss
      • :cauchy - Cauchy/Lorentzian loss
      • :atan - arctangent loss
    • :weights: weighting scheme applied to the per-bin loss terms; defaults to :n:
      • nil - uniform weights (all 1.0)
      • :n - number of pairs in each bin (default)
      • :nh - N divided by lag h
      • :nh+ - N divided by scaled lag h+ where h+ = (h+1)/(hmax+1)
      • :nhh - N divided by squared lag h^2
      • :nhh+ - N divided by squared scaled lag h+^2
      • :nexp - N divided by exp(1/h+)
      • :nsqrt - N divided by sqrt(h+)
      • :ngg - Cressie weights: N divided by squared model gamma; recomputed from the fitted model after optimisation
      • :ngg2 - N times empirical gamma divided by cubed model gamma; recomputed from the fitted model after optimisation. The loss is degenerate for the models of the power family (:power, :tpower, :tplstable): the weights grow without bound when the model goes to zero, and the optimum collapses (range at the lower bound, beta far from the data), do not use it for them
      • a sequence of explicit per-bin weights (finite numbers, one for every bin)
      • a function (fn ^double [^double h]) returning a scale per bin; the final weight is N divided by the absolute value of the function result
    • :defaults (map): fixed parameter values excluded from optimisation; keys are a subset of :nugget, :psill, :range, :beta; fitting is performed only for the remaining parameters. When all parameters are provided, no optimisation runs.
    • :parameter (double): the order or shape parameter passed to model constructors that support it; used as the order argument for :bessel, :matern, :hyperspherical, :superspherical, and as H for :tplstable; when it is not given the default of the constructor is used: 1.0 for :bessel (the same as bessel), 1.0 for :matern, 2.0 for :hyperspherical, 1.0 for :superspherical and 0.5 for :tplstable
    • :bounds (map): overrides for the default parameter search bounds; keys are a subset of :nugget, :psill, :range, :beta, each mapping to a [lo hi] vector; default bounds are:
      • :nugget - [0.0, 5 * min-gamma], where min-gamma is the smallest non-zero gamma
      • :psill - [0.0, 5 * max-gamma]
      • :range - [EPSILON, max-h], where max-h is the largest lag of the empirical semivariogram
      • :beta - the valid interval of the model: [EPSILON, 2.0] for :power, :expower and :tplstable, [EPSILON, 30.0] for :tpower, :rational and :cauchy; a model checks its parameters when it is built, so a :beta bound outside the valid interval makes the evaluation throw The default bounds bind often: the range is capped by the largest lag and the nugget by the smallest gamma, so when the true range is beyond the data the fit stops at the bound (the fitted range equals max-h). Wider bounds (for example {:range [1e-10 (* 10 max-h)]}) improve the fit of most models, in the research data the loss dropped by up to 195% for single bins and the median change was negligible, but they degrade :linear, whose loss is flat in the range direction (about 2.5 times the optimal loss), and extremely wide bounds degrade every model because the same number of scanned points covers a much larger box (increase :N then)
    • :rng: random number generator (see fastmath.random/rng) drawing the scanned starting points of the optimisation, passed to fastmath.optimization/scan-and-minimize. Seed it to reproduce the result: two fits with equal seeded generators in the same state give bitwise equal parameters. The generator is consumed by the fit. When it is not given a new random generator is used for every call and the fitted parameters vary from run to run (below 1e-6 for most models, more for :hole, :bessel and :linear, which have flat or multimodal losses)
    • :N (long): number of scanned starting points of the optimisation, passed to fastmath.optimization/scan-and-minimize (its default is 100); increase it for wide bounds or many parameters

Returns a map containing:

  • :semivariogram (function): the fitted semivariogram (fn ^double [^double x])
  • :semivariogram-creator (function): the model constructor used to build the semivariogram
  • :params (map): all model parameters, both fitted and fixed via :defaults
  • :weights (sequence): final per-bin weights used to compute the loss
  • :loss (double): the final weighted loss value after fitting

Throws ex-info (with :type :invalid-input and the key :property) for an empty empirical semivariogram, a non-finite :h, :gamma or :n (a NaN in the observations reaches the fit this way), an empirical semivariogram with only zero gamma, an unknown model keyword, :estimation or :weights keyword (the message lists the accepted values), explicit weights of a wrong length or unknown keys in :defaults and :bounds. A model which rejects its parameters throws ex-info as well (see exponential). Throws ex-info with :type :fit-failed when all the optimisation runs fail.

See also fit, empirical, rbf->variogram, variogram->covariance.

Fits a parametric semivariogram model to an empirical semivariogram and returns a detailed result map.

Minimises a weighted loss between the model predictions and the empirical gamma values
using L-BFGS-B numerical optimisation with jitter-based multi-start via
`fastmath.optimization/scan-and-minimize`. Parameters fixed via `:defaults` are excluded
from the optimisation. When all parameters are fixed, no optimisation is performed.
Returns a richer result than [[fit]], including the fitted parameters, weights, and final
loss value. Useful for model diagnostics and manual inspection of the fit quality.

Parameters:

- `empirical-semivariogram` (sequence of maps): empirical semivariogram data as returned
  by [[empirical]]; each map must contain `:h`, `:gamma` and `:n` keys, all finite
- `semivariogram-model` (keyword or function): the parametric model to fit; accepted values are:
    - a keyword naming a built-in model: `:linear`, `:spherical`, `:circular`,
      `:cubic`, `:pentaspherical`, `:gaussian`, `:exponential`, `:hole`, `:power`,
      `:tpower`, `:expower`, `:cauchy`, `:rational`, `:bessel`, `:matern`,
      `:hyperspherical`, `:superspherical`, `:tplstable`
    - an RBF kernel function (any function is taken as a kernel), which is automatically wrapped via [[rbf->variogram]]; a model constructor such as [[gaussian]] is a function too, but it is not a kernel and is not accepted: use its keyword
- `params` (map, optional): configuration map with the following keys (a `nil` value is the same as a missing key, except for `:weights` where `nil` means the uniform weights):
    - `:estimation` (keyword): loss function used during fitting; defaults to `:sq`:
        - `:sq` - squared difference (weighted least squares, default)
        - `:abs` - absolute difference
        - `:soft` - soft L1 (pseudo-Huber)
        - `:huber` - Huber loss
        - `:cauchy` - Cauchy/Lorentzian loss
        - `:atan` - arctangent loss
    - `:weights`: weighting scheme applied to the per-bin loss terms; defaults to `:n`:
        - `nil` - uniform weights (all `1.0`)
        - `:n` - number of pairs in each bin (default)
        - `:nh` - N divided by lag `h`
        - `:nh+` - N divided by scaled lag `h+` where `h+ = (h+1)/(hmax+1)`
        - `:nhh` - N divided by squared lag `h^2`
        - `:nhh+` - N divided by squared scaled lag `h+^2`
        - `:nexp` - N divided by `exp(1/h+)`
        - `:nsqrt` - N divided by `sqrt(h+)`
        - `:ngg` - Cressie weights: N divided by squared model gamma; recomputed from the
          fitted model after optimisation
        - `:ngg2` - N times empirical gamma divided by cubed model gamma; recomputed
          from the fitted model after optimisation. The loss is degenerate for the models of the power family (`:power`, `:tpower`, `:tplstable`): the weights grow without bound when the model goes to zero, and the optimum collapses (range at the lower bound, beta far from the data), do not use it for them
        - a sequence of explicit per-bin weights (finite numbers, one for every bin)
        - a function `(fn ^double [^double h])` returning a scale per bin; the final
          weight is N divided by the absolute value of the function result
    - `:defaults` (map): fixed parameter values excluded from optimisation; keys are a
      subset of `:nugget`, `:psill`, `:range`, `:beta`; fitting is performed only for
      the remaining parameters. When all parameters are provided, no optimisation runs.
    - `:parameter` (double): the order or shape parameter passed to model constructors
      that support it; used as the `order` argument for `:bessel`, `:matern`,
      `:hyperspherical`, `:superspherical`, and as `H` for `:tplstable`; when it is not given the
      default of the constructor is used: `1.0` for `:bessel` (the same as [[bessel]]), `1.0` for `:matern`,
      `2.0` for `:hyperspherical`, `1.0` for `:superspherical` and `0.5` for `:tplstable`
    - `:bounds` (map): overrides for the default parameter search bounds; keys are a
      subset of `:nugget`, `:psill`, `:range`, `:beta`, each mapping to a `[lo hi]`
      vector; default bounds are:
        - `:nugget` - `[0.0, 5 * min-gamma]`, where `min-gamma` is the smallest non-zero gamma
        - `:psill` - `[0.0, 5 * max-gamma]`
        - `:range` - `[EPSILON, max-h]`, where `max-h` is the largest lag of the empirical semivariogram
        - `:beta` - the valid interval of the model: `[EPSILON, 2.0]` for `:power`, `:expower` and `:tplstable`,
          `[EPSILON, 30.0]` for `:tpower`, `:rational` and `:cauchy`; a model checks its parameters when it is built, so
          a `:beta` bound outside the valid interval makes the evaluation throw
      The default bounds bind often: the range is capped by the largest lag and the nugget by the smallest gamma,
      so when the true range is beyond the data the fit stops at the bound (the fitted range equals `max-h`). Wider
      bounds (for example `{:range [1e-10 (* 10 max-h)]}`) improve the fit of most models, in the research data the loss dropped
      by up to 195% for single bins and the median change was negligible, but they degrade `:linear`, whose loss is
      flat in the range direction (about 2.5 times the optimal loss), and extremely wide bounds degrade every model because
      the same number of scanned points covers a much larger box (increase `:N` then)
    - `:rng`: random number generator (see [[fastmath.random/rng]]) drawing the scanned starting points of the
      optimisation, passed to `fastmath.optimization/scan-and-minimize`. Seed it to reproduce the result: two fits with equal
      seeded generators in the same state give bitwise equal parameters. The generator is consumed by the fit. When it is not given a new
      random generator is used for every call and the fitted parameters vary from run to run (below `1e-6` for most models, more
      for `:hole`, `:bessel` and `:linear`, which have flat or multimodal losses)
    - `:N` (long): number of scanned starting points of the optimisation, passed to
      `fastmath.optimization/scan-and-minimize` (its default is `100`); increase it for wide bounds or many parameters

Returns a map containing:
- `:semivariogram` (function): the fitted semivariogram `(fn ^double [^double x])`
- `:semivariogram-creator` (function): the model constructor used to build the semivariogram
- `:params` (map): all model parameters, both fitted and fixed via `:defaults`
- `:weights` (sequence): final per-bin weights used to compute the loss
- `:loss` (double): the final weighted loss value after fitting

Throws `ex-info` (with `:type :invalid-input` and the key `:property`) for an empty empirical semivariogram, a non-finite `:h`, `:gamma` or `:n`
(a `NaN` in the observations reaches the fit this way), an empirical semivariogram with only zero gamma, an unknown model keyword, `:estimation` or
`:weights` keyword (the message lists the accepted values), explicit weights of a wrong length or unknown keys in `:defaults` and `:bounds`. A model which
rejects its parameters throws `ex-info` as well (see [[exponential]]). Throws `ex-info` with `:type :fit-failed` when all the optimisation runs fail.

See also [[fit]], [[empirical]], [[rbf->variogram]], [[variogram->covariance]].
raw docstring

gaussianclj

(gaussian {:keys [nugget psill range]})

Gaussian semivariogram model.

The formula is: nugget + psill * (1 - exp(-(x / range)^2))

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range parameter controlling the horizontal scale; must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also exponential, expower, spherical, cubic.

Gaussian semivariogram model.

The formula is: `nugget + psill * (1 - exp(-(x / range)^2))`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the maximum contribution of the structured
      spatial variance above the nugget; must be non-negative
    - `:range` (double): the range parameter controlling the horizontal scale; must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[exponential]], [[expower]], [[spherical]], [[cubic]].
raw docstring

highly-robust-estimatorclj

(highly-robust-estimator n diffs)

Genton's highly robust empirical semivariogram estimator.

The estimate of the variogram is (2.2191 * Q)^2, where Q is the quantile of the absolute differences |d_i - d_j| (i < j) of all pairs of the differences in the bin, at the level k / C(N, 2) with k = C(floor(N / 2) + 1, 2) and N the number of pairs. The quantile is the interpolated sample quantile of fastmath.stats/quantile, not the exact k-th order statistic of the original estimator, so the result differs slightly from it (relative differences of a few percent for small bins, e.g. 4.8e-2 in the research data).

Parameters:

  • n (long): number of pairs in the bin
  • diffs (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; empirical halves it). The estimator is not defined for a bin with a single pair (N equal 1: no pair of pairs) and returns NaN there; empirical drops such bins. The cost is quadratic in the size of a bin.

See also empirical, cressie-estimator, dowd-estimator, robust-m-estimator.

Genton's highly robust empirical semivariogram estimator.

The estimate of the variogram is `(2.2191 * Q)^2`, where `Q` is the quantile of the absolute differences `|d_i - d_j|` (`i < j`) of all pairs of the differences in the bin, at the level `k / C(N, 2)` with `k = C(floor(N / 2) + 1, 2)` and `N` the number of pairs. The quantile is the interpolated sample quantile of [[fastmath.stats/quantile]], not the exact k-th order statistic of the original estimator, so the result differs slightly from it (relative differences of a few percent for small bins, e.g. 4.8e-2 in the research data).

Parameters:

- `n` (long): number of pairs in the bin
- `diffs` (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; [[empirical]] halves it). The estimator is not defined for a bin with a single pair (`N` equal 1: no pair of pairs) and returns `NaN` there; [[empirical]] drops such bins. The cost is quadratic in the size of a bin.

See also [[empirical]], [[cressie-estimator]], [[dowd-estimator]], [[robust-m-estimator]].
raw docstring

holeclj

(hole {:keys [nugget psill range]})

Hole effect semivariogram model.

The formula is: nugget + psill * (1 - sinc(x / range))

where sinc(t) = sin(pi * t) / (pi * t) is the normalised sinc, with sinc(0) = 1. The model equals the gstat Wav model (the gstat Hol model uses the unnormalised sinc, so it corresponds to range / pi here). The semivariance oscillates around the sill and tends to nugget + psill for an infinite lag.

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the amplitude of the oscillation around the sill; must be non-negative
    • :range (double): the scale parameter controlling the period of oscillation (the semivariance reaches the sill for the first time at range); must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also exponential, cauchy, bessel.

Hole effect semivariogram model.

The formula is: `nugget + psill * (1 - sinc(x / range))`

where `sinc(t) = sin(pi * t) / (pi * t)` is the normalised sinc, with `sinc(0) = 1`. The model equals the gstat `Wav` model (the gstat `Hol` model uses the unnormalised sinc, so it corresponds to `range / pi` here). The semivariance oscillates around the sill and tends to `nugget + psill` for an infinite lag.

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the amplitude of the oscillation around the sill;
      must be non-negative
    - `:range` (double): the scale parameter controlling the period of oscillation (the
      semivariance reaches the sill for the first time at `range`); must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[exponential]], [[cauchy]], [[bessel]].
raw docstring

hypersphericalclj

(hyperspherical params)

Hyperspherical semivariogram model.

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive
    • :order (double, optional): the sphere dimension; must be a positive real number; defaults to 2.0; 2.0 is equivalent to circular, 3.0 to spherical

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also ->hyperspherical, superspherical, spherical, circular.

Hyperspherical semivariogram model.

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive
    - `:order` (double, optional): the sphere dimension; must be a positive real number;
      defaults to `2.0`; `2.0` is equivalent to [[circular]], `3.0` to [[spherical]]

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[->hyperspherical]], [[superspherical]], [[spherical]], [[circular]].
raw docstring

linearclj

(linear {:keys [nugget psill range]})

Linear semivariogram model.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (x / range)
  • x > range: nugget + psill

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also spherical, power, tpower, circular.

Linear semivariogram model.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (x / range)`
- `x > range`: `nugget + psill`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[spherical]], [[power]], [[tpower]], [[circular]].
raw docstring

maternclj

(matern params)

Matérn semivariogram model.

A convenience wrapper around ->matern that reads the smoothness order directly from the params map. When :order is not provided, defaults to 1.0.

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range parameter controlling the horizontal scale; must be positive
    • :order (double, optional): the smoothness order; must be positive; defaults to 1.0; 0.5 is equivalent to the exponential model; large values approach the gaussian model with the range range * sqrt(2), not with range

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also ->matern, bessel, gaussian, exponential.

Matérn semivariogram model.

A convenience wrapper around [[->matern]] that reads the smoothness order directly from
the `params` map. When `:order` is not provided, defaults to `1.0`.

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the maximum contribution of the structured
      spatial variance above the nugget; must be non-negative
    - `:range` (double): the range parameter controlling the horizontal scale; must be positive
    - `:order` (double, optional): the smoothness order; must be positive; defaults to `1.0`;
      `0.5` is equivalent to the [[exponential]] model; large values approach the [[gaussian]] model
      with the range `range * sqrt(2)`, not with `range`

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[->matern]], [[bessel]], [[gaussian]], [[exponential]].
raw docstring

matheron-estimatorclj

(matheron-estimator _ diffs)

Matheron (classical) empirical semivariogram estimator.

Parameters:

  • n (long): number of pairs in the bin (not used)
  • diffs (sequence of doubles): differences of the values of the pairs in the bin

Returns the mean of the squared differences, the estimate of the variogram (twice the semivariance; empirical halves it). NaN for an empty diffs.

See also empirical, cressie-estimator, dowd-estimator.

Matheron (classical) empirical semivariogram estimator.

Parameters:

- `n` (long): number of pairs in the bin (not used)
- `diffs` (sequence of doubles): differences of the values of the pairs in the bin

Returns the mean of the squared differences, the estimate of the variogram (twice the semivariance; [[empirical]] halves it). `NaN` for an empty `diffs`.

See also [[empirical]], [[cressie-estimator]], [[dowd-estimator]].
raw docstring

maybe-remove-outliersclj

(maybe-remove-outliers combined ys remove-outliers?)

Optionally removes outliers from the points before the pairs are formed in empirical.

The outliers are detected in the observed values of the points, not in the differences of the values of the pairs.

Parameters:

  • combined (sequence of [id x y] triples): the points
  • ys (sequence of doubles): the values y of the triples
  • remove-outliers?: :mad for remove-outliers-mad, any other truthy value for remove-outliers-fence, false or nil to keep all the points

Returns the sequence of the kept triples.

See also empirical, remove-outliers-fence, remove-outliers-mad.

Optionally removes outliers from the points before the pairs are formed in [[empirical]].

The outliers are detected in the observed values of the points, not in the differences of the values of the pairs.

Parameters:

- `combined` (sequence of `[id x y]` triples): the points
- `ys` (sequence of doubles): the values `y` of the triples
- `remove-outliers?`: `:mad` for [[remove-outliers-mad]], any other truthy value for [[remove-outliers-fence]], `false` or `nil` to keep all the points

Returns the sequence of the kept triples.

See also [[empirical]], [[remove-outliers-fence]], [[remove-outliers-mad]].
raw docstring

pentasphericalclj

(pentaspherical {:keys [nugget psill range]})

Pentaspherical semivariogram model.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (1.875*(x/range) - 1.25*(x/range)^3 + 0.375*(x/range)^5)
  • x > range: nugget + psill

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also spherical, cubic, circular, linear.

Pentaspherical semivariogram model.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (1.875*(x/range) - 1.25*(x/range)^3 + 0.375*(x/range)^5)`
- `x > range`: `nugget + psill`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[spherical]], [[cubic]], [[circular]], [[linear]].
raw docstring

powerclj

(power {:keys [nugget psill range beta]})

Power semivariogram model.

The formula is: nugget + psill * (x / range)^beta

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the scaling coefficient for the power term; must be non-negative
    • :range (double): the range parameter controlling the horizontal scale of the power curve; must be positive
    • :beta (double): the power exponent controlling the rate of growth; must be in (0.0, 2.0], the only interval where the model is conditionally negative definite (a valid semivariogram); 2.0 is the parabola, 1.0 the linear model without a sill

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero. The model has no sill: it grows without bound (Infinity for an infinite lag).

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range (including :beta outside (0.0, 2.0]), throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also exponential, gaussian, spherical, expower, tpower.

Power semivariogram model.

The formula is: `nugget + psill * (x / range)^beta`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the scaling coefficient for the power term;
      must be non-negative
    - `:range` (double): the range parameter controlling the horizontal scale of the
      power curve; must be positive
    - `:beta` (double): the power exponent controlling the rate of growth; must be in
      `(0.0, 2.0]`, the only interval where the model is conditionally negative definite (a valid
      semivariogram); `2.0` is the parabola, `1.0` the linear model without a sill

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero. The model has no sill: it grows without bound (`Infinity` for an infinite lag).

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range (including `:beta` outside `(0.0, 2.0]`), throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[exponential]], [[gaussian]], [[spherical]], [[expower]], [[tpower]].
raw docstring

rationalclj

(rational {:keys [nugget psill range beta]})

Rational quadratic semivariogram model.

The formula is: nugget + psill * (1 - (1 + (x / range)^2 / beta)^(-beta))

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range parameter controlling the horizontal scale; must be positive
    • :beta (double): the shape exponent controlling curvature and convergence rate; must be positive; values below EPSILON are treated as EPSILON

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also cauchy, gaussian, expower, power.

Rational quadratic semivariogram model.

The formula is: `nugget + psill * (1 - (1 + (x / range)^2 / beta)^(-beta))`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the maximum contribution of the structured
      spatial variance above the nugget; must be non-negative
    - `:range` (double): the range parameter controlling the horizontal scale; must be positive
    - `:beta` (double): the shape exponent controlling curvature and convergence rate;
      must be positive; values below `EPSILON` are treated as `EPSILON`

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[cauchy]], [[gaussian]], [[expower]], [[power]].
raw docstring

rbf->variogramclj

(rbf->variogram kernel)

Builds a semivariogram model constructor from a Radial Basis Function (RBF) kernel.

Converts any RBF kernel from fastmath.kernel.rbf into a semivariogram model by treating the kernel as the correlation function: semivariance equals nugget + psill * (1 - kernel(x / range)). For this transformation to produce a valid semivariogram, the kernel must satisfy two conditions: it must equal 1.0 at the origin and decay to 0.0 at infinity. The kernel is evaluated at x / range, so the range of the model multiplies the scale of the RBF kernel: the kernel with :scale 2 and the range 3 gives the same model as the kernel with :scale 1 and the range 6 (for the gaussian kernel it is gaussian with the range 6).

The formula is: nugget + psill * (1 - kernel(x / range))

Suitable kernels from fastmath.kernel.rbf (value 1.0 at zero, decaying to 0.0):

  • :gaussian - smooth Gaussian decay
  • :matern - Matérn family; differentiability controlled by order
  • :truncated-power - compactly supported power kernel
  • :wendland - compactly supported, C^(2k) smooth
  • :gneiting - compactly supported Gneiting family
  • :wu - compactly supported Wu family
  • :whittaker - Whittaker family, normalised to 1.0 at zero
  • :poisson - Bessel J family; oscillates around 0.0, use with care; the kernel has to be normalised to 1.0 at zero (for dimensions above 2 it is only after the normalisation of the kernel in fastmath.kernel.rbf)

Unsuitable kernels (do not satisfy the required conditions):

  • :thin-plate / :thin-plate-splines - grows without bound
  • :linear - zero at origin, grows without bound
  • :radial-powers - zero or infinite at origin depending on exponent
  • :generalized-multiquadratic - not normalised to +1.0 at zero
  • :shifted-surface-splines - grows with distance for positive exponent

Parameters:

  • kernel (function): an RBF kernel function (fn ^double [^double x]) returning 1.0 at x = 0 and decaying to 0.0 as x increases; typically constructed via fastmath.kernel.rbf functions. The value of the kernel at zero is not used (the semivariance at lag zero is 0.0), so a kernel which is not 1.0 at zero gives a model which is not continuous as the lag goes to zero from nugget.

Returns a semivariogram model constructor (fn [params]) that accepts a map with:

  • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
  • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
  • :range (double): the horizontal scale, multiplies the RBF scale; must be positive

The constructor itself returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also exponential, gaussian, matern, fit-params.

Builds a semivariogram model constructor from a Radial Basis Function (RBF) kernel.

Converts any RBF kernel from `fastmath.kernel.rbf` into a semivariogram model by
treating the kernel as the correlation function: semivariance equals
`nugget + psill * (1 - kernel(x / range))`. For this transformation to produce a valid
semivariogram, the kernel must satisfy two conditions: it must equal `1.0` at the origin
and decay to `0.0` at infinity. The kernel is evaluated at `x / range`, so the `range` of the model
multiplies the `scale` of the RBF kernel: the kernel with `:scale` 2 and the `range` 3 gives the same
model as the kernel with `:scale` 1 and the `range` 6 (for the gaussian kernel it is [[gaussian]] with
the range 6).

The formula is: `nugget + psill * (1 - kernel(x / range))`

Suitable kernels from `fastmath.kernel.rbf` (value `1.0` at zero, decaying to `0.0`):

- `:gaussian` - smooth Gaussian decay
- `:matern` - Matérn family; differentiability controlled by order
- `:truncated-power` - compactly supported power kernel
- `:wendland` - compactly supported, C^(2k) smooth
- `:gneiting` - compactly supported Gneiting family
- `:wu` - compactly supported Wu family
- `:whittaker` - Whittaker family, normalised to `1.0` at zero
- `:poisson` - Bessel J family; oscillates around `0.0`, use with care; the kernel has to be normalised to `1.0` at zero (for dimensions above 2 it is only after the normalisation of the kernel in `fastmath.kernel.rbf`)

Unsuitable kernels (do not satisfy the required conditions):

- `:thin-plate` / `:thin-plate-splines` - grows without bound
- `:linear` - zero at origin, grows without bound
- `:radial-powers` - zero or infinite at origin depending on exponent
- `:generalized-multiquadratic` - not normalised to `+1.0` at zero
- `:shifted-surface-splines` - grows with distance for positive exponent

Parameters:

- `kernel` (function): an RBF kernel function `(fn ^double [^double x])` returning `1.0`
  at `x = 0` and decaying to `0.0` as `x` increases; typically constructed via
  `fastmath.kernel.rbf` functions. The value of the kernel at zero is not used (the semivariance
  at lag zero is `0.0`), so a kernel which is not `1.0` at zero gives a model which is not continuous
  as the lag goes to zero from `nugget`.

Returns a semivariogram model constructor `(fn [params])` that accepts a map with:
- `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
  variation or measurement error; must be non-negative
- `:psill` (double): the partial sill; the maximum contribution of the structured
  spatial variance above the nugget; must be non-negative
- `:range` (double): the horizontal scale, multiplies the RBF `scale`; must be positive

The constructor itself returns a function `(fn ^double [^double x])` that computes the
semivariance for a given lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[exponential]], [[gaussian]], [[matern]], [[fit-params]].
raw docstring

remove-outliers-fenceclj

(remove-outliers-fence combined ys)

Removes outliers using Tukey's fences (k=1.5).

Parameters:

  • combined (sequence of [id x y] triples): the points, as built by empirical
  • ys (sequence of doubles): the values y of the triples

Returns the triples with the value between Q1 - 1.5 * IQR and Q3 + 1.5 * IQR of ys (inclusive).

See also maybe-remove-outliers, remove-outliers-mad.

Removes outliers using Tukey's fences (`k`=1.5).

Parameters:

- `combined` (sequence of `[id x y]` triples): the points, as built by [[empirical]]
- `ys` (sequence of doubles): the values `y` of the triples

Returns the triples with the value between `Q1 - 1.5 * IQR` and `Q3 + 1.5 * IQR` of `ys` (inclusive).

See also [[maybe-remove-outliers]], [[remove-outliers-mad]].
raw docstring

remove-outliers-madclj

(remove-outliers-mad combined ys)

Removes outliers using median absolute deviation.

Parameters:

  • combined (sequence of [id x y] triples): the points, as built by empirical
  • ys (sequence of doubles): the values y of the triples

Returns the triples for which the modified z-score |y - median| / (MAD / 0.6745) is at most 3.0. When the median absolute deviation is 0.0 all values different from the median are removed.

See also maybe-remove-outliers, remove-outliers-fence.

Removes outliers using median absolute deviation.

Parameters:

- `combined` (sequence of `[id x y]` triples): the points, as built by [[empirical]]
- `ys` (sequence of doubles): the values `y` of the triples

Returns the triples for which the modified z-score `|y - median| / (MAD / 0.6745)` is at most `3.0`. When the median absolute deviation is `0.0` all values different from the median are removed.

See also [[maybe-remove-outliers]], [[remove-outliers-fence]].
raw docstring

robust-m-estimatorclj

(robust-m-estimator n diffs)

Robust M-estimator (Gunst and Hartfield) for empirical semivariogram.

A biweight (Tukey) M-estimate of location of the square roots of the absolute differences, raised to the fourth power and divided by the Hawkins and Cressie constant 0.457 + 0.494 / N + 0.045 / N^2 (see cressie-estimator).

Parameters:

  • n (long): number of pairs in the bin
  • diffs (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; empirical halves it). The scale of the estimator is the median absolute deviation, which is 0.0 (the result is NaN) for a bin with a single pair or with identical absolute differences; empirical drops such bins. The implementation is checked only against an independent re-implementation, not against a reference package.

See also empirical, cressie-estimator, highly-robust-estimator.

Robust M-estimator (Gunst and Hartfield) for empirical semivariogram.

A biweight (Tukey) M-estimate of location of the square roots of the absolute differences, raised to the fourth power and divided by the Hawkins and Cressie constant `0.457 + 0.494 / N + 0.045 / N^2` (see [[cressie-estimator]]).

Parameters:

- `n` (long): number of pairs in the bin
- `diffs` (sequence of doubles): differences of the values of the pairs in the bin

Returns the estimate of the variogram (twice the semivariance; [[empirical]] halves it). The scale of the estimator is the median absolute deviation, which is `0.0` (the result is `NaN`) for a bin with a single pair or with identical absolute differences; [[empirical]] drops such bins. The implementation is checked only against an independent re-implementation, not against a reference package.

See also [[empirical]], [[cressie-estimator]], [[highly-robust-estimator]].
raw docstring

sphericalclj

(spherical {:keys [nugget psill range]})

Spherical semivariogram model.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (1.5 * (x / range) - 0.5 * (x / range)^3)
  • x > range: nugget + psill

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also linear, cubic, pentaspherical, circular, gaussian.

Spherical semivariogram model.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (1.5 * (x / range) - 0.5 * (x / range)^3)`
- `x > range`: `nugget + psill`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[linear]], [[cubic]], [[pentaspherical]], [[circular]], [[gaussian]].
raw docstring

supersphericalclj

(superspherical params)

Superspherical semivariogram model.

A convenience wrapper around ->superspherical that reads the shape order directly from the params map. When :order is not provided, defaults to 1.0, which is equivalent to the standard spherical model. Setting :order to 0.0 recovers linear and 0.5 recovers circular.

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive
    • :order (double, optional): the shape order; must be non-negative; defaults to 1.0; 0.0 is equivalent to linear, 0.5 to circular, 1.0 to spherical

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also ->superspherical, hyperspherical, spherical, circular, linear.

Superspherical semivariogram model.

A convenience wrapper around [[->superspherical]] that reads the shape order directly
from the `params` map. When `:order` is not provided, defaults to `1.0`, which is
equivalent to the standard [[spherical]] model. Setting `:order` to `0.0` recovers
[[linear]] and `0.5` recovers [[circular]].

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive
    - `:order` (double, optional): the shape order; must be non-negative; defaults to `1.0`;
      `0.0` is equivalent to [[linear]], `0.5` to [[circular]], `1.0` to [[spherical]]

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[->superspherical]], [[hyperspherical]], [[spherical]], [[circular]], [[linear]].
raw docstring

tplstableclj

(tplstable params)

Truncated-Power-Law (TPL) Stable semivariogram model.

A convenience wrapper around ->tplstable that reads the Hurst exponent directly from the params map via the :H key. When :H is not provided, defaults to 0.5.

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the maximum contribution of the structured spatial variance above the nugget; must be non-negative
    • :range (double): the scale parameter controlling the horizontal extent; must be positive
    • :beta (double): the power exponent controlling the short-range growth rate; must be in (0.0, 2.0] for a valid conditionally negative-definite model
    • :H (double, optional): the Hurst exponent controlling long-range dependence; must be in (0.0, 1.0); defaults to 0.5

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also ->tplstable, power, expower, matern.

Truncated-Power-Law (TPL) Stable semivariogram model.

A convenience wrapper around [[->tplstable]] that reads the Hurst exponent directly
from the `params` map via the `:H` key. When `:H` is not provided, defaults to `0.5`.

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the maximum contribution of the structured
      spatial variance above the nugget; must be non-negative
    - `:range` (double): the scale parameter controlling the horizontal extent; must be positive
    - `:beta` (double): the power exponent controlling the short-range growth rate;
      must be in `(0.0, 2.0]` for a valid conditionally negative-definite model
    - `:H` (double, optional): the Hurst exponent controlling long-range dependence;
      must be in `(0.0, 1.0)`; defaults to `0.5`

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[->tplstable]], [[power]], [[expower]], [[matern]].
raw docstring

tpowerclj

(tpower {:keys [nugget psill range beta]})

Truncated power semivariogram model.

The formula is:

  • x = 0: 0.0
  • x <= range: nugget + psill * (1 - (1 - x / range)^beta)
  • x > range: nugget + psill

Parameters:

  • params (map): a map of model parameters with the following keys:
    • :nugget (double): the nugget effect; the y-intercept representing micro-scale variation or measurement error; must be non-negative
    • :psill (double): the partial sill; the structured spatial variance above the nugget; must be non-negative
    • :range (double): the range at which the sill is reached exactly; must be positive
    • :beta (double): the power exponent controlling the shape of the rise within the range; must be positive; 1.0 gives a linear rise

Returns a function (fn ^double [^double x]) that computes the semivariance for a given lag distance x. Returns 0.0 when x is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws ex-info with :type :invalid-input and the keys :model, :property, :value and :expected in the data. The lag x is expected to be non-negative; NaN gives NaN.

See also power, linear, spherical, expower.

Truncated power semivariogram model.

The formula is:
- `x = 0`: `0.0`
- `x <= range`: `nugget + psill * (1 - (1 - x / range)^beta)`
- `x > range`: `nugget + psill`

Parameters:

- `params` (map): a map of model parameters with the following keys:
    - `:nugget` (double): the nugget effect; the y-intercept representing micro-scale
      variation or measurement error; must be non-negative
    - `:psill` (double): the partial sill; the structured spatial variance above the nugget;
      must be non-negative
    - `:range` (double): the range at which the sill is reached exactly; must be positive
    - `:beta` (double): the power exponent controlling the shape of the rise within the
      range; must be positive; `1.0` gives a linear rise

Returns a function `(fn ^double [^double x])` that computes the semivariance for a given
lag distance `x`. Returns `0.0` when `x` is zero.

The parameters are checked once, when the model is built (not at every evaluation): a missing, non-numeric or non-finite parameter, or a value outside the stated range, throws `ex-info` with `:type :invalid-input` and the keys `:model`, `:property`, `:value` and `:expected` in the data. The lag `x` is expected to be non-negative; `NaN` gives `NaN`.

See also [[power]], [[linear]], [[spherical]], [[expower]].
raw docstring

variogram->covarianceclj

(variogram->covariance semivariogram sill)

Converts a semivariogram function to the covariance function with the given total sill.

The covariance is C(x) = sill - gamma(x), the relation of a second order stationary process. The total sill is the variance of the process, nugget + psill of the models of this namespace: then C(0) equals the variance, C(x) tends to psill (the nugget is lost) for a tiny positive lag and C(x) = 0 beyond the range of the bounded models.

Parameters:

  • semivariogram (function): a semivariogram (fn ^double [^double x]), for example a model of this namespace built from a parameter map or the result of fit; it should return 0.0 at lag zero, which all the models do
  • sill (double): the total sill (the variance), it must be finite and non-negative; use (+ nugget psill) of the parameters of the model, or from the result of fit-params (let [{:keys [nugget psill]} (:params result)] (+ nugget psill))

Returns a function (fn ^double [^double x]) computing sill - gamma(x); NaN gives NaN.

Corner cases: for the models without a sill (see power) the covariance is negative from some lag and is not a covariance of a stationary process; an unbounded semivariogram makes only sense as the generalised covariance. Throws ex-info with :type :invalid-input and the key :property equal :sill for a sill which is not a finite non-negative number, and with the property :semivariogram when the first argument is not a function.

See also fit-params, exponential, spherical, gaussian.

Converts a semivariogram function to the covariance function with the given total sill.

The covariance is `C(x) = sill - gamma(x)`, the relation of a second order stationary process. The total sill is the variance of the process, `nugget + psill` of the models of this namespace: then `C(0)` equals the variance, `C(x)` tends to `psill` (the nugget is lost) for a tiny positive lag and `C(x) = 0` beyond the `range` of the bounded models.

Parameters:

- `semivariogram` (function): a semivariogram `(fn ^double [^double x])`, for example a model of this namespace built from a parameter map or the result of [[fit]]; it should return `0.0` at lag zero, which all the models do
- `sill` (double): the total sill (the variance), it must be finite and non-negative; use `(+ nugget psill)` of the parameters of the model, or from the result of [[fit-params]] `(let [{:keys [nugget psill]} (:params result)] (+ nugget psill))`

Returns a function `(fn ^double [^double x])` computing `sill - gamma(x)`; `NaN` gives `NaN`.

Corner cases: for the models without a sill (see [[power]]) the covariance is negative from some lag and is not a covariance of a stationary process; an unbounded semivariogram makes only sense as the generalised covariance. Throws `ex-info` with `:type :invalid-input` and the key `:property` equal `:sill` for a `sill` which is not a finite non-negative number, and with the property `:semivariogram` when the first argument is not a function.

See also [[fit-params]], [[exponential]], [[spherical]], [[gaussian]].
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close