Kriging interpolation of scattered data.
Kriging interpolation of scattered data.
(kriging xss ys)(kriging xss ys variogram)(kriging xss ys variogram opts)Creates the kriging interpolator of scattered data, ordinary or universal.
The interpolant is f(x) = sum_i w_i gamma(d(x, xs_i)) + sum_j c_j p_j(x), where gamma is the semivariogram and the weights w and the coefficients c solve the kriging system built on the nodes. The default polynomial is a constant (ordinary kriging).
Parameters:
xss (sequence): the nodes, at least one (at least two when the variogram is estimated); numbers for one dimensional data or sequences of numbersys (sequence of numbers): the values at the nodes, as many as nodesvariogram (function, optional): the semivariogram gamma(h), for example a model from fastmath.kernel.variogram ((vgram/spherical {:nugget 0.0 :psill 1.0 :range 3.0})). It has to be a valid semivariogram: gamma(0) = 0 (a nugget is the limit at 0+, not the value at 0) and conditionally negative definite. When it is nil (the default), the empirical variogram of the data is estimated and a gaussian model is fitted to it by random search, see the options :rng and :Nopts (map, optional; a nil value is the same as a missing key, except for :polynomial-terms):
:error (double or sequence of doubles, default: 0.0): the standard deviation of the measurement error of the values, the same for all the nodes or one per node. The variance error^2 is subtracted from the diagonal of the variogram matrix, so the interpolator smooths the data instead of passing through the nodes. It is the Err component of the gstat variogram (its value is the variance there, so Err = error^2). An empty sequence means no error:distance (function, default: Euclidean distance, fastmath.distance/euclidean-1d for numbers and fastmath.distance/euclidean for sequences): a binary distance function (fn [x1 x2]); it is used for the kriging system and also for the estimation of the empirical variogram of the default variogram:polynomial-terms (function, default: a constant, (constantly [1.0])): a function of a point returning the sequence of the values of the drift basis, for example (fn [[x y]] [1.0 x y]) for the linear drift of universal kriging; nil or false removes the drift terms and the unbiasedness constraint, the system is then the plain variogram matrix equation, which is rarely wanted:rng (random number generator, default: a new unseeded generator for every call): the generator which draws the starting points of the variogram fit; it is used only when variogram is nil. Pass a seeded generator (see fastmath.random/rng) to get the same interpolator on every construction; the generator is consumed:N (long, default: 100): the number of the starting points scanned by the fit of the default variogram, increase it for a hard fit; used only when variogram is nilReturns a function of a query point (a number for one dimensional data, a sequence of numbers otherwise) returning a double. It does not return the kriging variance.
Repeated nodes make the system singular: the minimum norm solution of the SVD is used silently, and the value at a repeated node is the mean of the values there (gstat gives NA). The default variogram is the best gaussian model for the binned estimate and is only a starting point: a visual check of the variogram or an explicit model fitted with fastmath.kernel.variogram/fit is recommended.
Throws ex-info (with :type :invalid-input, :method :kriging and the key :property) when xss and ys have different lengths (:length-mismatch), there are too few nodes (:too-few-points) or :error is not a finite number or a sequence of finite numbers with one entry per node (:error). The estimation of the default variogram can throw its own ex-info, for example when all the nodes are at one location.
See also fastmath.interpolation/kriging, fastmath.kernel.variogram/fit, fastmath.kernel.variogram/empirical, fastmath.interpolation.rbf/rbf, fastmath.interpolation.gp/gp.
Creates the kriging interpolator of scattered data, ordinary or universal.
The interpolant is `f(x) = sum_i w_i gamma(d(x, xs_i)) + sum_j c_j p_j(x)`, where `gamma` is the semivariogram and the weights `w` and the coefficients `c` solve the kriging system built on the nodes. The default polynomial is a constant (ordinary kriging).
Parameters:
- `xss` (sequence): the nodes, at least one (at least two when the variogram is estimated); numbers for one dimensional data or sequences of numbers
- `ys` (sequence of numbers): the values at the nodes, as many as nodes
- `variogram` (function, optional): the semivariogram `gamma(h)`, for example a model from `fastmath.kernel.variogram` (`(vgram/spherical {:nugget 0.0 :psill 1.0 :range 3.0})`). It has to be a valid semivariogram: `gamma(0) = 0` (a nugget is the limit at `0+`, not the value at `0`) and conditionally negative definite. When it is `nil` (the default), the empirical variogram of the data is estimated and a gaussian model is fitted to it by random search, see the options `:rng` and `:N`
- `opts` (map, optional; a `nil` value is the same as a missing key, except for `:polynomial-terms`):
- `:error` (double or sequence of doubles, default: `0.0`): the standard deviation of the measurement error of the values, the same for all the nodes or one per node. The variance `error^2` is subtracted from the diagonal of the variogram matrix, so the interpolator smooths the data instead of passing through the nodes. It is the `Err` component of the gstat variogram (its value is the variance there, so `Err = error^2`). An empty sequence means no error
- `:distance` (function, default: Euclidean distance, `fastmath.distance/euclidean-1d` for numbers and `fastmath.distance/euclidean` for sequences): a binary distance function `(fn [x1 x2])`; it is used for the kriging system and also for the estimation of the empirical variogram of the default variogram
- `:polynomial-terms` (function, default: a constant, `(constantly [1.0])`): a function of a point returning the sequence of the values of the drift basis, for example `(fn [[x y]] [1.0 x y])` for the linear drift of universal kriging; `nil` or `false` removes the drift terms and the unbiasedness constraint, the system is then the plain variogram matrix equation, which is rarely wanted
- `:rng` (random number generator, default: a new unseeded generator for every call): the generator which draws the starting points of the variogram fit; it is used only when `variogram` is `nil`. Pass a seeded generator (see [[fastmath.random/rng]]) to get the same interpolator on every construction; the generator is consumed
- `:N` (long, default: `100`): the number of the starting points scanned by the fit of the default variogram, increase it for a hard fit; used only when `variogram` is `nil`
Returns a function of a query point (a number for one dimensional data, a sequence of numbers otherwise) returning a double. It does not return the kriging variance.
Repeated nodes make the system singular: the minimum norm solution of the SVD is used silently, and the value at a repeated node is the mean of the values there (gstat gives `NA`). The default variogram is the best gaussian model for the binned estimate and is only a starting point: a visual check of the variogram or an explicit model fitted with `fastmath.kernel.variogram/fit` is recommended.
Throws `ex-info` (with `:type :invalid-input`, `:method :kriging` and the key `:property`) when `xss` and `ys` have different lengths (`:length-mismatch`), there are too few nodes (`:too-few-points`) or `:error` is not a finite number or a sequence of finite numbers with one entry per node (`:error`). The estimation of the default variogram can throw its own `ex-info`, for example when all the nodes are at one location.
See also [[fastmath.interpolation/kriging]], [[fastmath.kernel.variogram/fit]], [[fastmath.kernel.variogram/empirical]], [[fastmath.interpolation.rbf/rbf]], [[fastmath.interpolation.gp/gp]].cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |