/** * /check individual functions first */ @Test public void functionsTest() { for (int i = 0; i < 3; i++) { DoubleArray y = F[i].apply(X[i]); DoubleMatrix jac = F[i].calculateJacobian(X[i]); AssertMatrix.assertEqualsVectors(Y_EXP[i], y, 1e-15); AssertMatrix.assertEqualsMatrix(JAC_EXP[i], jac, 1e-15); } }
@Override public DoubleArray apply(DoubleArray x) { ArgChecker.notNull(x, "x"); ArgChecker.isTrue( x.size() == getLengthOfDomain(), "Incorrect length of x. Is {} but should be {}", x.size(), getLengthOfDomain()); double[] y = new double[getLengthOfRange()]; int posInput = 0; int posOutput = 0; //evaluate each function (with the appropriate sub vector) and concatenate the results for (int i = 0; i < nPartitions; i++) { int length = xPartition[i]; DoubleArray sub = x.subArray(posInput, posInput + length); DoubleArray eval = functions[i].apply(sub); eval.copyInto(y, posOutput); posInput += length; posOutput += eval.size(); } return DoubleArray.copyOf(y); }
@Test public void test() { final ParameterizedCurveVectorFunctionProvider pro = new ParameterizedCurveVectorFunctionProvider(s_PCurve); final double[] points = new double[] {-1.0, 0.0, 1.0 }; final VectorFunction f = pro.from(points); assertEquals(2, f.getLengthOfDomain()); assertEquals(3, f.getLengthOfRange()); final DoubleArray x = DoubleArray.of(0.5, 2.0); //the parameters a & b final DoubleArray y = f.apply(x); assertEquals(0.5 * Math.sinh(-2.0), y.get(0), 1e-14); assertEquals(0.0, y.get(1), 1e-14); assertEquals(0.5 * Math.sinh(2.0), y.get(2), 1e-14); final DoubleMatrix jac = f.calculateJacobian(x); final DoubleMatrix fdJac = (new VectorFieldFirstOrderDifferentiator().differentiate(f)).apply(x); AssertMatrix.assertEqualsMatrix(fdJac, jac, 1e-9); } }