use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class EigenvalueTest method testRandomSymmetricValuesOnly.
@Test
public void testRandomSymmetricValuesOnly() {
final NumberContext evaluationContext = NumberContext.getGeneral(MathContext.DECIMAL32);
for (int dim = 1; dim < 10; dim++) {
final PrimitiveDenseStore matrix = MatrixUtils.makeSPD(dim);
for (final Eigenvalue<Double> decomp : MatrixDecompositionTests.getEigenvaluePrimitiveSymmetric()) {
decomp.decompose(matrix);
TestUtils.assertEquals(matrix, decomp, evaluationContext);
final Array1D<ComplexNumber> expected = decomp.getEigenvalues();
decomp.computeValuesOnly(matrix);
final Array1D<ComplexNumber> actual = decomp.getEigenvalues();
TestUtils.assertEquals(expected, actual, evaluationContext);
}
}
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class EigenvalueTest method testPaulsMathNote.
@Test
public void testPaulsMathNote() {
final double[][] tmpData = new double[][] { { 3, -9 }, { 4, -3 } };
final PrimitiveDenseStore tmpA = PrimitiveDenseStore.FACTORY.rows(tmpData);
final int tmpLength = tmpData.length;
final Array1D<ComplexNumber> tmpExpVals = Array1D.COMPLEX.makeZero(2);
tmpExpVals.set(0, ComplexNumber.of(0.0, THREE * SQRT.invoke(THREE)));
tmpExpVals.set(1, tmpExpVals.get(0).conjugate());
final Array2D<ComplexNumber> tmpExpVecs = Array2D.COMPLEX.makeZero(2, 2);
tmpExpVecs.set(0, 0, ComplexNumber.of(THREE, ZERO));
tmpExpVecs.set(1, 0, ComplexNumber.of(ONE, -SQRT.invoke(THREE)));
tmpExpVecs.set(0, 1, ComplexNumber.of(THREE, ZERO));
tmpExpVecs.set(1, 1, ComplexNumber.of(ONE, SQRT.invoke(THREE)));
final Eigenvalue<Double> tmpEvD = Eigenvalue.PRIMITIVE.make(tmpA, false);
tmpEvD.decompose(tmpA);
final MatrixStore<Double> tmpD = tmpEvD.getD();
final MatrixStore<Double> tmpV = tmpEvD.getV();
final Array1D<ComplexNumber> tmpValues = tmpEvD.getEigenvalues();
final MatrixStore<ComplexNumber> tmpVectors = tmpEvD.getEigenvectors();
TestUtils.assertEquals(tmpExpVals, tmpValues);
for (int j = 0; j < tmpLength; j++) {
final Array1D<ComplexNumber> tmpSliceColumn = tmpExpVecs.sliceColumn(0, j);
final Access1D<ComplexNumber> tmpActual = tmpVectors.sliceColumn(0, j);
final ComplexNumber tmpFactor = tmpActual.get(0).divide(tmpSliceColumn.get(0));
TestUtils.assertEquals(tmpSliceColumn.get(1).multiply(tmpFactor), tmpActual.get(1));
}
final ComplexDenseStore tmpCmplA = ComplexDenseStore.FACTORY.copy(tmpA);
final ComplexDenseStore tmpCmplD = ComplexDenseStore.FACTORY.copy(tmpD);
final ComplexDenseStore tmpCmplV = ComplexDenseStore.FACTORY.copy(tmpV);
final MatrixStore<ComplexNumber> tmpExp1 = tmpCmplA.multiply(tmpCmplV);
final MatrixStore<ComplexNumber> tmpAct1 = tmpCmplV.multiply(tmpCmplD);
TestUtils.assertEquals(tmpExp1, tmpAct1);
final ComplexDenseStore tmpComplexD = ComplexDenseStore.FACTORY.makeZero(tmpLength, tmpLength);
for (int j = 0; j < tmpLength; j++) {
tmpComplexD.set(j, j, tmpValues.get(j));
}
final MatrixStore<ComplexNumber> tmpExp2 = tmpCmplA.multiply(tmpVectors);
final MatrixStore<ComplexNumber> tmpAct2 = tmpVectors.multiply(tmpComplexD);
TestUtils.assertEquals(tmpExp2, tmpAct2);
tmpEvD.computeValuesOnly(tmpA);
final Array1D<ComplexNumber> tmpEigenvaluesOnly = tmpEvD.getEigenvalues();
TestUtils.assertEquals(tmpValues, tmpEigenvaluesOnly);
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class EigenvalueTest method testProblemFoundInTheWild.
/**
* A matrix that has been problematic for another library...
*/
@Test
public void testProblemFoundInTheWild() {
final PrimitiveDenseStore matrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1, 0, 0 }, { 0.01, 0, -1 }, { 0.01, 1, 0 } });
for (final Eigenvalue<Double> tmpEigenvalue : MatrixDecompositionTests.getEigenvaluePrimitiveGeneral()) {
tmpEigenvalue.decompose(matrix);
TestUtils.assertEquals(matrix, tmpEigenvalue, NumberContext.getGeneral(MathContext.DECIMAL64));
final Array1D<ComplexNumber> tmpValues = tmpEigenvalue.getEigenvalues();
tmpEigenvalue.computeValuesOnly(matrix);
final Array1D<ComplexNumber> tmpEigenvaluesOnly = tmpEigenvalue.getEigenvalues();
TestUtils.assertEquals(tmpValues, tmpEigenvaluesOnly);
}
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class ExtremeElementsCase method testInvertEvD_10_307_1.
@Test
public void testInvertEvD_10_307_1() {
final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.488828119167862, 0.42210916029401624, 0.3090339419657017, 0.31968488522727556, 0.32307269871880584, 0.46899580731023627, 0.12091920407255509, 0.03795763520492966, 0.17470282114825963, 0.3946701200769135 }, { 0.42210916029401624, 1.8635124366670595, 0.545906918558408, 0.5647217567560566, 0.570706312407284, 0.8284787565954789, 0.21360317145069477, 0.06705197344564522, 0.3086116630097931, 0.6971828004646068 }, { 0.3090339419657017, 0.545906918558408, 1.632193464017115, 0.41344326780911667, 0.417824671952357, 0.6065446573280001, 0.1563828419260192, 0.04908999287306165, 0.22594032001124298, 0.5104204536764679 }, { 0.31968488522727556, 0.5647217567560566, 0.41344326780911667, 1.6539821927009415, 0.43222511886101456, 0.6274493925480824, 0.16177262133291218, 0.05078189352797441, 0.23372741780909156, 0.528012240705021 }, { 0.32307269871880584, 0.570706312407284, 0.417824671952357, 0.43222511886101456, 1.660912672676802, 0.6340986950817811, 0.1634869828633994, 0.051320047166039655, 0.23620430969852588, 0.5336077726660703 }, { 0.46899580731023627, 0.8284787565954789, 0.6065446573280001, 0.6274493925480824, 0.6340986950817811, 1.959428864502749, 0.23732958500300408, 0.07449990991899043, 0.34289134104035285, 0.7746238203382216 }, { 0.12091920407255509, 0.21360317145069477, 0.1563828419260192, 0.16177262133291218, 0.1634869828633994, 0.23732958500300408, 1.2473654835536, 0.019207996469193075, 0.08840622324485663, 0.19971798116519177 }, { 0.03795763520492966, 0.06705197344564522, 0.04908999287306165, 0.05078189352797441, 0.051320047166039655, 0.07449990991899043, 0.019207996469193075, 1.0776502695252994, 0.027751515547194034, 0.06269328624082444 }, { 0.17470282114825963, 0.3086116630097931, 0.22594032001124298, 0.23372741780909156, 0.23620430969852588, 0.34289134104035285, 0.08840622324485663, 0.027751515547194034, 1.3573911039439759, 0.2885504830370714 }, { 0.3946701200769135, 0.6971828004646068, 0.5104204536764679, 0.528012240705021, 0.5336077726660703, 0.7746238203382216, 0.19971798116519177, 0.06269328624082444, 0.2885504830370714, 1.8073801497932753 } });
tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, 307)));
final RawEigenvalue.Symmetric tmpAlgorithm = new RawEigenvalue.Symmetric();
final NumberContext tmpContext = NumberContext.getGeneral(1, Integer.MIN_VALUE);
ExtremeElementsCase.performInvertTest(tmpOriginal, tmpAlgorithm, tmpContext);
}
use of org.ojalgo.matrix.store.PrimitiveDenseStore in project ojAlgo by optimatika.
the class ExtremeElementsCase method testInvertTask_2_155_1.
@Test
public void testInvertTask_2_155_1() {
final PrimitiveDenseStore tmpOriginal = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.7755876870972727, 0.5243083105843722 }, { 0.5243083105843722, 1.6760142267686806 } });
tmpOriginal.modifyAll(PrimitiveFunction.MULTIPLY.second(PrimitiveFunction.POWER.invoke(PrimitiveMath.TEN, 155)));
final InverterTask<Double> tmpAlgorithm = InverterTask.PRIMITIVE.make(tmpOriginal);
final NumberContext tmpContext = NumberContext.getGeneral(1, Integer.MIN_VALUE);
ExtremeElementsCase.performInvertTest(tmpOriginal, tmpAlgorithm, tmpContext);
}
Aggregations