1

I want to do Least-Squares Adjustment with ojalgo. The problem is that my Designmatrix is very huge (more than 100kx100k) but very sparse. To set up huge sparse matrices with ojalgo is no problem. Also do some basic mathematical operations. When i create an QR-Object out of a SparseStore Matrix, it seems that the SparseStore matrix information is ignored and the qr-object gets initialized as a 2D-DenseMatrix object. Of course than my system runs out of memory.

Are there possibilites to do qr (or others) operations keeping the SparseStore.

Thanks for your help,

Best, Ronnie

Source-Code:

package matrixTest;
import static org.ojalgo.type.CalendarDateUnit.*;

import java.util.Random;

import org.ojalgo.OjAlgoUtils;
import org.ojalgo.array.LongToNumberMap;
import org.ojalgo.array.Primitive64Array;
import org.ojalgo.array.SparseArray;
import org.ojalgo.matrix.decomposition.QR;
import org.ojalgo.matrix.store.MatrixStore;
import org.ojalgo.matrix.store.SparseStore;
import org.ojalgo.matrix.task.iterative.ConjugateGradientSolver;
import org.ojalgo.netio.BasicLogger;
import org.ojalgo.series.BasicSeries;
import org.ojalgo.type.Stopwatch;

/**
 * Example use of SparseStore and other special MatrixStore implementations.
 *
 * @see https://www.ojalgo.org/2020/09/sparse-and-special-structure-matrices/
 * @see https://github.com/optimatika/ojAlgo/wiki/Sparse-Matrices
 */
public class SparseMatrices {

    private static String NON_ZEROS = "{} non-zeroes out of {} matrix elements calculated in {}";
    private static Random RANDOM = new Random();

    public static void main(final String[] args) {

        BasicLogger.debug();
        BasicLogger.debug(SparseMatrices.class);
        BasicLogger.debug(OjAlgoUtils.getTitle());
        BasicLogger.debug(OjAlgoUtils.getDate());
        BasicLogger.debug();

        int dim = 100_000;

        SparseStore<Double> mtrxD = SparseStore.PRIMITIVE64.make(dim, dim);

        for (int j = 0; j < dim; j++) {
            double val = RANDOM.nextDouble();
            mtrxD.set(j, j, val);
        } // Each column of B contains 1 non-zero element at random row

        QR<Double> decompQR = QR.PRIMITIVE.make(mtrxD);

        
        stopwatch.reset();
        decompQR.compute(mtrxD);
        BasicLogger.debug("Sparse Identity decomposed (QR) in {}", stopwatch.stop());

    }

}

1 Answers1

0

Currently there are no matrix decompositions that preserve sparseness.

Not sure what you need or exactly what's in ojAlgo. Can you multiply by the transposed matrix and then use an iterative solver?

apete
  • 1,250
  • 1
  • 10
  • 16
  • Should be also possible. But then i think i have to calculate the inverse of the matrix first. And as is understand, this is also not possible in ojAlgo or? thanks for your answer! – RonnieHerbert Oct 19 '20 at 09:05
  • I thought maybe the iterative solvers could help you with that. Look in the org.ojalgo.matrix.task.iterative package, and the org.ojalgo.optimisation.convex.IterativeASS class has a nested type MyIterativeSolver that is a sparse implementation/usage. – apete Oct 19 '20 at 10:26