Search in sources :

Example 11 with RawStore

use of org.ojalgo.matrix.store.RawStore in project ojAlgo by optimatika.

the class LDLTest method testWikipediaCase.

@Test
public void testWikipediaCase() {
    final RawStore tmpA = new RawStore(new double[][] { { 4, 12, -16 }, { 12, 37, -43 }, { -16, -43, 98 } });
    final RawStore tmpL = new RawStore(new double[][] { { 1, 0, 0 }, { 3, 1, 0 }, { -4, 5, 1 } });
    final RawStore tmpD = new RawStore(new double[][] { { 4, 0, 0 }, { 0, 1, 0 }, { 0, 0, 9 } });
    final RawStore tmpReconstructed = tmpL.multiply(tmpD.multiply(tmpL.transpose()));
    TestUtils.assertEquals(tmpA, tmpReconstructed);
    final RawLDL tmpRawLDL = new RawLDL();
    tmpRawLDL.decompose(tmpA);
    final LDL<Double> tmpPrimLDL = new LDLDecomposition.Primitive();
    tmpPrimLDL.decompose(tmpA);
    // BasicLogger.debug(tmpL);
    // BasicLogger.debug(tmpD);
    // BasicLogger.debug("RAW L", tmpRawLDL.getL());
    // BasicLogger.debug("RAW D", tmpRawLDL.getD());
    // 
    // BasicLogger.debug("PRIM L", tmpPrimLDL.getL());
    // BasicLogger.debug("PRIM D", tmpPrimLDL.getD());
    TestUtils.assertEquals(tmpL, tmpRawLDL.getL());
    TestUtils.assertEquals(tmpD, tmpRawLDL.getD());
    final MatrixStore<Double> tmpRawInv = tmpRawLDL.getSolution(MatrixStore.PRIMITIVE.makeIdentity(3).get());
    final MatrixStore<Double> tmpPrimInv = tmpPrimLDL.getSolution(MatrixStore.PRIMITIVE.makeIdentity(3).get());
    tmpRawInv.multiply(tmpA);
    tmpPrimInv.multiply(tmpA);
    tmpRawLDL.decompose(tmpRawInv);
    final MatrixStore<Double> tmpInverse2 = tmpRawLDL.getSolution(MatrixStore.PRIMITIVE.makeIdentity(3).get());
    TestUtils.assertEquals(tmpA, tmpInverse2);
}
Also used : RawStore(org.ojalgo.matrix.store.RawStore) Test(org.junit.jupiter.api.Test)

Example 12 with RawStore

use of org.ojalgo.matrix.store.RawStore in project ojAlgo by optimatika.

the class RawCholesky method doGetInverse.

private MatrixStore<Double> doGetInverse(final PhysicalStore<Double> preallocated) {
    final RawStore tmpBody = this.getRawInPlaceStore();
    preallocated.substituteForwards(tmpBody, false, false, true);
    preallocated.substituteBackwards(tmpBody, false, true, true);
    return preallocated.logical().hermitian(false).get();
}
Also used : RawStore(org.ojalgo.matrix.store.RawStore)

Example 13 with RawStore

use of org.ojalgo.matrix.store.RawStore in project ojAlgo by optimatika.

the class RawLDL method doGetInverse.

private MatrixStore<Double> doGetInverse(final PhysicalStore<Double> preallocated) {
    preallocated.fillAll(ZERO);
    preallocated.fillDiagonal(0L, 0L, ONE);
    final RawStore tmpBody = this.getRawInPlaceStore();
    preallocated.substituteForwards(tmpBody, true, false, true);
    for (int i = 0; i < preallocated.countRows(); i++) {
        preallocated.modifyRow(i, 0, DIVIDE.second(tmpBody.doubleValue(i, i)));
    }
    preallocated.substituteBackwards(tmpBody, true, true, true);
    return preallocated;
}
Also used : RawStore(org.ojalgo.matrix.store.RawStore)

Example 14 with RawStore

use of org.ojalgo.matrix.store.RawStore in project ojAlgo by optimatika.

the class RawLDL method getL.

public MatrixStore<Double> getL() {
    final RawStore tmpRawInPlaceStore = this.getRawInPlaceStore();
    final LogicalBuilder<Double> tmpBuilder = tmpRawInPlaceStore.logical();
    final LogicalBuilder<Double> tmpTriangular = tmpBuilder.triangular(false, true);
    return tmpTriangular.get();
}
Also used : RawStore(org.ojalgo.matrix.store.RawStore)

Example 15 with RawStore

use of org.ojalgo.matrix.store.RawStore in project ojAlgo by optimatika.

the class RawQR method getQ.

/**
 * Generate and return the (economy-sized) orthogonal factor
 *
 * @return Q
 */
public RawStore getQ() {
    final int m = this.getRowDim();
    final int n = this.getColDim();
    final double[][] tmpData = this.getRawInPlaceData();
    final RawStore retVal = new RawStore(m, n);
    final double[][] retData = retVal.data;
    for (int k = n - 1; k >= 0; k--) {
        for (int i = 0; i < m; i++) {
            retData[i][k] = ZERO;
        }
        retData[k][k] = ONE;
        for (int j = k; j < n; j++) {
            if (tmpData[k][k] != 0) {
                double s = ZERO;
                for (int i = k; i < m; i++) {
                    s += tmpData[k][i] * retData[i][j];
                }
                s = -s / tmpData[k][k];
                for (int i = k; i < m; i++) {
                    retData[i][j] += s * tmpData[k][i];
                }
            }
        }
    }
    return retVal;
}
Also used : RawStore(org.ojalgo.matrix.store.RawStore)

Aggregations

RawStore (org.ojalgo.matrix.store.RawStore)17 Test (org.junit.jupiter.api.Test)2 Optimisation (org.ojalgo.optimisation.Optimisation)2 Result (org.ojalgo.optimisation.Optimisation.Result)1 Builder (org.ojalgo.optimisation.convex.ConvexSolver.Builder)1