Search in sources :

Example 26 with NumberContext

use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.

the class DecompositionProblems method testP20100512a.

@Test
public void testP20100512a() {
    final PhysicalStore<Double> tmpA = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.2845, 0.3597, 0.9544 }, { 0.3597, 0.6887, 0.0782 }, { 0.9544, 0.0782, 0.1140 } });
    final Eigenvalue<Double> tmpPrimitive = Eigenvalue.PRIMITIVE.make();
    tmpPrimitive.decompose(tmpA);
    TestUtils.assertEquals(tmpA, tmpPrimitive, new NumberContext(7, 6));
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) Test(org.junit.jupiter.api.Test)

Example 27 with NumberContext

use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.

the class DecompositionProblems method testP20111213tall.

/**
 * A user reported problems solving complex valued (overdetermined) equation systemes.
 */
@Test
public void testP20111213tall() {
    final int tmpDim = Uniform.randomInteger(2, 6);
    final PhysicalStore<ComplexNumber> original = MatrixUtils.makeRandomComplexStore(tmpDim + tmpDim, tmpDim);
    final PhysicalStore<ComplexNumber> identity = ComplexDenseStore.FACTORY.makeEye(tmpDim, tmpDim);
    MatrixStore<ComplexNumber> solution;
    @SuppressWarnings("unchecked") final MatrixDecomposition<ComplexNumber>[] tmpCmplxDecomps = new MatrixDecomposition[] { QR.COMPLEX.make(), SingularValue.COMPLEX.make(), Bidiagonal.COMPLEX.make() };
    for (final MatrixDecomposition<ComplexNumber> decomp : tmpCmplxDecomps) {
        decomp.decompose(original);
        if (MatrixDecompositionTests.DEBUG) {
            BasicLogger.debug(decomp.toString());
            BasicLogger.debug("Original", original);
            BasicLogger.debug("Recretaed", decomp.reconstruct());
        }
        TestUtils.assertEquals(decomp.toString(), original, decomp.reconstruct(), new NumberContext(7, 5));
        if ((decomp instanceof MatrixDecomposition.Solver<?>) && ((Solver<ComplexNumber>) decomp).isSolvable()) {
            solution = ((Solver<ComplexNumber>) decomp).getSolution(original);
            if (MatrixDecompositionTests.DEBUG) {
                BasicLogger.debug("Actual", solution);
            }
            TestUtils.assertEquals(decomp.toString(), identity, solution, new NumberContext(7, 6));
        }
    }
}
Also used : Solver(org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver) NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) Test(org.junit.jupiter.api.Test)

Example 28 with NumberContext

use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.

the class DegenerateLUCase method testComplex.

@Test
public void testComplex() {
    final NumberContext tmpEvalContext = new NumberContext(7, 4);
    final BasicMatrix tmpMtrxA = RationalMatrix.FACTORY.makeZero(SimpleEquationCase.getBody().countRows(), (int) SimpleEquationCase.getBody().countColumns()).mergeColumns(SimpleEquationCase.getBody()).mergeColumns(SimpleEquationCase.getBody());
    final LU<ComplexNumber> tmpComplexDecomp = LU.COMPLEX.make();
    tmpComplexDecomp.decompose(ComplexDenseStore.FACTORY.copy(tmpMtrxA));
    // System.out.println("A: " + tmpMtrxA.enforce(tmpEvalContext));
    // System.out.println("P: " + new ComplexMatrix(tmpComplexDecomp.getP()).enforce(tmpEvalContext));
    // System.out.println("L: " + new ComplexMatrix(tmpComplexDecomp.getL()).enforce(tmpEvalContext));
    // System.out.println("PL: " + new ComplexMatrix(tmpComplexDecomp.getP().multiplyRight(tmpComplexDecomp.getL())).enforce(tmpEvalContext));
    // System.out.println("D: " + new ComplexMatrix(tmpComplexDecomp.getD()).enforce(tmpEvalContext));
    // System.out.println("U: " + new ComplexMatrix(tmpComplexDecomp.getU()).enforce(tmpEvalContext));
    // System.out.println("DU: " + new ComplexMatrix(tmpComplexDecomp.getD().multiplyRight(tmpComplexDecomp.getU())).enforce(tmpEvalContext));
    TestUtils.assertEquals(ComplexDenseStore.FACTORY.copy(tmpMtrxA), tmpComplexDecomp, tmpEvalContext);
}
Also used : BasicMatrix(org.ojalgo.matrix.BasicMatrix) NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) Test(org.junit.jupiter.api.Test)

Example 29 with NumberContext

use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.

the class DegenerateLUCase method testRawPrimitive.

@Test
public void testRawPrimitive() {
    final NumberContext tmpEvalContext = new NumberContext(7, 4);
    final BasicMatrix tmpMtrxA = RationalMatrix.FACTORY.makeZero(SimpleEquationCase.getBody().countRows(), (int) SimpleEquationCase.getBody().countColumns()).mergeColumns(SimpleEquationCase.getBody()).mergeColumns(SimpleEquationCase.getBody());
    final LU<Double> tmpDoubleDecomp = LU.PRIMITIVE.make();
    tmpDoubleDecomp.decompose(PrimitiveDenseStore.FACTORY.copy(tmpMtrxA));
    // System.out.println("A: " + tmpMtrxA.enforce(tmpEvalContext));
    // System.out.println("P: " + new PrimitiveMatrix(tmpDoubleDecomp.getP()).enforce(tmpEvalContext));
    // System.out.println("L: " + new PrimitiveMatrix(tmpDoubleDecomp.getL()).enforce(tmpEvalContext));
    // System.out.println("PL: " + new PrimitiveMatrix(tmpDoubleDecomp.getP().multiplyRight(tmpDoubleDecomp.getL())).enforce(tmpEvalContext));
    // System.out.println("D: " + new PrimitiveMatrix(tmpDoubleDecomp.getD()).enforce(tmpEvalContext));
    // System.out.println("U: " + new PrimitiveMatrix(tmpDoubleDecomp.getU()).enforce(tmpEvalContext));
    // System.out.println("DU: " + new PrimitiveMatrix(tmpDoubleDecomp.getD().multiplyRight(tmpDoubleDecomp.getU())).enforce(tmpEvalContext));
    TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.copy(tmpMtrxA), tmpDoubleDecomp, tmpEvalContext);
}
Also used : BasicMatrix(org.ojalgo.matrix.BasicMatrix) NumberContext(org.ojalgo.type.context.NumberContext) Test(org.junit.jupiter.api.Test)

Example 30 with NumberContext

use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.

the class EigenvalueTest method testP20050125Case.

@Test
public void testP20050125Case() {
    final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.copy(P20050125Case.getProblematic());
    TestUtils.assertTrue(MatrixUtils.isHermitian(tmpOriginalMatrix));
    final Eigenvalue<Double>[] tmpDecomps = MatrixDecompositionTests.getEigenvaluePrimitiveSymmetric();
    for (Eigenvalue<Double> tmpDecomp : tmpDecomps) {
        tmpDecomp.decompose(tmpOriginalMatrix);
    }
    if (MatrixDecompositionTests.DEBUG) {
        BasicLogger.debug("Eigenvalues");
        for (Eigenvalue<Double> tmpDecomp : tmpDecomps) {
            BasicLogger.debug(tmpDecomp.getClass().getName() + ": " + tmpDecomp.getEigenvalues().toString());
        }
        BasicLogger.debug("D");
        for (Eigenvalue<Double> tmpDecomp : tmpDecomps) {
            BasicLogger.debug(tmpDecomp.getClass().getName() + ": " + PrimitiveDenseStore.FACTORY.copy(tmpDecomp.getD()));
        }
        BasicLogger.debug("V");
        for (Eigenvalue<Double> tmpDecomp : tmpDecomps) {
            BasicLogger.debug(tmpDecomp.getClass().getName() + ": " + PrimitiveDenseStore.FACTORY.copy(tmpDecomp.getV()));
        }
    }
    for (Eigenvalue<Double> tmpDecomp : tmpDecomps) {
        TestUtils.assertEquals(tmpOriginalMatrix, tmpDecomp, new NumberContext(7, 6));
    }
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) Test(org.junit.jupiter.api.Test)

Aggregations

NumberContext (org.ojalgo.type.context.NumberContext)91 Test (org.junit.jupiter.api.Test)63 ComplexNumber (org.ojalgo.scalar.ComplexNumber)16 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)15 BigDecimal (java.math.BigDecimal)14 BasicMatrix (org.ojalgo.matrix.BasicMatrix)13 BeforeEach (org.junit.jupiter.api.BeforeEach)12 Result (org.ojalgo.optimisation.Optimisation.Result)12 ExpressionsBasedModel (org.ojalgo.optimisation.ExpressionsBasedModel)9 Expression (org.ojalgo.optimisation.Expression)8 Variable (org.ojalgo.optimisation.Variable)8 PrimitiveMatrix (org.ojalgo.matrix.PrimitiveMatrix)6 Optimisation (org.ojalgo.optimisation.Optimisation)6 Uniform (org.ojalgo.random.Uniform)4 BigArray (org.ojalgo.array.BigArray)3 SimultaneousPrimitive (org.ojalgo.matrix.decomposition.HermitianEvD.SimultaneousPrimitive)3 MatrixStore (org.ojalgo.matrix.store.MatrixStore)3 Tag (org.junit.jupiter.api.Tag)2 RationalMatrix (org.ojalgo.matrix.RationalMatrix)2 Solver (org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver)2