[ILNumerics Interpolation Toolbox]
Namespace: ILNumerics.Toolboxes
Assembly: ILNumerics.Toolboxes.Interpolation (in ILNumerics.Toolboxes.Interpolation.dll) Version: 5.5.0.0 (5.5.7503.3146)
public static RetArray<float> interpn( InArray<float> V, InCell X = null, InCell Xn = null, InterpolationMethod method = InterpolationMethod.linear )
Parameters
- V
- Type: ILNumericsInArraySingle
N-dimensional array with known values. - X (Optional)
- Type: ILNumericsInCell
[Optional] Cell array with range definitions for each dimension in V. Default (null): assume uniform spacing of length 1. - Xn (Optional)
- Type: ILNumericsInCell
[Optional] New query points. Cell vector of length N. Default: (null) define new points by subdividing ranges given in X. - method (Optional)
- Type: ILNumerics.ToolboxesInterpolationMethod
[Optional] Interpolation method. Default: linear.
Return Value
Type: RetArraySingleN-dimensional array with interpolated values. The size corresponds to the ranges given by Xn.
Exception | Condition |
---|---|
ArgumentException | if any of the input parameter is invalid. |
interpn(InArraySingle, NullableSingle, InCell, InCell, InterpolationMethod) interpolates new points from a rectilinear, uniform or non-uniform grid of sample points. Both, the set of sampled values V as well as the set of new query points Xn are expected as a rectilinear n-dimensional grid. A rectilinear grid exposes square angles in all crossings of grid lines. However, individual grid elements (simplex or hyper cubes) are not necessarily congruent.
interpn(InArraySingle, InCell, InCell, InterpolationMethod) assigns NaN to all query points laying outside of the range of X. Use the overload interpn(InArraySingle, NullableSingle, InCell, InCell, InterpolationMethod) in order to specify another value for grid points laying out-of-range or to create extrapolated values for them by specifying its outOfRange parameter as null.
As a special case V can be a row vector or a column vector. In this case X and Xn are expected as vectors (hence one dimensional) and a shape preserving 1-dimensional interpolation is performed on the values of V.
In the general case X and Xn are cell containers, each holding N vectors of range definitions. X describes the 'coordinates' for the N dimensions of V. Xn specifies the grid of new query points to be interpolated. Here, Xn determines a hyper cube of N dimensions. Each array from Xn corresponds to one dimension of the resulting N-dim array.
Cell array elements in both, X and Xn must be arrays with strictly monotonically increasing numerical elements. They form a regular grid which, however, is not required to be equally spaced. So the distances between elements within one dimension range in X and Xn can be arbitrary.
Any cell element specified in X for a specific dimension i must match the length of the corresponding dimension in V, i.e.
X.GetArray<float>(i).S.NumberOfElements == V.S[i]
Cell elements in X and Xn may have any numeric element type. However, it is recommended to provide these ranges as ArrayT of element type 'float' since it gives both: best performance and best precision. Other element types are converted to float arrays internally.
The method parameter determines the algorithm used for interpolation. The default method is linear. The following methods are supported:
- nearest - Nearest neighbor interpolation returns the nearest sample point in terms of its euclidean distance to a query point. This method needs little ressources and is recommended for 'large' and 'huge' data (what ever that means in relation to your hardware).
- previous - returns the sample point from the surrounding hyper cube with the smallest index in each dimension, corresponds to the floor() function. For query points outside of the specified domain the nearest available sample point is returned. At least 2 samples are required in each dimension. This function requires little resources and performs at about the same speed as nearest.
- next - returns the sample point from the surrounding hyper cube with the highest index in each dimension, corresponds to the ceil() function. If no 'next' sample is available (for extrapolating query points) the last edge sample is returned. At least 2 samples are required in each dimension. This function needs little resources and performs with about the same speed as nearest.
- linear - Linear interpolation between adjacent sample points, produces continous function values but discontinuities in the first derivative. One will notice that the slopes of the interpolation result will change abruptly at the sample points. This method is efficiently implemented and carefully optimized. It is most efficient for query sets having a significant number of query points lined up along the first dimension. The algorithm uses slightly more ressources than nearest but fewer ressources as cubic and spline. At least two samples in each dimension are needed in each working dimension of V for linear interpolation.
- parabolic, cubic and pp - Piecewise cubic interpolation builds up a polynomial of order 2 or 3 respectively, based on the 3 or 4 points surrounding a query point. The interpolation result will be smooth in the function values and its first derivatives, but may introduce jumps in the second derivatives at the sample points. Due to its computational simplicity cubic interpolation is able to serve as a quick alternative for large datasets with less strict smoothness requirements as an alternative to spline interpolation. At least 3 or 4 points are required in V in each dimension for 'parabolic' and 'cubic' polynomials respectively.
- polynomial - performs global polynomial interpolation along each dimension iseparately. The order of the polynomial function corresponds to the number of sample points V.S[i]-1 along dimension i. Due to the nature of higher order polynomials such 'global' interpolation is best suited for small sample sets with 3...7 sample values in each dimension of V. For larger data, consider using one of the piecewise interpolations, like cubic or spline.
- spline - cubic spline interpolation produces the smoothest results in terms of function values as well as its first and second derivatives. For uniform V (i.e. elements of X are equally spaced within each dimension but not necessarily have the same spacing among all dimensions) an efficient N-D implementation of Catmull-Rom splines is used. Query points at the edges of V are computed by help of virtual query points extending the domain of X in each direction. For non-uniform X general cubic splines are applied with not-a-knot boundary condition. At least 3 sample points are required for V in each (working) dimension. One may use splinen(InArraySingle, NullableSingle, InCell, InCell) directly if more control of the boundary conditions is needed. This method brings the smoothest results among all methods listed here - to the price of slightly higher computational demands.
By default interpn(InArraySingle, InCell, InCell, InterpolationMethod) assigns NaN to all query points laying outside of the range as specified in X. Use the overload interpn(InArraySingle, NullableSingle, InCell, InCell, InterpolationMethod) in order to specify another value for grid points laying out of range or to create extrapolated values for them by specifying the outOfRange parameter as null.
[ILNumerics Interpolation Toolbox]