Liking cljdoc? Tell your friends :D
Clojure only.

fastmath.interpolation.monotone


monotoneclj

(monotone xs ys)

Creates a 1D monotone piecewise cubic Hermite interpolator (Fritsch-Carlson).

The interpolant passes through all data points and preserves the monotonicity of the data: on every interval it stays between the two neighbouring values, so it never overshoots and has a local extremum only at a data point. This avoids the oscillations of a natural cubic spline.

The tangent at an interior node is the arithmetic mean of the two neighbouring secants, or zero when the secants have different signs or one of them is zero. The end tangents are the secants of the first and the last interval. Then every interval (including the last one) is limited: the ratios of the two tangents to the secant of the interval are scaled back into the circle of radius 3, which is sufficient for monotonicity (Fritsch and Carlson, 1980). The interpolant is C1.

Parameters:

  • xs (sequence of numbers): nodes, finite and strictly increasing; at least 2 points.
  • ys (sequence of numbers): values, the same length as xs.

Returns a function f such that (f x) returns the interpolated double value at x. f returns the data value exactly at a node. Outside the domain the cubic of the first or the last interval is continued (extrapolation, not limited). A NaN in ys produces NaN around it.

Throws ex-info (with :type :invalid-input, :method :monotone and a :property) when the lengths differ, there are fewer than 2 points, xs contains NaN or an infinity, or xs is not strictly increasing (unsorted or duplicated).

See also pchip (harmonic mean tangents), fastmath.interpolation.cubic/cubic, fastmath.interpolation.linear/linear.

Creates a 1D monotone piecewise cubic Hermite interpolator (Fritsch-Carlson).

The interpolant passes through all data points and preserves the monotonicity of the data: on every interval it stays between the two neighbouring values, so it never overshoots and has a local extremum only at a data point. This avoids the oscillations of a natural cubic spline.

The tangent at an interior node is the arithmetic mean of the two neighbouring secants, or zero when the secants have different signs or one of them is zero. The end tangents are the secants of the first and the last interval. Then every interval (including the last one) is limited: the ratios of the two tangents to the secant of the interval are scaled back into the circle of radius 3, which is sufficient for monotonicity (Fritsch and Carlson, 1980). The interpolant is C1.

Parameters:

- `xs` (sequence of numbers): nodes, finite and strictly increasing; at least 2 points.
- `ys` (sequence of numbers): values, the same length as `xs`.

Returns a function `f` such that `(f x)` returns the interpolated `double` value at `x`. `f` returns the data value exactly at a node. Outside the domain the cubic of the first or the last interval is continued (extrapolation, not limited). A `NaN` in `ys` produces `NaN` around it.

Throws `ex-info` (with `:type :invalid-input`, `:method :monotone` and a `:property`) when the lengths differ, there are fewer than 2 points, `xs` contains `NaN` or an infinity, or `xs` is not strictly increasing (unsorted or duplicated).

See also [[pchip]] (harmonic mean tangents), [[fastmath.interpolation.cubic/cubic]], [[fastmath.interpolation.linear/linear]].
raw docstring

pchipclj

(pchip xs ys)

Creates a 1D shape-preserving piecewise cubic Hermite interpolator (PCHIP, Fritsch-Butland).

The interpolant passes through all data points, is C1 and does not overshoot: on every interval it stays between the two neighbouring values. It equals scipy.interpolate.PchipInterpolator.

The tangent at an interior node is the weighted harmonic mean of the two neighbouring secants (weights depend on the widths of the intervals, so a nonuniform grid is handled), or zero when the secants have different signs or one of them is zero. The end tangents use the non-centered three point formula, set to zero when its sign differs from the end secant and limited to three times the end secant when the secants of the end intervals have different signs. With two points the interpolant is the straight line.

Parameters:

  • xs (sequence of numbers): nodes, finite and strictly increasing; at least 2 points.
  • ys (sequence of numbers): values, the same length as xs.

Returns a function f such that (f x) returns the interpolated double value at x. f returns the data value exactly at a node. Outside the domain the cubic of the first or the last interval is continued (extrapolation, not limited).

Throws ex-info (with :type :invalid-input, :method :pchip and a :property) when the lengths differ, there are fewer than 2 points, xs contains NaN or an infinity, or xs is not strictly increasing.

See also monotone (arithmetic mean tangents, Fritsch-Carlson), fastmath.interpolation.cubic/cubic.

Creates a 1D shape-preserving piecewise cubic Hermite interpolator (PCHIP, Fritsch-Butland).

The interpolant passes through all data points, is C1 and does not overshoot: on every interval it stays between the two neighbouring values. It equals `scipy.interpolate.PchipInterpolator`.

The tangent at an interior node is the weighted harmonic mean of the two neighbouring secants (weights depend on the widths of the intervals, so a nonuniform grid is handled), or zero when the secants have different signs or one of them is zero. The end tangents use the non-centered three point formula, set to zero when its sign differs from the end secant and limited to three times the end secant when the secants of the end intervals have different signs. With two points the interpolant is the straight line.

Parameters:

- `xs` (sequence of numbers): nodes, finite and strictly increasing; at least 2 points.
- `ys` (sequence of numbers): values, the same length as `xs`.

Returns a function `f` such that `(f x)` returns the interpolated `double` value at `x`. `f` returns the data value exactly at a node. Outside the domain the cubic of the first or the last interval is continued (extrapolation, not limited).

Throws `ex-info` (with `:type :invalid-input`, `:method :pchip` and a `:property`) when the lengths differ, there are fewer than 2 points, `xs` contains `NaN` or an infinity, or `xs` is not strictly increasing.

See also [[monotone]] (arithmetic mean tangents, Fritsch-Carlson), [[fastmath.interpolation.cubic/cubic]].
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