/** * Creates an instance. * * @param absoluteTol the absolute tolerance * @param relativeTol the relative tolerance * @param maxSteps the maximum steps * @param decomp the decomposition */ public BroydenVectorRootFinder(double absoluteTol, double relativeTol, int maxSteps, Decomposition<?> decomp) { super( absoluteTol, relativeTol, maxSteps, new JacobianDirectionFunction(decomp), new JacobianEstimateInitializationFunction(), new BroydenMatrixUpdateFunction()); }
@Override public DoubleArray getRoot(Function<DoubleArray, DoubleArray> function, DoubleArray startPosition) { return findRoot(function, startPosition); }
/** * Creates an instance. * * @param absoluteTol the absolute tolerance * @param relativeTol the relative tolerance * @param maxSteps the maximum steps * @param decomp the decomposition */ public NewtonDefaultVectorRootFinder(double absoluteTol, double relativeTol, int maxSteps, Decomposition<?> decomp) { super( absoluteTol, relativeTol, maxSteps, new JacobianDirectionFunction(decomp), new JacobianEstimateInitializationFunction(), new NewtonDefaultUpdateFunction()); }
private void cubicBacktrack(DoubleArray p, Function<DoubleArray, DoubleArray> function, DataBundle data) { double temp1, temp2, temp3, temp4, temp5; double lambda0 = data.getLambda0(); double lambda1 = data.getLambda1(); double g0 = data.getG0(); temp1 = 1.0 / lambda0 / lambda0; temp2 = 1.0 / lambda1 / lambda1; temp3 = data.getG1() + g0 * (2 * lambda0 - 1.0); temp4 = data.getG2() + g0 * (2 * lambda1 - 1.0); temp5 = 1.0 / (lambda0 - lambda1); double a = temp5 * (temp1 * temp3 - temp2 * temp4); double b = temp5 * (-lambda1 * temp1 * temp3 + lambda0 * temp2 * temp4); double lambda = (-b + Math.sqrt(b * b + 6 * a * g0)) / 3 / a; lambda = Math.min(Math.max(lambda, 0.01 * lambda0), 0.75 * lambda1); // make sure new lambda is between 1% & 75% of old value data.swapLambdaAndReplace(lambda); updatePosition(p, function, data); }
/** * Creates an instance. * * @param absoluteTol the absolute tolerance * @param relativeTol the relative tolerance * @param maxSteps the maximum steps * @param decomp the decomposition * @param algebra the instance of matrix algebra */ public ShermanMorrisonVectorRootFinder( double absoluteTol, double relativeTol, int maxSteps, Decomposition<?> decomp, MatrixAlgebra algebra) { super( absoluteTol, relativeTol, maxSteps, new InverseJacobianDirectionFunction(algebra), new InverseJacobianEstimateInitializationFunction(decomp), new ShermanMorrisonMatrixUpdateFunction(algebra)); }
private void quadraticBacktrack( DoubleArray p, Function<DoubleArray, DoubleArray> function, DataBundle data) { double lambda0 = data.getLambda0(); double g0 = data.getG0(); double lambda = Math.max(0.01 * lambda0, g0 * lambda0 * lambda0 / (data.getG1() + g0 * (2 * lambda0 - 1))); data.swapLambdaAndReplace(lambda); updatePosition(p, function, data); }
private void bisectBacktrack(DoubleArray p, Function<DoubleArray, DoubleArray> function, DataBundle data) { do { data.setLambda0(data.getLambda0() * 0.1); updatePosition(p, function, data); if (data.getLambda0() == 0.0) { throw new MathException("Failed to converge"); } } while (Double.isNaN(data.getG1()) || Double.isInfinite(data.getG1()) || Double.isNaN(data.getG2()) || Double.isInfinite(data.getG2())); }
@Test public void test() { assertLinear(DEFAULT, EPS); assertLinear(SV, EPS); assertFunction2D(SV, EPS); assertFunction3D(DEFAULT, EPS); assertFunction3D(DEFAULT_JACOBIAN_3D, EPS); assertFunction3D(SV, EPS); assertFunction3D(SV_JACOBIAN_3D, EPS); assertYieldCurveBootstrap(DEFAULT, EPS); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNull() { new JacobianDirectionFunction(null); }
/** * Obtains an instance of the Broyden root finder specifying the tolerances. * * @param absoluteTol the absolute tolerance * @param relativeTol the relative tolerance * @param maxSteps the maximum steps * @param decomposition the decomposition function * @return the root finder */ public static NewtonVectorRootFinder broyden( double absoluteTol, double relativeTol, int maxSteps, Decomposition<?> decomposition) { return new BroydenVectorRootFinder(absoluteTol, relativeTol, maxSteps, decomposition); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullMatrix() { UPDATE.getUpdatedMatrix(J, V, V, V, null); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullVector() { F.getUpdatedMatrix(new Function<DoubleArray, DoubleMatrix>() { @Override public DoubleMatrix apply(DoubleArray x) { return null; } }, null, null, null, null); }
@Override public DoubleArray getRoot(final Function<DoubleArray, DoubleArray> function, final DoubleArray x) { checkInputs(function, x); return null; }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullMatrix() { UPDATE.getUpdatedMatrix(J, V, V, V, null); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullVector() { ESTIMATE.getInitializedMatrix(J, null); }
@Override public DoubleArray findRoot(Function<DoubleArray, DoubleArray> function, DoubleArray startPosition) { VectorFieldFirstOrderDifferentiator jac = new VectorFieldFirstOrderDifferentiator(); return findRoot(function, jac.differentiate(function), startPosition); }
/** * Obtains an instance of the Broyden root finder. * <p> * This uses SV decomposition and standard tolerances. * * @return the root finder */ public static NewtonVectorRootFinder broyden() { return new BroydenVectorRootFinder(new SVDecompositionCommons()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDeltaX() { UPDATE.getUpdatedMatrix(J, V, null, V, M); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullFunction() { F.getUpdatedMatrix(null, null, null, null, null); }