Search in sources :

Example 76 with NumberContext

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

the class SchurTest method testDiagonalCase.

@Test
public void testDiagonalCase() {
    final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.0, 3.0, 2.0, 1.0 }, { 0.0, 3.0, 2.0, 1.0 }, { 0.0, 0.0, 2.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 } });
    final ComplexNumber tmp00 = ComplexNumber.valueOf(4.0);
    final ComplexNumber tmp11 = ComplexNumber.valueOf(3.0);
    final ComplexNumber tmp22 = ComplexNumber.valueOf(2.0);
    final ComplexNumber tmp33 = ComplexNumber.valueOf(1.0);
    final Array1D<ComplexNumber> tmpExpectedDiagonal = Array1D.COMPLEX.copy(new ComplexNumber[] { tmp00, tmp11, tmp22, tmp33 });
    SchurTest.doTest(tmpOriginalMatrix, tmpExpectedDiagonal, new NumberContext(7, 6));
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) Test(org.junit.jupiter.api.Test)

Example 77 with NumberContext

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

the class SchurTest method testPlanetMathCase.

/**
 * http://planetmath.org/encyclopedia/AnExampleForSchurDecomposition.html
 */
@Test
public void testPlanetMathCase() {
    final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 5, 7 }, { -2, -4 } });
    PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1 / PrimitiveMath.SQRT_TWO, 1 / PrimitiveMath.SQRT_TWO }, { -1 / PrimitiveMath.SQRT_TWO, 1 / PrimitiveMath.SQRT_TWO } });
    final double tmp00 = -2;
    final double tmp11 = 3.0;
    final Array1D<ComplexNumber> tmpExpectedDiagonal = Array1D.COMPLEX.copy(new ComplexNumber[] { ComplexNumber.valueOf(tmp00), ComplexNumber.valueOf(tmp11) });
    PrimitiveDenseStore.FACTORY.rows(new double[][] { { tmp00, 9 }, { 0.0, tmp11 } });
    SchurTest.doTest(tmpOriginalMatrix, tmpExpectedDiagonal, new NumberContext(7, 5));
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) Test(org.junit.jupiter.api.Test)

Example 78 with NumberContext

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

the class TridiagonalizeCase method testRandomBigComplexPrimitive.

@Test
@Tag("unstable")
public void testRandomBigComplexPrimitive() {
    BasicMatrix tmpSymmetricRandoml = PrimitiveMatrix.FACTORY.makeFilled(9, 9, new Normal());
    tmpSymmetricRandoml = tmpSymmetricRandoml.add(tmpSymmetricRandoml.transpose());
    final MatrixStore<BigDecimal> tmpBigA = BigDenseStore.FACTORY.copy(tmpSymmetricRandoml);
    final MatrixStore<ComplexNumber> tmpComplexA = ComplexDenseStore.FACTORY.copy(tmpSymmetricRandoml);
    final MatrixStore<Double> tmpPrimitiveA = PrimitiveDenseStore.FACTORY.copy(tmpSymmetricRandoml);
    final Tridiagonal<BigDecimal> tmpBigDecomp = Tridiagonal.BIG.make();
    final Tridiagonal<ComplexNumber> tmpComplexDecomp = Tridiagonal.COMPLEX.make();
    final Tridiagonal<Double> tmpPrimitiveDecomp = Tridiagonal.PRIMITIVE.make();
    tmpBigDecomp.decompose(tmpBigA);
    tmpComplexDecomp.decompose(tmpComplexA);
    tmpPrimitiveDecomp.decompose(tmpPrimitiveA);
    TestUtils.assertEquals(tmpBigA, tmpBigDecomp, new NumberContext(7, 14));
    TestUtils.assertEquals(tmpComplexA, tmpComplexDecomp, new NumberContext(7, 14));
    TestUtils.assertEquals(tmpPrimitiveA, tmpPrimitiveDecomp, new NumberContext(7, 14));
    if (MatrixDecompositionTests.DEBUG) {
        BasicLogger.debug("Big Q", tmpBigDecomp.getQ());
        BasicLogger.debug("Complex Q", tmpComplexDecomp.getQ());
        BasicLogger.debug("Primitive Q", tmpPrimitiveDecomp.getQ());
        BasicLogger.debug("Big D", tmpBigDecomp.getD());
        BasicLogger.debug("Complex D", tmpComplexDecomp.getD());
        BasicLogger.debug("Primitive D", tmpPrimitiveDecomp.getD());
    }
    TestUtils.assertEquals(tmpPrimitiveDecomp.getD(), PrimitiveDenseStore.FACTORY.copy(tmpBigDecomp.getD()), new NumberContext(7, 14));
    // TODO        JUnitUtils.assertEquals(tmpPrimitiveDecomp.getD(), PrimitiveDenseStore.FACTORY.copy(tmpComplexDecomp.getD()), JUnitUtils.EQUALS);
    TestUtils.assertEquals(tmpPrimitiveDecomp.getQ(), PrimitiveDenseStore.FACTORY.copy(tmpBigDecomp.getQ()), new NumberContext(7, 14));
// TODO        JUnitUtils.assertEquals(tmpPrimitiveDecomp.getQ(), PrimitiveDenseStore.FACTORY.copy(tmpComplexDecomp.getQ()), JUnitUtils.EQUALS);
}
Also used : BasicMatrix(org.ojalgo.matrix.BasicMatrix) NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) Normal(org.ojalgo.random.Normal) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 79 with NumberContext

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

the class StoreProblems method testP20110223.

/**
 * Peter Abeles reported a problem with ojAlgo his benchmark's C=A*BT test. The problem turned out be that
 * fillByMultiplying did not reset the destination matrix elements when doung "multiply right".
 */
@Test
public void testP20110223() {
    final int tmpDim = 9;
    final PhysicalStore<Double> tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
    final PhysicalStore<Double> tmpMtrxB = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
    final PhysicalStore<Double> tmpMtrxC = PrimitiveDenseStore.FACTORY.makeZero(tmpDim, tmpDim);
    PhysicalStore<Double> tmpExpected;
    PhysicalStore<Double> tmpActual;
    tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB);
    tmpExpected = tmpMtrxC.copy();
    tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB);
    tmpActual = tmpMtrxC.copy();
    TestUtils.assertEquals(tmpExpected, tmpActual, new NumberContext(7, 6));
    tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB.logical().transpose().get());
    tmpExpected = tmpMtrxC.copy();
    tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB.logical().transpose().get());
    tmpActual = tmpMtrxC.copy();
    TestUtils.assertEquals(tmpExpected, tmpActual, new NumberContext(7, 6));
    tmpMtrxC.fillByMultiplying(tmpMtrxA.logical().transpose().get(), tmpMtrxB);
    tmpExpected = tmpMtrxC.copy();
    tmpMtrxC.fillByMultiplying(tmpMtrxA.logical().transpose().get(), tmpMtrxB);
    tmpActual = tmpMtrxC.copy();
    TestUtils.assertEquals(tmpExpected, tmpActual, new NumberContext(7, 6));
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) Test(org.junit.jupiter.api.Test)

Example 80 with NumberContext

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

the class SimpleEigenvalueCase method setUp.

@BeforeEach
@Override
public void setUp() {
    DEFINITION = new NumberContext(7, 14);
    EVALUATION = new NumberContext(7, 3);
    myBigAA = SimpleEigenvalueCase.getOriginal();
    myBigAX = SimpleEigenvalueCase.getMatrixV();
    myBigAB = SimpleEigenvalueCase.getMatrixV().multiply(SimpleEigenvalueCase.getMatrixD());
    myBigI = BasicMatrixTest.getIdentity(myBigAA.countRows(), myBigAA.countColumns(), DEFINITION);
    myBigSafe = BasicMatrixTest.getSafe(myBigAA.countRows(), myBigAA.countColumns(), DEFINITION);
    super.setUp();
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

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