@Override public BoundCurveInterpolator bind(DoubleArray xValues, DoubleArray yValues) { return new Bound(xValues, yValues); }
@Override protected double doFirstDerivative(double xValue) { int nCoefs = poly.getOrder(); int numberOfIntervals = poly.getNumberOfIntervals(); return differentiate(xValue, poly.getKnots(), poly.getCoefMatrix(), poly.getDimensions(), nCoefs, numberOfIntervals); }
private static double differentiate( double xValue, DoubleArray knots, DoubleMatrix coefMatrix, int dimensions, int nCoefs, int numberOfIntervals) { int rowCount = dimensions * numberOfIntervals; int colCount = nCoefs - 1; DoubleMatrix coef = DoubleMatrix.of( rowCount, colCount, (i, j) -> coefMatrix.get(i, j) * (nCoefs - j - 1)); return evaluate(xValue, knots, coef, dimensions); }
@Override protected double doInterpolate(double xValue) { return evaluate(xValue, poly.getKnots(), poly.getCoefMatrix(), poly.getDimensions()); }
@Override public BoundCurveInterpolator bind( BoundCurveExtrapolator extrapolatorLeft, BoundCurveExtrapolator extrapolatorRight) { return new Bound(this, extrapolatorLeft, extrapolatorRight); } }
private static double evaluate( double xValue, DoubleArray knots, DoubleMatrix coefMatrix, int dimensions) { // check for 1 less interval than knots int lowerBound = FunctionUtils.getLowerBoundIndex(knots, xValue); int indicator = lowerBound == knots.size() - 1 ? lowerBound - 1 : lowerBound; DoubleArray coefs = coefMatrix.row(dimensions * indicator); return getValue(coefs.toArrayUnsafe(), xValue, knots.get(indicator)); }