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());
}
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));
}
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));
}
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));
}
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);
}
Aggregations