* Linear Interpolation
*/
CubicSplineInterpolator interp = new CubicSplineInterpolator();
Interpolator1DDataBundle dataBundLin1 = INTERP1D.getDataBundleFromSortedArrays(xValuesForLin, yValuesForLin1);
Interpolator1DDataBundle dataBundLin2 = INTERP1D.getDataBundleFromSortedArrays(xValuesForLin, yValuesForLin2);
for (int i = 0; i < keyLength; ++i) {
final double val = interp.interpolate(xValuesForLin, yValuesForLin1, xKeys[i]);
final double ref = val == 0. ? 1. : Math.abs(val);
assertEquals(val, INTERP1D.interpolate(dataBundLin1, xKeys[i]), ref * 1.e-15);
}
for (int i = 0; i < keyLength; ++i) {
final double val = interp.interpolate(xValuesForLin, yValuesForLin2, xKeys[i]);
final double ref = val == 0. ? 1. : Math.abs(val);
assertEquals(val, INTERP1D.interpolate(dataBundLin2, xKeys[i]), ref * 1.e-15);
}
for (int j = 0; j < 2; ++j) {
yValuesForLin1Up[j] = yValuesForLin1[j] == 0. ? EPS : yValuesForLin1[j] * (1. + EPS);
yValuesForLin2Up[j] = yValuesForLin2[j] == 0. ? EPS : yValuesForLin2[j] * (1. + EPS);
yValuesForLin1Dw[j] = yValuesForLin1[j] == 0. ? EPS : yValuesForLin1[j] * (1. - EPS);
yValuesForLin2Dw[j] = yValuesForLin2[j] == 0. ? EPS : yValuesForLin2[j] * (1. - EPS);
Interpolator1DDataBundle dataBund1Up = INTERP1D.getDataBundleFromSortedArrays(xValuesForLin, yValuesForLin1Up);
Interpolator1DDataBundle dataBund2Up = INTERP1D.getDataBundleFromSortedArrays(xValuesForLin, yValuesForLin2Up);
Interpolator1DDataBundle dataBund1Dw = INTERP1D.getDataBundleFromSortedArrays(xValuesForLin, yValuesForLin1Dw);
Interpolator1DDataBundle dataBund2Dw = INTERP1D.getDataBundleFromSortedArrays(xValuesForLin, yValuesForLin2Dw);
for (int i = 0; i < keyLength; ++i) {
final double ref1 = yValuesForLin1[j] == 0. ? EPS : yValuesForLin1[j] * EPS;
final double ref2 = yValuesForLin2[j] == 0. ? EPS : yValuesForLin2[j] * EPS;
double res1 = 0.5 * (INTERP1D.interpolate(dataBund1Up, xKeys[i]) - INTERP1D.interpolate(dataBund1Dw, xKeys[i])) / ref1;
double res2 = 0.5 * (INTERP1D.interpolate(dataBund2Up, xKeys[i]) - INTERP1D.interpolate(dataBund2Dw, xKeys[i])) / ref2;
assertEquals(res1, INTERP1D.getNodeSensitivitiesForValue(dataBundLin1, xKeys[i])[j], Math.max(Math.abs(yValuesForLin1[j]) * EPS, EPS));
assertEquals(res2, INTERP1D.getNodeSensitivitiesForValue(dataBundLin2, xKeys[i])[j], Math.max(Math.abs(yValuesForLin2[j]) * EPS, EPS));
}
yValuesForLin1Up[j] = yValuesForLin1[j];
yValuesForLin2Up[j] = yValuesForLin2[j];
yValuesForLin1Dw[j] = yValuesForLin1[j];
yValuesForLin2Dw[j] = yValuesForLin2[j];
}
/**
* Quadratic Interpolation
*/
Interpolator1DDataBundle dataBundQuad1 = INTERP1D.getDataBundleFromSortedArrays(xValuesForQuad, yValuesForQuad1);
Interpolator1DDataBundle dataBundQuad2 = INTERP1D.getDataBundleFromSortedArrays(xValuesForQuad, yValuesForQuad2);
for (int i = 0; i < keyLength; ++i) {
final double val = interp.interpolate(xValuesForQuad, yValuesForQuad1, xKeys[i]);
final double ref = val == 0. ? 1. : Math.abs(val);
assertEquals(val, INTERP1D.interpolate(dataBundQuad1, xKeys[i]), ref * 1.e-15);
}
for (int i = 0; i < keyLength; ++i) {
final double val = interp.interpolate(xValuesForQuad, yValuesForQuad2, xKeys[i]);
final double ref = val == 0. ? 1. : Math.abs(val);
assertEquals(val, INTERP1D.interpolate(dataBundQuad2, xKeys[i]), ref * 1.e-15);
}
for (int j = 0; j < 3; ++j) {
yValuesForQuad1Up[j] = yValuesForQuad1[j] == 0. ? EPS : yValuesForQuad1[j] * (1. + EPS);
yValuesForQuad2Up[j] = yValuesForQuad2[j] == 0. ? EPS : yValuesForQuad2[j] * (1. + EPS);
yValuesForQuad1Dw[j] = yValuesForQuad1[j] == 0. ? EPS : yValuesForQuad1[j] * (1. - EPS);
yValuesForQuad2Dw[j] = yValuesForQuad2[j] == 0. ? EPS : yValuesForQuad2[j] * (1. - EPS);
Interpolator1DDataBundle dataBund1Up = INTERP1D.getDataBundleFromSortedArrays(xValuesForQuad, yValuesForQuad1Up);
Interpolator1DDataBundle dataBund2Up = INTERP1D.getDataBundleFromSortedArrays(xValuesForQuad, yValuesForQuad2Up);
Interpolator1DDataBundle dataBund1Dw = INTERP1D.getDataBundleFromSortedArrays(xValuesForQuad, yValuesForQuad1Dw);
Interpolator1DDataBundle dataBund2Dw = INTERP1D.getDataBundleFromSortedArrays(xValuesForQuad, yValuesForQuad2Dw);
for (int i = 0; i < keyLength; ++i) {
final double ref1 = yValuesForQuad1[j] == 0. ? EPS : yValuesForQuad1[j] * EPS;
final double ref2 = yValuesForQuad2[j] == 0. ? EPS : yValuesForQuad2[j] * EPS;
double res1 = 0.5 * (INTERP1D.interpolate(dataBund1Up, xKeys[i]) - INTERP1D.interpolate(dataBund1Dw, xKeys[i])) / ref1;
double res2 = 0.5 * (INTERP1D.interpolate(dataBund2Up, xKeys[i]) - INTERP1D.interpolate(dataBund2Dw, xKeys[i])) / ref2;