@Override protected DoubleArray doParameterSensitivity(double xValue) { double[] result = new double[yValues.length]; int lowerIndex = lowerBoundIndex(xValue, xValues); // check if x-value is at the last node if (lowerIndex == intervalCount) { // sensitivity is entirely to the last node result[intervalCount] = 1d; } else { double x1 = xValues[lowerIndex]; double x2 = xValues[lowerIndex + 1]; double dx = x2 - x1; double a = (x2 - xValue) / dx; result[lowerIndex] = a; result[lowerIndex + 1] = 1 - a; } return DoubleArray.ofUnsafe(result); }
@Override protected double doFirstDerivative(double xValue) { int lowerIndex = lowerBoundIndex(xValue, xValues); // check if x-value is at the last node if (lowerIndex == intervalCount) { // if value is at last node, calculate the gradient from the previous interval lowerIndex--; } return gradients[lowerIndex]; }
@Override protected double doInterpolateFromExtrapolator(double xValue) { int lowerIndex = lowerBoundIndex(xValue, xValues); // check if x-value is at the last node if (lowerIndex == intervalCount) { // if value is at last node, calculate the gradient from the previous interval lowerIndex--; } double x1 = xValues[lowerIndex]; double y1 = yValues[lowerIndex]; return y1 + (xValue - x1) * gradients[lowerIndex]; }
@Override protected double doInterpolate(double xValue) { // x-value is less than the x-value of the last node (lowerIndex < intervalCount) int lowerIndex = lowerBoundIndex(xValue, xValues); double x1 = xValues[lowerIndex]; double y1 = yValues[lowerIndex]; return y1 + (xValue - x1) * gradients[lowerIndex]; }