Repository navigation
NearestNeighbor.Function.createNearestNeighborInterpolator
commons-math-interpolation / NearestNeighbor / createNearestNeighborInterpolator
function createNearestNeighborInterpolator(xVals, yVals): UniFunction;Defined in: NearestNeighbor.ts:37
Returns a nearest neighbor interpolating function for a dataset.
The returned function returns the y value of the interpolation point nearest to its argument.
If the argument is exactly in the middle between two points, the y value of the right point is returned.
Arguments below the first point return the y value of the first point, and arguments above the last point
return the y value of the last point. If the argument is NaN, NaN is returned.
Unlike the other interpolation methods, this method also accepts fewer than two points:
With no points, the returned function always returns NaN.
With a single point, it returns the y value of that point for all arguments except NaN.
The passed arrays are copied, so the returned function does not depend on them.
ArrayLike<number>
The arguments of the interpolation points, in strictly increasing order. The values must be finite.
ArrayLike<number>
The values of the interpolation points.
A function which interpolates the dataset.
Error
If xVals and yVals have different lengths, or if xVals contains non-finite values
or is not strictly increasing.