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