CubicSplineInterpolator extends PiecewisePolynomialInterpolator { @Override public PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues) { ArgumentChecker.notNull(xValues, "xValues"); ArgumentChecker.notNull(yValues, "yValues"); ArgumentChecker.isTrue(xValues.length == yValues.length | xValues.length + 2 == yValues.length, "(xValues length = yValues length) or (xValues length + 2 = yValues length)"); ArgumentChecker.isTrue(xValues.length > 1, "Data points should be more than 1"); final int nDataPts = xValues.length; final int nYdata = yValues.length; for (int i = 0; i < nDataPts; ++i) { ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xData containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xData containing Infinity"); } for (int i = 0; i < nYdata; ++i) { ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yData containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yData containing Infinity"); } for (int i = 0; i < nDataPts; ++i) { for (int j = i + 1; j < nDataPts; ++j) { ArgumentChecker.isFalse(xValues[i] == xValues[j], "Data should be distinct"); } } double[] xValuesSrt = new double[nDataPts]; double[] yValuesSrt = new double[nDataPts]; xValuesSrt = Arrays.copyOf(xValues, nDataPts); if (xValues.length + 2 == yValues.length) { _solver = new CubicSplineClampedSolver(yValues[0], yValues[nDataPts + 1]); yValuesSrt = Arrays.copyOfRange(yValues, 1, nDataPts + 1); } else { _solver = new CubicSplineNakSolver(); yValuesSrt = Arrays.copyOf(yValues, nDataPts); } ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt); final DoubleMatrix2D coefMatrix = _solver.solve(xValuesSrt, yValuesSrt); final int nCoefs = coefMatrix.getNumberOfColumns(); for (int i = 0; i < _solver.getKnotsMat1D(xValuesSrt).getNumberOfElements() - 1; ++i) { for (int j = 0; j < nCoefs; ++j) { ArgumentChecker.isFalse(Double.isNaN(coefMatrix.getData()[i][j]), "Too large input"); ArgumentChecker.isFalse(Double.isInfinite(coefMatrix.getData()[i][j]), "Too large input"); } } return new PiecewisePolynomialResult(_solver.getKnotsMat1D(xValuesSrt), coefMatrix, nCoefs, 1); }  @Override PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues); @Override PiecewisePolynomialResult interpolate(final double[] xValues, final double[][] yValuesMatrix); @Override PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(final double[] xValues, final double[] yValues);  }
@Test public void ClampedRecoverTest() { final double[] xValues = new double[] {1, 3, 2, 4 }; final double[] yValues = new double[] {3, -1, 1, 0, 8, 12 }; final double[][] yValuesMatrix = new double[][] { {3, -1, 1, 0, 8, 12 }, {-20, 20, 0, 5, 5, 10 } }; final double[] xSamples = new double[] {0, 5. / 2., 5. / 3., 29. / 7. }; final double[][] ySamples = new double[][] { {-8, 1. / 8., -1. / 27., Math.pow(15. / 7., 3.) }, {45., 5. / 4., 80. / 9., 320. / 49. } }; final double[][] xSamplesMatrix = new double[][] { {-2, 1, 2, 3 }, {4, 5, 6, 7 } }; final double[][][] ySamplesMatrix = new double[][][] { { {-64., -1., 0., 1. }, {8., 27., 64., 125. } }, { {125., 20., 5., 0 }, {5., 20., 45., 80. } } }; final int xDim = 2; final DoubleMatrix2D coefsExpectedMatrix = new DoubleMatrix2D( new double[][] { {1., -3., 3., -1 }, {0., 5., -20., 20 }, {1., 0., 0., 0. }, {0., 5., -10., 5 }, {1., 3., 3., 1. }, {0., 5., 0., 0. } }); final int dimMatrix = 2; final int orderMatrix = 4; final int nIntervalsMatrix = 3; final double[] knotsMatrix = new double[] {1, 2, 3, 4 }; CubicSplineInterpolator interpMatrix = new CubicSplineInterpolator(); PiecewisePolynomialResult resultMatrix = interpMatrix.interpolate(xValues, yValuesMatrix); final int nRows = coefsExpectedMatrix.getNumberOfRows(); final int nCols = coefsExpectedMatrix.getNumberOfColumns(); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { final double ref = coefsExpectedMatrix.getData()[i][j] == 0. ? 1. : Math.abs(coefsExpectedMatrix.getData()[i][j]); assertEquals(resultMatrix.getCoefMatrix().getData()[i][j], coefsExpectedMatrix.getData()[i][j], ref * EPS); } } assertEquals(resultMatrix.getNumberOfIntervals(), nIntervalsMatrix); assertEquals(resultMatrix.getOrder(), orderMatrix); assertEquals(resultMatrix.getDimensions(), dimMatrix); assertEquals(resultMatrix.getKnots().getData(), knotsMatrix); DoubleMatrix2D resultValuesMatrix2D = interpMatrix.interpolate(xValues, yValuesMatrix, xSamples); final int nSamples = xSamples.length; for (int i = 0; i < dimMatrix; ++i) { for (int j = 0; j < nSamples; ++j) { final double ref = ySamples[i][j] == 0. ? 1. : Math.abs(ySamples[i][j]); assertEquals(resultValuesMatrix2D.getData()[i][j], ySamples[i][j], ref * EPS); } } DoubleMatrix1D resultValuesMatrix1D = interpMatrix.interpolate(xValues, yValuesMatrix, xSamples[0]); for (int i = 0; i < dimMatrix; ++i) { final double ref = ySamples[i][0] == 0. ? 1. : Math.abs(ySamples[i][0]); assertEquals(resultValuesMatrix1D.getData()[i], ySamples[i][0], ref * EPS); } DoubleMatrix2D[] resultValuesMatrix2DVec = interpMatrix.interpolate(xValues, yValuesMatrix, xSamplesMatrix); for (int i = 0; i < nSamples; ++i) { for (int j = 0; j < dimMatrix; ++j) { for (int k = 0; k < xDim; ++k) { final double ref = ySamplesMatrix[j][k][i] == 0. ? 1. : Math.abs(ySamplesMatrix[j][k][i]); assertEquals(resultValuesMatrix2DVec[i].getData()[j][k], ySamplesMatrix[j][k][i], ref * EPS); } } } CubicSplineInterpolator interp = new CubicSplineInterpolator(); PiecewisePolynomialResult result = interp.interpolate(xValues, yValues); for (int i = 0; i < nIntervalsMatrix; ++i) { for (int j = 0; j < nCols; ++j) { final double ref = coefsExpectedMatrix.getData()[2 * i][j] == 0. ? 1. : Math.abs(coefsExpectedMatrix.getData()[2 * i][j]); assertEquals(result.getCoefMatrix().getData()[i][j], coefsExpectedMatrix.getData()[2 * i][j], ref * EPS); } } assertEquals(result.getNumberOfIntervals(), nIntervalsMatrix); assertEquals(result.getOrder(), orderMatrix); assertEquals(result.getDimensions(), 1); assertEquals(result.getKnots().getData(), knotsMatrix); DoubleMatrix1D resultValues1D = interp.interpolate(xValues, yValues, xSamples); for (int j = 0; j < nSamples; ++j) { final double ref = ySamples[0][j] == 0. ? 1. : Math.abs(ySamples[0][j]); assertEquals(resultValues1D.getData()[j], ySamples[0][j], ref * EPS); } double resultValue = interp.interpolate(xValues, yValues, xSamples[1]); final double refb = ySamples[0][1] == 0. ? 1. : Math.abs(ySamples[0][1]); assertEquals(resultValue, ySamples[0][1], refb * EPS); DoubleMatrix2D resultValuesMatrix2DSingle = interp.interpolate(xValues, yValues, xSamplesMatrix); for (int i = 0; i < nSamples; ++i) { for (int k = 0; k < xDim; ++k) { final double ref = ySamplesMatrix[0][k][i] == 0. ? 1. : Math.abs(ySamplesMatrix[0][k][i]); assertEquals(resultValuesMatrix2DSingle.getData()[k][i], ySamplesMatrix[0][k][i], ref * EPS); } } }
@Test public void NotAKnotRecoverTest() { final double[] xValues = new double[] {1, 3, 2, 4 }; final double[] yValues = new double[] {-1, 1, 0, 8 }; final double[][] yValuesMatrix = new double[][] { {-1, 1, 0, 8 }, {20, 0, 5, 5 } }; final double[] xSamples = new double[] {0, 5. / 2., 7. / 3., 29. / 7. }; final double[][] ySamples = new double[][] { {-8, 1. / 8., 1. / 27., Math.pow(15. / 7., 3.) }, {45., 5. / 4., 20. / 9., 320. / 49. } }; final double[][] xSamplesMatrix = new double[][] { {-2, 1, 2, 2.5 }, {4, 5, 6, 7 } }; final double[][][] ySamplesMatrix = new double[][][] { { {-64., -1., 0., 1. / 8. }, {8., 27., 64., 125. } }, { {125., 20., 5., 5. / 4. }, {5., 20., 45., 80. } } }; final int xDim = 2; final DoubleMatrix2D coefsExpectedMatrix = new DoubleMatrix2D( new double[][] { {1., -3., 3., -1 }, {0., 5., -20., 20 }, {1., 0., 0., 0. }, {0., 5., -10., 5 }, {1., 3., 3., 1. }, {0., 5., 0., 0. } }); final int dimMatrix = 2; final int orderMatrix = 4; final int nIntervalsMatrix = 3; final double[] knotsMatrix = new double[] {1, 2, 3, 4 }; CubicSplineInterpolator interpMatrix = new CubicSplineInterpolator(); PiecewisePolynomialResult resultMatrix = interpMatrix.interpolate(xValues, yValuesMatrix); final int nRows = coefsExpectedMatrix.getNumberOfRows(); final int nCols = coefsExpectedMatrix.getNumberOfColumns(); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { final double ref = coefsExpectedMatrix.getData()[i][j] == 0. ? 1. : Math.abs(coefsExpectedMatrix.getData()[i][j]); assertEquals(resultMatrix.getCoefMatrix().getData()[i][j], coefsExpectedMatrix.getData()[i][j], ref * EPS); } } assertEquals(resultMatrix.getNumberOfIntervals(), nIntervalsMatrix); assertEquals(resultMatrix.getOrder(), orderMatrix); assertEquals(resultMatrix.getDimensions(), dimMatrix); assertEquals(resultMatrix.getKnots().getData(), knotsMatrix); DoubleMatrix2D resultValuesMatrix2D = interpMatrix.interpolate(xValues, yValuesMatrix, xSamples); final int nSamples = xSamples.length; for (int i = 0; i < dimMatrix; ++i) { for (int j = 0; j < nSamples; ++j) { final double ref = ySamples[i][j] == 0. ? 1. : Math.abs(ySamples[i][j]); assertEquals(resultValuesMatrix2D.getData()[i][j], ySamples[i][j], ref * EPS); } } DoubleMatrix1D resultValuesMatrix1D = interpMatrix.interpolate(xValues, yValuesMatrix, xSamples[0]); for (int i = 0; i < dimMatrix; ++i) { final double ref = ySamples[i][0] == 0. ? 1. : Math.abs(ySamples[i][0]); assertEquals(resultValuesMatrix1D.getData()[i], ySamples[i][0], ref * EPS); } DoubleMatrix2D[] resultValuesMatrix2DVec = interpMatrix.interpolate(xValues, yValuesMatrix, xSamplesMatrix); for (int i = 0; i < nSamples; ++i) { for (int j = 0; j < dimMatrix; ++j) { for (int k = 0; k < xDim; ++k) { final double ref = ySamplesMatrix[j][k][i] == 0. ? 1. : Math.abs(ySamplesMatrix[j][k][i]); assertEquals(resultValuesMatrix2DVec[i].getData()[j][k], ySamplesMatrix[j][k][i], ref * EPS); } } } CubicSplineInterpolator interp = new CubicSplineInterpolator(); PiecewisePolynomialResult result = interp.interpolate(xValues, yValues); for (int i = 0; i < nIntervalsMatrix; ++i) { for (int j = 0; j < nCols; ++j) { final double ref = coefsExpectedMatrix.getData()[2 * i][j] == 0. ? 1. : Math.abs(coefsExpectedMatrix.getData()[2 * i][j]); assertEquals(result.getCoefMatrix().getData()[i][j], coefsExpectedMatrix.getData()[2 * i][j], ref * EPS); } } assertEquals(result.getNumberOfIntervals(), nIntervalsMatrix); assertEquals(result.getOrder(), orderMatrix); assertEquals(result.getDimensions(), 1); assertEquals(result.getKnots().getData(), knotsMatrix); DoubleMatrix1D resultValues1D = interp.interpolate(xValues, yValues, xSamples); for (int j = 0; j < nSamples; ++j) { final double ref = ySamples[0][j] == 0. ? 1. : Math.abs(ySamples[0][j]); assertEquals(resultValues1D.getData()[j], ySamples[0][j], ref * EPS); } double resultValue = interp.interpolate(xValues, yValues, xSamples[1]); final double refb = ySamples[0][1] == 0. ? 1. : Math.abs(ySamples[0][1]); assertEquals(resultValue, ySamples[0][1], refb * EPS); DoubleMatrix2D resultValuesMatrix2DSingle = interp.interpolate(xValues, yValues, xSamplesMatrix); for (int i = 0; i < nSamples; ++i) { for (int k = 0; k < xDim; ++k) { final double ref = ySamplesMatrix[0][k][i] == 0. ? 1. : Math.abs(ySamplesMatrix[0][k][i]); assertEquals(resultValuesMatrix2DSingle.getData()[k][i], ySamplesMatrix[0][k][i], ref * EPS); } } }
@Test public void LinearAndQuadraticNakTest() { final double[] xValuesForLin = new double[] {1., 2. }; final double[][] yValuesForLin = new double[][] { {3., 7. }, {2, -6 } }; final double[] xValuesForQuad = new double[] {1., 2., 3. }; final double[][] yValuesForQuad = new double[][] { {1., 6., 5. }, {2., -2., -3. } }; final double[][] coefsExpectedForLin = new double[][] { {4., 3., }, {-8., 2. } }; final double[][] coefsExpectedForQuad = new double[][] { {-3., 8., 1. }, {3. / 2., -11. / 2., 2. } }; final double[][] xKeys = new double[][] { {-0.5, 6. / 5., 2.38 }, {1., 2., 3. } }; final double[][][] yExpectedForLin = new double[][][] { { {-3., 3.8, 8.52 }, {3., 7., 11. } }, { {14., 0.4, -9.04 }, {2., -6., -14. } } }; final double[][][] yExpectedForQuad = new double[][][] { { {-17.75, 2.48, 6.3268 }, {1., 6., 5. } }, { {13.625, 0.96, -2.7334 }, {2., -2., -3. } } }; final int keyDim = xKeys.length; final int keyLength = xKeys[0].length; final int yDim = yValuesForLin.length; CubicSplineInterpolator interp = new CubicSplineInterpolator(); PiecewisePolynomialResult resultLin = interp.interpolate(xValuesForLin, yValuesForLin); int nRowsLin = coefsExpectedForLin.length; int nColsLin = coefsExpectedForLin[0].length; for (int i = 0; i < nRowsLin; ++i) { for (int j = 0; j < nColsLin; ++j) { final double ref = coefsExpectedForLin[i][j] == 0. ? 1. : Math.abs(coefsExpectedForLin[i][j]); assertEquals(resultLin.getCoefMatrix().getData()[i][j], coefsExpectedForLin[i][j], ref * EPS); } } assertEquals(resultLin.getDimensions(), yDim); assertEquals(resultLin.getNumberOfIntervals(), 1); assertEquals(resultLin.getKnots().getData(), xValuesForLin); assertEquals(resultLin.getOrder(), 2); resultLin = interp.interpolate(xValuesForLin, yValuesForLin[0]); for (int i = 0; i < 2; ++i) { final double ref = coefsExpectedForLin[0][i] == 0. ? 1. : Math.abs(coefsExpectedForLin[0][i]); assertEquals(resultLin.getCoefMatrix().getData()[0][i], coefsExpectedForLin[0][i], ref * EPS); } assertEquals(resultLin.getDimensions(), 1); assertEquals(resultLin.getNumberOfIntervals(), 1); assertEquals(resultLin.getKnots().getData(), xValuesForLin); assertEquals(resultLin.getOrder(), 2); DoubleMatrix2D resultMatrixLin2D = interp.interpolate(xValuesForLin, yValuesForLin[0], xKeys); for (int i = 0; i < keyDim; ++i) { for (int j = 0; j < keyLength; ++j) { final double ref = yExpectedForLin[0][i][j] == 0. ? 1. : Math.abs(yExpectedForLin[0][i][j]); assertEquals(resultMatrixLin2D.getData()[i][j], yExpectedForLin[0][i][j], ref * EPS); } } DoubleMatrix1D resultMatrixLin1D = interp.interpolate(xValuesForLin, yValuesForLin[0], xKeys[0]); for (int j = 0; j < keyLength; ++j) { final double ref = yExpectedForLin[0][0][j] == 0. ? 1. : Math.abs(yExpectedForLin[0][0][j]); assertEquals(resultMatrixLin1D.getData()[j], yExpectedForLin[0][0][j], ref * EPS); } double resultMatrixLinValue = interp.interpolate(xValuesForLin, yValuesForLin[0], xKeys[0][0]); { final double ref = yExpectedForLin[0][0][0] == 0. ? 1. : Math.abs(yExpectedForLin[0][0][0]); assertEquals(resultMatrixLinValue, yExpectedForLin[0][0][0], ref * EPS); } DoubleMatrix1D resultMatrixLinValues1D = interp.interpolate(xValuesForLin, yValuesForLin, xKeys[0][0]); for (int i = 0; i < yDim; ++i) { final double ref = yExpectedForLin[i][0][0] == 0. ? 1. : Math.abs(yExpectedForLin[i][0][0]); assertEquals(resultMatrixLinValues1D.getData()[i], yExpectedForLin[i][0][0], ref * EPS); } DoubleMatrix2D[] resultMatrixLin2DVec = interp.interpolate(xValuesForLin, yValuesForLin, xKeys); for (int i = 0; i < yDim; ++i) { for (int j = 0; j < keyDim; ++j) { for (int k = 0; k < keyLength; ++k) { final double ref = yExpectedForLin[i][j][k] == 0. ? 1. : Math.abs(yExpectedForLin[i][j][k]); assertEquals(resultMatrixLin2DVec[k].getData()[i][j], yExpectedForLin[i][j][k], ref * EPS); } } } PiecewisePolynomialResult resultQuad = interp.interpolate(xValuesForQuad, yValuesForQuad); int nRowsQuad = coefsExpectedForQuad.length; int nColsQuad = coefsExpectedForQuad[0].length; for (int i = 0; i < nRowsQuad; ++i) { for (int j = 0; j < nColsQuad; ++j) { final double ref = coefsExpectedForQuad[i][j] == 0. ? 1. : Math.abs(coefsExpectedForQuad[i][j]); assertEquals(resultQuad.getCoefMatrix().getData()[i][j], coefsExpectedForQuad[i][j], ref * EPS); } } assertEquals(resultQuad.getDimensions(), yDim); assertEquals(resultQuad.getNumberOfIntervals(), 1); assertEquals(resultQuad.getKnots().getData(), new double[] {xValuesForQuad[0], xValuesForQuad[2] }); assertEquals(resultQuad.getOrder(), 3); resultQuad = interp.interpolate(xValuesForQuad, yValuesForQuad[0]); for (int i = 0; i < 3; ++i) { final double ref = coefsExpectedForQuad[0][i] == 0. ? 1. : Math.abs(coefsExpectedForQuad[0][i]); assertEquals(resultQuad.getCoefMatrix().getData()[0][i], coefsExpectedForQuad[0][i], ref * EPS); } assertEquals(resultQuad.getDimensions(), 1); assertEquals(resultQuad.getNumberOfIntervals(), 1); assertEquals(resultQuad.getKnots().getData(), new double[] {xValuesForQuad[0], xValuesForQuad[2] }); assertEquals(resultQuad.getOrder(), 3); DoubleMatrix2D resultMatrixQuad2D = interp.interpolate(xValuesForQuad, yValuesForQuad[0], xKeys); for (int i = 0; i < keyDim; ++i) { for (int j = 0; j < keyLength; ++j) { final double ref = yExpectedForQuad[0][i][j] == 0. ? 1. : Math.abs(yExpectedForQuad[0][i][j]); assertEquals(resultMatrixQuad2D.getData()[i][j], yExpectedForQuad[0][i][j], ref * EPS); } } DoubleMatrix1D resultMatrixQuad1D = interp.interpolate(xValuesForQuad, yValuesForQuad[0], xKeys[0]); for (int j = 0; j < keyLength; ++j) { final double ref = yExpectedForQuad[0][0][j] == 0. ? 1. : Math.abs(yExpectedForQuad[0][0][j]); assertEquals(resultMatrixQuad1D.getData()[j], yExpectedForQuad[0][0][j], ref * EPS); } double resultMatrixQuadValue = interp.interpolate(xValuesForQuad, yValuesForQuad[0], xKeys[0][0]); { final double ref = yExpectedForQuad[0][0][0] == 0. ? 1. : Math.abs(yExpectedForQuad[0][0][0]); assertEquals(resultMatrixQuadValue, yExpectedForQuad[0][0][0], ref * EPS); } DoubleMatrix1D resultMatrixQuadValues1D = interp.interpolate(xValuesForQuad, yValuesForQuad, xKeys[0][0]); for (int i = 0; i < yDim; ++i) { final double ref = yExpectedForQuad[i][0][0] == 0. ? 1. : Math.abs(yExpectedForQuad[i][0][0]); assertEquals(resultMatrixQuadValues1D.getData()[i], yExpectedForQuad[i][0][0], ref * EPS); } DoubleMatrix2D[] resultMatrixQuad2DVec = interp.interpolate(xValuesForQuad, yValuesForQuad, xKeys); for (int i = 0; i < yDim; ++i) { for (int j = 0; j < keyDim; ++j) { for (int k = 0; k < keyLength; ++k) { final double ref = yExpectedForQuad[i][j][k] == 0. ? 1. : Math.abs(yExpectedForQuad[i][j][k]); assertEquals(resultMatrixQuad2DVec[k].getData()[i][j], yExpectedForQuad[i][j][k], ref * EPS); } } } }
@Test(expectedExceptions = IllegalArgumentException.class) public void DataShortNakTest() { final double[] xValues = new double[] {1. }; final double[] yValues = new double[] {4. }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void DataShortNakMultiTest() { final double[] xValues = new double[] {1. }; final double[][] yValues = new double[][] { {4. }, {3. } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void DataShortClapmedTest() { final double[] xValues = new double[] {1. }; final double[] yValues = new double[] {0., 4., 3. }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void DataShortClapmedMultiTest() { final double[] xValues = new double[] {1. }; final double[][] yValues = new double[][] { {0., 4., 3. }, {9., 4., 1.5 } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void WrongDataLengthTest() { final double[] xValues = new double[] {1, 2, 3 }; final double[] yValues = new double[] {2, 3, 4, 5 }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void WrongDataLengthMultiTest() { final double[] xValues = new double[] {1, 2, 3 }; final double[][] yValues = new double[][] { {1, 3, 5, 2 }, {5, 3, 2, 7 }, {1, 8, -1, 0 } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void RepeatDataTest() { final double[] xValues = new double[] {1., 2., 0.5, 8., 1. / 2. }; final double[] yValues = new double[] {2., 3., 4., 5., 8. }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void RepeatDataMultiTest() { final double[] xValues = new double[] {1., 2., 0.5, 8., 1. / 2. }; final double[][] yValues = new double[][] { {2., 3., 4., 5., 8. }, {2., 1., 4., 2., 8. } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NullTest() { final double[] xValues = null; final double[] yValues = null; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NullmultiTest() { final double[] xValues = null; final double[][] yValues = null; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfinityXTest() { final int nPts = 5; double[] xValues = new double[nPts]; double[] yValues = new double[nPts]; final double zero = 0.; for (int i = 0; i < nPts; ++i) { xValues[i] = 1. / zero; yValues[i] = i; } CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfinityYTest() { final int nPts = 5; double[] xValues = new double[nPts]; double[] yValues = new double[nPts]; final double zero = 0.; for (int i = 0; i < nPts; ++i) { xValues[i] = i; yValues[i] = 1. / zero; } CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfinityXMultiTest() { final int nPts = 5; final int nDim = 3; double[] xValues = new double[nPts]; double[][] yValues = new double[nDim][nPts]; final double zero = 0.; for (int i = 0; i < nPts; ++i) { xValues[i] = i; for (int j = 0; j < nDim; ++j) { yValues[j][i] = i; } } xValues[1] = 1. / zero; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfinityYMultiTest() { final int nPts = 5; final int nDim = 3; double[] xValues = new double[nPts]; double[][] yValues = new double[nDim][nPts]; final double zero = 0.; for (int i = 0; i < nPts; ++i) { xValues[i] = i; for (int j = 0; j < nDim; ++j) { yValues[j][i] = i; } } yValues[1][2] = 1. / zero; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNXTest() { final int nPts = 5; double[] xValues = new double[nPts]; double[] yValues = new double[nPts]; for (int i = 0; i < nPts; ++i) { xValues[i] = i; yValues[i] = i; } xValues[1] = Double.NaN; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNYTest() { final int nPts = 5; double[] xValues = new double[nPts]; double[] yValues = new double[nPts]; for (int i = 0; i < nPts; ++i) { xValues[i] = i; yValues[i] = i; } yValues[1] = Double.NaN; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNXMultiTest() { final int nPts = 5; final int nDim = 3; double[] xValues = new double[nPts]; double[][] yValues = new double[nDim][nPts]; for (int i = 0; i < nPts; ++i) { xValues[i] = i; for (int j = 0; j < nDim; ++j) { yValues[j][i] = i; } } xValues[1] = Double.NaN; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNYMultiTest() { final int nPts = 5; final int nDim = 3; double[] xValues = new double[nPts]; double[][] yValues = new double[nDim][nPts]; for (int i = 0; i < nPts; ++i) { xValues[i] = i; for (int j = 0; j < nDim; ++j) { yValues[j][i] = i; } } yValues[1][0] = Double.NaN; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNOutputNakTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[] yValues = new double[] {1., 6.e307, -2.e306, 3. }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNOutputClampedTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[] yValues = new double[] {2., 1., 6.e307, -2.e306, 3., 6. }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNOutputNakMultiTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[][] yValues = new double[][] { {1., 2., 3., 4. }, {1., 6.e307, -2.e306, 3. } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NaNOutputClampedMultiTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[][] yValues = new double[][] { {3., 1., 2., 3., 4., 1. }, {100., 1., 6.e307, -2.e306, 3., 2 } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfOutputNakTest() { final double[] xValues = new double[] {1., 1.000001 }; final double[] yValues = new double[] {1., 3.e307 }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfOutputClampedTest() { final double[] xValues = new double[] {1., 1.000001 }; final double[] yValues = new double[] {0., 1., 3.e307, 0. }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfOutputNakMultiTest() { final double[] xValues = new double[] {1., 1.000001 }; final double[][] yValues = new double[][] { {1., 2. }, {1., 3.e307 } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfOutputClampedMultiTest() { final double[] xValues = new double[] {1., 1.000001 }; final double[][] yValues = new double[][] { {3., 1., 2., 1. }, {0., 1., 3.e307, 0. } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfOutputNakQuadTest() { final double[] xValues = new double[] {1., 1.000001, 1.000002 }; final double[] yValues = new double[] {1., 3.e307, 3.e-307 }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void InfOutputNakQuadMultiTest() { final double[] xValues = new double[] {1., 1.000001, 1.000002 }; final double[][] yValues = new double[][] { {2., 3., 4. }, {1., 3.e307, 3.e-307 } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues); }
@Test(expectedExceptions = IllegalArgumentException.class) public void LargeKeyTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[] yValues = new double[] {8., 6., 7., 8. }; final double key = 3.e103; CubicSplineInterpolator interp = new CubicSplineInterpolator(); System.out.println(interp.interpolate(xValues, yValues, key)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void LargeMultiKeyTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[] yValues = new double[] {8., 6., 7., 8. }; final double[] key = new double[] {1., 3., 3.e103 }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); System.out.println(interp.interpolate(xValues, yValues, key)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void LargeKeyMultiTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[][] yValues = new double[][] { {8., 6., 7., 8. }, {3., 12., 1., 8. } }; final double key = 3.e103; CubicSplineInterpolator interp = new CubicSplineInterpolator(); System.out.println(interp.interpolate(xValues, yValues, key)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void LargeMultiKeyMultiTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[][] yValues = new double[][] { {8., 6., 7., 8. }, {3., 12., 1., 8. } }; final double[] key = new double[] {1., 3., 3.e103 }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); System.out.println(interp.interpolate(xValues, yValues, key)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void LargeMatrixKeyTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[] yValues = new double[] {8., 6., 7., 8. }; final double[][] key = new double[][] { {1., 3., 3.e103 }, {0.1, 2., 5. } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); System.out.println(interp.interpolate(xValues, yValues, key)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void LargeMatrixKeyMultiTest() { final double[] xValues = new double[] {1., 2., 3., 4. }; final double[][] yValues = new double[][] { {8., 6., 7., 8. }, {3., 12., 1., 8. } }; final double[][] key = new double[][] { {1., 3., 3.e103 }, {0.1, 2., 5. } }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); System.out.println(interp.interpolate(xValues, yValues, key)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NullKeyTest() { double[] xValues = new double[] {1., 2., 3. }; double[] yValues = new double[] {1., 3., 4. }; double[] xKey = new double[3]; xKey = null; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues, xKey); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NullKeyMultiTest() { double[] xValues = new double[] {1., 2., 3. }; double[][] yValues = new double[][] { {1., 3., 4. }, {2., 3., 1. } }; double[] xKey = new double[3]; xKey = null; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues, xKey); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NullKeyMatrixTest() { double[] xValues = new double[] {1., 2., 3. }; double[] yValues = new double[] {1., 3., 4. }; double[][] xKey = new double[3][3]; xKey = null; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues, xKey); }
@Test(expectedExceptions = IllegalArgumentException.class) public void NullKeyMatrixMultiTest() { double[] xValues = new double[] {1., 2., 3. }; double[][] yValues = new double[][] { {1., 3., 4. }, {2., 3., 1. } }; double[][] xKey = new double[3][4]; xKey = null; CubicSplineInterpolator interp = new CubicSplineInterpolator(); interp.interpolate(xValues, yValues, xKey); }
@Test (enabled = false) public void printTest() { final double[] xValues = new double[] {1., 2., 2.00001, 4. }; final double[] yValues = new double[] {2., 3., 4., 5. }; CubicSplineInterpolator interp = new CubicSplineInterpolator(); PiecewisePolynomialResult result = interp.interpolate(xValues, yValues); System.out.println(result.getCoefMatrix()); System.out.println(result.getKnots()); System.out.println(result.getNumberOfIntervals()); System.out.println(result.getOrder()); System.out.println(result.getDimensions()); System.out.println(interp.interpolate(xValues, yValues, 3.9999)); }