/** * Creates an instance. * * @param absoluteTol the absolute tolerance * @param relativeTol the relative tolerance * @param maxSteps the maximum steps */ public BroydenVectorRootFinder(double absoluteTol, double relativeTol, int maxSteps) { this(absoluteTol, relativeTol, maxSteps, new LUDecompositionCommons()); }
/** * @return Returns the tridiagonal matrix as a {@link DoubleMatrix} */ public DoubleMatrix toDoubleMatrix() { if (_matrix == null) { calMatrix(); } return _matrix; }
@Override protected double[] matrixEqnSolver(final double[][] doubMat, final double[] doubVec) { final int sizeM1 = doubMat.length - 1; final double[] a = new double[sizeM1]; final double[] b = new double[sizeM1 + 1]; final double[] c = new double[sizeM1]; for (int i = 0; i < sizeM1; ++i) { a[i] = doubMat[i][i + 1]; b[i] = doubMat[i][i]; c[i] = doubMat[i + 1][i]; } b[sizeM1] = doubMat[sizeM1][sizeM1]; final TridiagonalMatrix m = new TridiagonalMatrix(b, a, c); return TridiagonalSolver.solvTriDag(m, doubVec); }
/** * Tests A = L L^T. */ public void recoverOrginal() { final CholeskyDecompositionResult result = CDOG.apply(A3); final DoubleMatrix a = (DoubleMatrix) ALGEBRA.multiply(result.getL(), result.getLT()); checkEquals(A3, a); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongC() { new TridiagonalMatrix(A, B, new double[] {1, 2, 3, 4, 5, 6, 7 }); }
@Override public SVDecompositionResult apply(DoubleMatrix x) { ArgChecker.notNull(x, "x"); MatrixValidate.notNaNOrInfinite(x); RealMatrix commonsMatrix = CommonsMathWrapper.wrap(x); SingularValueDecomposition svd = new SingularValueDecomposition(commonsMatrix); return new SVDecompositionCommonsResult(svd); }
/** * Tests solve Ax = b from A and b. */ public void solveVector() { final CholeskyDecompositionResult result = CDOG.apply(A5); double[] b = new double[] {1.0, 2.0, 3.0, 4.0, -1.0 }; double[] x = result.solve(b); DoubleArray ax = (DoubleArray) ALGEBRA.multiply(A5, DoubleArray.copyOf(x)); ArrayAsserts.assertArrayEquals("Cholesky decomposition OpenGamma - solve", b, ax.toArray(), 1.0E-10); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testThrowOnNull() { new SVDecompositionCommonsResult(null); }
/** * Solves the system Ax = y for the unknown vector x, where A is a tridiagonal matrix and y is a vector. * This takes order n operations where n is the size of the system * (number of linear equations), as opposed to order n^3 for the general problem. * @param aM tridiagonal matrix * @param b known vector (must be same length as rows/columns of matrix) * @return vector with same length as y */ public static DoubleArray solvTriDag(TridiagonalMatrix aM, DoubleArray b) { return DoubleArray.copyOf(solvTriDag(aM, b.toArray())); }
/** * 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()); }
/** * {@inheritDoc} */ @Override public CholeskyDecompositionResult apply(DoubleMatrix x) { return evaluate(x, DEFAULT_SYMMETRY_THRESHOLD, DEFAULT_POSITIVITY_THRESHOLD); }
private DirectIborCapletFloorletVolatilityCalibrator( VolatilityIborCapFloorLegPricer pricer, double epsilon, ReferenceData referenceData) { super(pricer, referenceData); this.solver = new NonLinearLeastSquareWithPenalty(new CholeskyDecompositionCommons(), epsilon); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testBadName() { DecompositionFactory.getDecomposition("X"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullObjectMatrix() { CDOG.apply((DoubleMatrix) null); }
/** * Compare results with Common decomposition */ public void compareCommon() { final CholeskyDecompositionResult resultOG = CDOG.apply(A3); final CholeskyDecompositionResult resultC = CDC.apply(A3); checkEquals(resultC.getL(), resultOG.getL()); checkEquals(ALGEBRA.getTranspose(resultC.getL()), resultOG.getLT()); assertEquals("Determinant", resultC.getDeterminant(), resultOG.getDeterminant(), 1.0E-10); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullA() { new TridiagonalMatrix(null, B, C); }
/** * Creates an instance. * * @param absoluteTol the absolute tolerance * @param relativeTol the relative tolerance * @param maxSteps the maximum steps */ public ShermanMorrisonVectorRootFinder(double absoluteTol, double relativeTol, int maxSteps) { this(absoluteTol, relativeTol, maxSteps, new LUDecompositionCommons()); }
/** * Tests solve AX = B from A and B. */ public void solveMatrix() { final CholeskyDecompositionResult result = CDOG.apply(A5); double[][] b = new double[][] { {1.0, 2.0 }, {2.0, 3.0 }, {3.0, 4.0 }, {4.0, -2.0 }, {-1.0, -1.0 } }; DoubleMatrix x = result.solve(DoubleMatrix.copyOf(b)); DoubleMatrix ax = (DoubleMatrix) ALGEBRA.multiply(A5, x); ArrayAsserts.assertArrayEquals("Cholesky decomposition OpenGamma - solve", b[0], ax.rowArray(0), 1.0E-10); ArrayAsserts.assertArrayEquals("Cholesky decomposition OpenGamma - solve", b[1], ax.rowArray(1), 1.0E-10); }
/** * Creates an instance. */ public GeneralizedLeastSquare() { _decomposition = new SVDecompositionCommons(); _algebra = new CommonsMatrixAlgebra(); }
/** * Creates an instance. * * @param absoluteTol the absolute tolerance * @param relativeTol the relative tolerance * @param maxSteps the maximum steps */ public NewtonDefaultVectorRootFinder(double absoluteTol, double relativeTol, int maxSteps) { this(absoluteTol, relativeTol, maxSteps, new LUDecompositionCommons()); }