ArgChecker.notNull(pp, "null pp"); if (pp.getDimensions() > 1) { throw new UnsupportedOperationException(); int nCoefs = pp.getOrder(); ArgChecker.isFalse(nCoefs < 3, "Polynomial degree is too low"); int nIntervals = pp.getNumberOfIntervals(); DoubleMatrix[] senseMat = pp.getCoefficientSensitivityAll(); int nData = senseMat[0].columnCount(); for (int i = 0; i < nIntervals; ++i) { new PiecewisePolynomialResultsWithSensitivity(pp.getKnots(), pp.getCoefMatrix(), nCoefs - 2, pp.getDimensions(), diffSense); return nodeSensitivity(ppDiff, xKeys);
ArgChecker.isFalse(Double.isInfinite(xKey), "xKey containing Infinity"); if (pp.getDimensions() > 1) { throw new UnsupportedOperationException(); int nCoefs = pp.getOrder(); ArgChecker.isFalse(nCoefs < 2, "Polynomial degree is too low"); DoubleArray knots = pp.getKnots(); int nKnots = knots.size(); int interval = FunctionUtils.getLowerBoundIndex(knots, xKey); DoubleMatrix a = pp.getCoefficientSensitivity(interval);
/** * Finds the node sensitivity. * * @param pp the {@link PiecewisePolynomialResultsWithSensitivity} * @param xKey the key * @return Node sensitivity value at x=xKey */ public DoubleArray nodeSensitivity(PiecewisePolynomialResultsWithSensitivity pp, double xKey) { ArgChecker.notNull(pp, "null pp"); ArgChecker.isFalse(Double.isNaN(xKey), "xKey containing NaN"); ArgChecker.isFalse(Double.isInfinite(xKey), "xKey containing Infinity"); if (pp.getDimensions() > 1) { throw new UnsupportedOperationException(); } DoubleArray knots = pp.getKnots(); int nKnots = knots.size(); int interval = FunctionUtils.getLowerBoundIndex(knots, xKey); if (interval == nKnots - 1) { interval--; // there is 1 less interval that knots } double s = xKey - knots.get(interval); DoubleMatrix a = pp.getCoefficientSensitivity(interval); int nCoefs = a.rowCount(); DoubleArray res = a.row(0); for (int i = 1; i < nCoefs; i++) { res = (DoubleArray) MA.scale(res, s); res = (DoubleArray) MA.add(res, a.row(i)); } return res; }
DoubleMatrix[] newCoefSense = new DoubleMatrix[nIntervalsAll + 1]; for (int i = 0; i < nIntervalsAll; ++i) { newCoefSense[i] = resultCast.getCoefficientSensitivity(i); double[][] extraCoefSense = new double[resultCast.getOrder()][extraSense.length]; extraCoefSense[resultCast.getOrder() - 1] = Arrays.copyOf(extraSense, extraSense.length); extraCoefSense[resultCast.getOrder() - 2] = Arrays.copyOf(extraSenseDer, extraSenseDer.length); newCoefSense[nIntervalsAll] = DoubleMatrix.copyOf(extraCoefSense); return new PiecewisePolynomialResultsWithSensitivity( DoubleArray.copyOf(newKnots), DoubleMatrix.copyOf(newCoefMatrix), resultCast.getOrder(), 1, newCoefSense);
return new PiecewisePolynomialResultsWithSensitivity( DoubleArray.ofUnsafe(xValuesSrt), coefMatrix,
new PiecewisePolynomialResultsWithSensitivity( DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 1, sense1); final PiecewisePolynomialResultsWithSensitivity resSen2 = new PiecewisePolynomialResultsWithSensitivity( DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 1, sense1); final PiecewisePolynomialResultsWithSensitivity resSen3 = new PiecewisePolynomialResultsWithSensitivity( DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 1, sense2); assertTrue(resSen1.equals(resSen1)); assertTrue(!(resSen1.equals(ANOTHER_TYPE))); assertTrue(!(resSen1.equals(res5))); assertTrue(resSen1.equals(resSen2)); assertTrue(resSen2.equals(resSen1)); assertTrue(resSen1.hashCode() == resSen2.hashCode()); assertTrue(!(resSen1.hashCode() == resSen3.hashCode())); assertTrue(!(resSen1.equals(resSen3))); assertTrue(!(resSen3.equals(resSen1))); new PiecewisePolynomialResultsWithSensitivity( DoubleArray.copyOf(knots1), DoubleMatrix.copyOf(matrix1), order, 2, sense1); throw new RuntimeException();
final PiecewisePolynomialResultsWithSensitivity resultWithSensitivity = _method.interpolateWithSensitivity(xValues, yValues); ArgChecker.isTrue(resultWithSensitivity.getOrder() == 4, "Primary interpolant is not cubic"); final int nCoefs = coefMatrix.columnCount(); return new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(xValues), coefMatrix, nCoefs, 1, coefSenseMatrix);
@Override protected DoubleArray doParameterSensitivity(double xValue) { int interval = FunctionUtils.getLowerBoundIndex(poly.getKnots(), xValue); if (interval == poly.getKnots().size() - 1) { interval--; // there is 1 less interval than knots } DoubleMatrix coefficientSensitivity = polySens.get().getCoefficientSensitivity(interval); int nCoefs = coefficientSensitivity.rowCount(); double s = xValue - poly.getKnots().get(interval); DoubleArray res = coefficientSensitivity.row(0); for (int i = 1; i < nCoefs; i++) { res = (DoubleArray) MA.scale(res, s); res = (DoubleArray) MA.add(res, coefficientSensitivity.row(i)); } return res; }
Bound(DoubleArray xValues, DoubleArray yValues) { super(xValues, yValues); this.xValues = xValues.toArrayUnsafe(); this.yValues = yValues.toArrayUnsafe(); PiecewisePolynomialInterpolator underlying = new PiecewiseCubicHermiteSplineInterpolatorWithSensitivity(); PiecewisePolynomialResult poly = underlying.interpolate(xValues.toArray(), yValues.toArray()); this.knots = poly.getKnots(); this.coefMatrix = poly.getCoefMatrix(); this.coefMatrixSensi = Suppliers.memoize( () -> underlying.interpolateWithSensitivity(xValues.toArray(), yValues.toArray()).getCoefficientSensitivityAll()); }
ArgChecker.isFalse(Double.isInfinite(xKeys[i]), "xKey containing Infinity"); if (pp.getDimensions() > 1) { throw new UnsupportedOperationException(); DoubleArray knots = pp.getKnots(); int nKnots = knots.size(); DoubleMatrix a = pp.getCoefficientSensitivity(interval); int nCoefs = a.rowCount();
int nCoefs = coefMatrix.columnCount(); return new PiecewisePolynomialResultsWithSensitivity( DoubleArray.copyOf(xValues), coefMatrix, nCoefs, 1, coefSenseMatrix);
ArgChecker.isTrue(resultWithSensitivity.getOrder() == 4, "Primary interpolant is not cubic"); final int nCoefs = coefMatrix.columnCount(); return new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(xValues), coefMatrix, nCoefs, 1, coefSenseMatrix);
@Override protected DoubleArray doParameterSensitivity(double xValue) { int interval = FunctionUtils.getLowerBoundIndex(poly.getKnots(), xValue); if (interval == poly.getKnots().size() - 1) { interval--; // there is 1 less interval than knots } DoubleMatrix coefficientSensitivity = polySens.get().getCoefficientSensitivity(interval); int nCoefs = coefficientSensitivity.rowCount(); double s = xValue - poly.getKnots().get(interval); DoubleArray res = coefficientSensitivity.row(0); for (int i = 1; i < nCoefs; i++) { res = (DoubleArray) MA.scale(res, s); res = (DoubleArray) MA.add(res, coefficientSensitivity.row(i)); } return res; }
ArgChecker.notNull(pp, "null pp"); if (pp.getDimensions() > 1) { throw new UnsupportedOperationException(); int nCoefs = pp.getOrder(); ArgChecker.isFalse(nCoefs < 2, "Polynomial degree is too low"); int nIntervals = pp.getNumberOfIntervals(); DoubleMatrix[] senseMat = pp.getCoefficientSensitivityAll(); int nData = senseMat[0].columnCount(); for (int i = 0; i < nIntervals; ++i) { PiecewisePolynomialResultsWithSensitivity ppDiff = new PiecewisePolynomialResultsWithSensitivity( pp.getKnots(), pp.getCoefMatrix(), nCoefs - 1, pp.getDimensions(), diffSense); return nodeSensitivity(ppDiff, xKeys);
ArgChecker.isFalse(Double.isInfinite(xKey), "xKey containing Infinity"); if (pp.getDimensions() > 1) { throw new UnsupportedOperationException(); int nCoefs = pp.getOrder(); ArgChecker.isFalse(nCoefs < 3, "Polynomial degree is too low"); DoubleArray knots = pp.getKnots(); int nKnots = knots.size(); int interval = FunctionUtils.getLowerBoundIndex(knots, xKey); DoubleMatrix a = pp.getCoefficientSensitivity(interval);
final int nCoefs = coefMatrix.columnCount(); return new PiecewisePolynomialResultsWithSensitivity(DoubleArray.copyOf(xValues), coefMatrix, nCoefs, 1, coefSenseMatrix);
@Override protected DoubleArray doParameterSensitivity(double xValue) { int interval = FunctionUtils.getLowerBoundIndex(poly.getKnots(), xValue); if (interval == poly.getKnots().size() - 1) { interval--; // there is 1 less interval that knots } DoubleMatrix coefficientSensitivity = polySens.get().getCoefficientSensitivity(interval); double[] resSense = nodeSensitivity( xValue, poly.getKnots(), poly.getCoefMatrix(), poly.getDimensions(), interval, coefficientSensitivity).toArray(); double resValue = Math.exp(evaluate(xValue, poly.getKnots(), poly.getCoefMatrix(), poly.getDimensions())); double[] knotValues = getValues(logYValues); final int knotValuesLength = knotValues.length; double[] res = new double[knotValuesLength]; for (int i = 0; i < knotValuesLength; ++i) { res[i] = resSense[i + 1] * resValue / knotValues[i]; } return DoubleArray.ofUnsafe(res); }
final int nCoefs = coefMatrix.columnCount(); return new PiecewisePolynomialResultsWithSensitivity(_solver.getKnotsMat1D(xValues), coefMatrix, nCoefs, 1, coefSenseMatrix);
@Override protected DoubleArray doParameterSensitivity(double xValue) { int interval = FunctionUtils.getLowerBoundIndex(poly.getKnots(), xValue); if (interval == poly.getKnots().size() - 1) { interval--; // there is 1 less interval that knots } DoubleMatrix coefficientSensitivity = polySens.get().getCoefficientSensitivity(interval); double[] resSense = nodeSensitivity( xValue, poly.getKnots(), poly.getCoefMatrix(), poly.getDimensions(), interval, coefficientSensitivity).toArray(); double resValue = Math.exp(evaluate(xValue, poly.getKnots(), poly.getCoefMatrix(), poly.getDimensions())); double[] knotValues = getValues(logYValues); final int knotValuesLength = knotValues.length; double[] res = new double[knotValuesLength]; for (int i = 0; i < knotValuesLength; ++i) { res[i] = resSense[i] * resValue / knotValues[i]; } return DoubleArray.ofUnsafe(res); }
final int nCoefs = coefMatrix.columnCount(); return new PiecewisePolynomialResultsWithSensitivity(this._solver.getKnotsMat1D(xValues), coefMatrix, nCoefs, 1, coefSenseMatrix);