Class MultiCubicSpline
N-dimensional cubic spline interpolation between discrete points, in 1 to 15 dimensions.
public sealed class MultiCubicSpline
- Inheritance
-
MultiCubicSpline
- Inherited Members
Remarks
QuantLib's recursion: at construction a natural cubic spline's second derivatives along the last dimension, for every line of it; at each evaluation the splines of the lower dimensions through the values the higher ones interpolate, the first dimension last, each step's arithmetic and order QuantLib's, so the values are QuantLib's.
Immutable and safe to share across threads: the grid and the values are copied, and each evaluation computes
QuantLib's coefficients in scratch of its own, where QuantLib's spline holds references to its inputs and
evaluates through mutable members. The dimension is the grid's, read at construction, where QuantLib's is a
template parameter.
The last grid point of a dimension is interpolated on its last interval, where QuantLib refuses it as
extrapolation (its documented bug, "cannot interpolate at the grid points on the boundary surface"), and with
extrapolation allowed a point beyond it reads the last value, where QuantLib's flat value reads one value past the
data; an argument that isn't a number is refused, where QuantLib's search reads past the grid
(Divergences/MultiCubicSplineBoundaryTests.cs).
Constructors
MultiCubicSpline(ImmutableArray<ImmutableArray<double>>, ReadOnlySpan<double>, ReadOnlySpan<bool>)
Initializes a new instance of the MultiCubicSpline class.
public MultiCubicSpline(ImmutableArray<ImmutableArray<double>> grid, ReadOnlySpan<double> values, ReadOnlySpan<bool> extrapolation = default)
Parameters
gridImmutableArray<ImmutableArray<double>>The grid, one increasing list of at least four points per dimension.
valuesReadOnlySpan<double>The values at the grid's points, the first dimension slowest (QuantLib's nested data table, flattened), copied.
extrapolationReadOnlySpan<bool>Whether each dimension extrapolates flat beyond the grid; empty, QuantLib's default, for none.
Exceptions
- ArgumentException
The grid's dimension isn't 1 to 15, a dimension is empty, holds fewer than four points or isn't increasing, the values don't fill the grid, or the extrapolation flags aren't one per dimension.
Fields
MaxDimension
The largest dimension, QuantLib's fifteen splines.
public const int MaxDimension = 15
Field Value
Properties
Dimension
Gets the dimension.
public int Dimension { get; }
Property Value
Grid
Gets the grid.
public ImmutableArray<ImmutableArray<double>> Grid { get; }
Property Value
Methods
Evaluate(ReadOnlySpan<double>)
The interpolated value at a point.
public double Evaluate(ReadOnlySpan<double> x)
Parameters
xReadOnlySpan<double>The point, one coordinate per dimension.
Returns
- double
The value.
Exceptions
- ArgumentException
xdoesn't hold one coordinate per dimension, a coordinate isn't a number, or lies outside its dimension's grid where that dimension doesn't extrapolate.