Shepard (inverse distance weighting) interpolation of scattered data.
Shepard (inverse distance weighting) interpolation of scattered data.
(shepard xss ys)(shepard xss ys opts)Creates the inverse distance weighting (Shepard) interpolator of scattered data.
The value at a query point x is the weighted mean of the values ys, with the weights 1 / d(x, xs_i)^p, where d is the distance to the i-th node. The interpolator passes exactly through the nodes. The result is always a weighted mean of ys, so it never leaves the range of the values and does not extrapolate trends: far from the data it tends to the mean of all the values. For p > 1 it is flat (zero gradient) at the nodes.
Parameters:
xss (sequence): the nodes, at least one; numbers for one dimensional data or sequences of numbers (vectors, Vec2, ...) of an equal lengthys (sequence of numbers): the values at the nodes, as many as nodesopts (map, optional; a nil value is the same as a missing key):
:p (double, default: 2.0): the power of the distance in the weights, finite and not negative; a larger p makes the result closer to the value of the nearest node, p = 0 gives the mean of all the values (except at the nodes):distance (function, default: Euclidean distance, fastmath.distance/euclidean-1d for numbers, fastmath.distance/euclidean for sequences): a binary function (fn [x1 x2]) returning the distance as a doubleReturns a function of a query point (a number for one dimensional data, also a one element sequence; a sequence of numbers otherwise) returning a double.
A query point is a node when its distance to the node is exactly 0.0 (not when the keys are equal): a long 1 hits a node 1.0, a vector [1 0] hits [1.0 0.0], and a Vec2 hits a vector. Then the value of the node is returned. When nodes are repeated, the value of the last repeated node wins. The weights are scaled by the smallest distance, so very small distances (1e-154 and less) cannot overflow: the result is a weighted mean of the values for any p, never Inf or NaN (unless a value is NaN, the query point is NaN, or all the distances overflow to infinity). The default Euclidean distance is computed without overflow or underflow of the squares (coordinates differing by 1e-300 or 1e200 are fine); a custom :distance is called as is.
Throws ex-info (with :type :invalid-input, :method :shepard and the key :property) when xss and ys have different lengths (:length-mismatch), there are no nodes (:too-few-points) :p is negative, infinite or NaN (:p), or, with the default distance, the nodes or the query point have different dimensions (:dimension-mismatch).
See also fastmath.interpolation/shepard, fastmath.interpolation.rbf/rbf, fastmath.interpolation.kriging/kriging.
Creates the inverse distance weighting (Shepard) interpolator of scattered data.
The value at a query point `x` is the weighted mean of the values `ys`, with the weights `1 / d(x, xs_i)^p`, where `d` is the distance to the `i`-th node. The interpolator passes exactly through the nodes. The result is always a weighted mean of `ys`, so it never leaves the range of the values and does not extrapolate trends: far from the data it tends to the mean of all the values. For `p > 1` it is flat (zero gradient) at the nodes.
Parameters:
- `xss` (sequence): the nodes, at least one; numbers for one dimensional data or sequences of numbers (vectors, `Vec2`, ...) of an equal length
- `ys` (sequence of numbers): the values at the nodes, as many as nodes
- `opts` (map, optional; a `nil` value is the same as a missing key):
- `:p` (double, default: `2.0`): the power of the distance in the weights, finite and not negative; a larger `p` makes the result closer to the value of the nearest node, `p = 0` gives the mean of all the values (except at the nodes)
- `:distance` (function, default: Euclidean distance, `fastmath.distance/euclidean-1d` for numbers, `fastmath.distance/euclidean` for sequences): a binary function `(fn [x1 x2])` returning the distance as a double
Returns a function of a query point (a number for one dimensional data, also a one element sequence; a sequence of numbers otherwise) returning a double.
A query point is a node when its distance to the node is exactly `0.0` (not when the keys are equal): a long `1` hits a node `1.0`, a vector `[1 0]` hits `[1.0 0.0]`, and a `Vec2` hits a vector. Then the value of the node is returned. When nodes are repeated, the value of the last repeated node wins. The weights are scaled by the smallest distance, so very small distances (`1e-154` and less) cannot overflow: the result is a weighted mean of the values for any `p`, never `Inf` or `NaN` (unless a value is `NaN`, the query point is `NaN`, or all the distances overflow to infinity). The default Euclidean distance is computed without overflow or underflow of the squares (coordinates differing by `1e-300` or `1e200` are fine); a custom `:distance` is called as is.
Throws `ex-info` (with `:type :invalid-input`, `:method :shepard` and the key `:property`) when `xss` and `ys` have different lengths (`:length-mismatch`), there are no nodes (`:too-few-points`) `:p` is negative, infinite or `NaN` (`:p`), or, with the default distance, the nodes or the query point have different dimensions (`:dimension-mismatch`).
See also [[fastmath.interpolation/shepard]], [[fastmath.interpolation.rbf/rbf]], [[fastmath.interpolation.kriging/kriging]].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 |