use of org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver in project ojAlgo by optimatika.
the class DecompositionProblems method testP20111213square.
/**
* A user reported problems solving complex valued (overdetermined) equation systemes.
*/
@Test
@Tag("unstable")
public void testP20111213square() {
final int tmpDim = Uniform.randomInteger(2, 6);
final PhysicalStore<ComplexNumber> tmpSquare = MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim);
final MatrixStore<ComplexNumber> tmpHermitian = tmpSquare.conjugate().multiply(tmpSquare);
final PhysicalStore<ComplexNumber> tmpExpected = ComplexDenseStore.FACTORY.makeEye(tmpDim, tmpDim);
MatrixStore<ComplexNumber> tmpActual;
@SuppressWarnings("unchecked") final MatrixDecomposition<ComplexNumber>[] tmpCmplxDecomps = new MatrixDecomposition[] { Bidiagonal.COMPLEX.make(), Cholesky.COMPLEX.make(), Eigenvalue.COMPLEX.make(MatrixDecomposition.TYPICAL, true), /*
* , HessenbergDecomposition. makeComplex()
*/
LU.COMPLEX.make(), QR.COMPLEX.make(), SingularValue.COMPLEX.make() /*
* , TridiagonalDecomposition . makeComplex ( )
*/
};
for (final MatrixDecomposition<ComplexNumber> tmpDecomposition : tmpCmplxDecomps) {
tmpDecomposition.decompose(tmpHermitian);
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug(tmpDecomposition.toString());
BasicLogger.debug("Original", tmpHermitian);
BasicLogger.debug("Recretaed", tmpDecomposition.reconstruct());
}
TestUtils.assertEquals("Recreation: " + tmpDecomposition.toString(), tmpHermitian, tmpDecomposition.reconstruct(), new NumberContext(8, 5));
if ((tmpDecomposition instanceof MatrixDecomposition.Solver<?>) && ((Solver) tmpDecomposition).isSolvable()) {
tmpActual = ((Solver) tmpDecomposition).getSolution(tmpHermitian);
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Actual", tmpActual);
}
TestUtils.assertEquals("Solving: " + tmpDecomposition.toString(), tmpExpected, tmpActual, new NumberContext(7, 6));
}
}
}
use of org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver 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));
}
}
}
Aggregations