Search in sources :

Example 36 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.

the class LUTest method testP20061119Case.

@Test
public void testP20061119Case() {
    final RationalMatrix tmpProblematic = P20061119Case.getProblematic();
    final LU<BigDecimal> tmpBig = LU.BIG.make();
    tmpBig.decompose(BigDenseStore.FACTORY.copy(tmpProblematic));
    final LU<ComplexNumber> tmpComplex = LU.COMPLEX.make();
    tmpComplex.decompose(ComplexDenseStore.FACTORY.copy(tmpProblematic));
    final LU<Double> tmpPrimitive = LU.PRIMITIVE.make();
    tmpPrimitive.decompose(PrimitiveDenseStore.FACTORY.copy(tmpProblematic));
    final LU<Double> tmpJama = new RawLU();
    tmpJama.decompose(PrimitiveDenseStore.FACTORY.copy(tmpProblematic));
    final NumberContext tmpPrintContext = NumberContext.getGeneral(20);
    if (MatrixDecompositionTests.DEBUG) {
        BasicLogger.debug("Big L", tmpBig.getL(), tmpPrintContext);
        BasicLogger.debug("Complex L", tmpComplex.getL(), tmpPrintContext);
        BasicLogger.debug("Primitive L", tmpPrimitive.getL(), tmpPrintContext);
        BasicLogger.debug("Jama L", tmpJama.getL(), tmpPrintContext);
    }
    if (MatrixDecompositionTests.DEBUG) {
        BasicLogger.debug("Big U", tmpBig.getU(), tmpPrintContext);
        BasicLogger.debug("Complex U", tmpComplex.getU(), tmpPrintContext);
        BasicLogger.debug("Primitive U", tmpPrimitive.getU(), tmpPrintContext);
        BasicLogger.debug("Jama U", tmpJama.getU(), tmpPrintContext);
    }
    final SingularValue<Double> tmpSVD = new RawSingularValue();
    tmpSVD.decompose(PrimitiveDenseStore.FACTORY.copy(tmpProblematic));
    TestUtils.assertEquals("LU.rank SVD vs Big", tmpSVD.getRank(), tmpBig.getRank());
    TestUtils.assertEquals("LU.rank SVD vs Complex", tmpSVD.getRank(), tmpComplex.getRank());
    TestUtils.assertEquals("LU.rank SVD vs Primitive", tmpSVD.getRank(), tmpPrimitive.getRank());
    TestUtils.assertEquals("LU.rank SVD vs Jama", tmpSVD.getRank(), tmpJama.getRank());
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) RationalMatrix(org.ojalgo.matrix.RationalMatrix) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 37 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.

the class QRTest method testP20030422Case.

@Test
public void testP20030422Case() {
    final RationalMatrix tmpOriginal = P20030422Case.getProblematic();
    final QR<BigDecimal> tmpBigDecomp = QR.BIG.make();
    final QR<ComplexNumber> tmpComplexDecomp = QR.COMPLEX.make();
    final QR<Double> tmpPrimitiveDecomp = QR.PRIMITIVE.make();
    tmpBigDecomp.decompose(BigDenseStore.FACTORY.copy(tmpOriginal));
    tmpComplexDecomp.decompose(ComplexDenseStore.FACTORY.copy(tmpOriginal));
    tmpPrimitiveDecomp.decompose(PrimitiveDenseStore.FACTORY.copy(tmpOriginal));
    final MatrixStore<BigDecimal> tmpBigQ = tmpBigDecomp.getQ();
    final MatrixStore<ComplexNumber> tmpComplexQ = tmpComplexDecomp.getQ();
    final MatrixStore<Double> tmpPrimitiveQ = tmpPrimitiveDecomp.getQ();
    if (MatrixDecompositionTests.DEBUG) {
        BasicLogger.debug("Big Q", tmpBigQ);
        BasicLogger.debug("Complex Q", tmpComplexQ);
        BasicLogger.debug("Primitive Q", tmpPrimitiveQ);
    }
    final MatrixStore<BigDecimal> tmpBigR = tmpBigDecomp.getR();
    final MatrixStore<ComplexNumber> tmpComplexR = tmpComplexDecomp.getR();
    final MatrixStore<Double> tmpPrimitiveR = tmpPrimitiveDecomp.getR();
    if (MatrixDecompositionTests.DEBUG) {
        BasicLogger.debug("Big R", tmpBigR);
        BasicLogger.debug("Complex R", tmpComplexR);
        BasicLogger.debug("Primitive R", tmpPrimitiveR);
    }
    TestUtils.assertEquals(BigDenseStore.FACTORY.copy(tmpOriginal), tmpBigDecomp, new NumberContext(7, 14));
    TestUtils.assertEquals(ComplexDenseStore.FACTORY.copy(tmpOriginal), tmpComplexDecomp, new NumberContext(7, 14));
    TestUtils.assertEquals(PrimitiveDenseStore.FACTORY.copy(tmpOriginal), tmpPrimitiveDecomp, new NumberContext(7, 14));
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) RationalMatrix(org.ojalgo.matrix.RationalMatrix) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 38 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber 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 39 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber 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 40 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber 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)

Aggregations

ComplexNumber (org.ojalgo.scalar.ComplexNumber)53 Test (org.junit.jupiter.api.Test)20 NumberContext (org.ojalgo.type.context.NumberContext)16 DivideAndConquer (org.ojalgo.concurrent.DivideAndConquer)7 ComplexArray (org.ojalgo.array.ComplexArray)5 BigDecimal (java.math.BigDecimal)4 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)4 BasicMatrix (org.ojalgo.matrix.BasicMatrix)3 Householder (org.ojalgo.matrix.transformation.Householder)3 Tag (org.junit.jupiter.api.Tag)2 RationalMatrix (org.ojalgo.matrix.RationalMatrix)2 Solver (org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver)2 ComplexDenseStore (org.ojalgo.matrix.store.ComplexDenseStore)2 Normal (org.ojalgo.random.Normal)2 Quaternion (org.ojalgo.scalar.Quaternion)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Uniform (org.ojalgo.random.Uniform)1