简体   繁体   English

ojalgo 中的稀疏矩阵分解

[英]Sparse Matrix Decomposition in ojalgo

I want to do Least-Squares Adjustment with ojalgo.我想用 ojalgo 做最小二乘调整。 The problem is that my Designmatrix is very huge (more than 100kx100k) but very sparse.问题是我的 Designmatrix 非常大(超过 100kx100k)但非常稀疏。 To set up huge sparse matrices with ojalgo is no problem.用 ojalgo 建立巨大的稀疏矩阵是没有问题的。 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.当我从 SparseStore 矩阵创建 QR 对象时,似乎忽略了 SparseStore 矩阵信息,并且 qr 对象被初始化为 2D-DenseMatrix 对象。 Of course than my system runs out of memory.当然比我的系统内存不足。

Are there possibilites to do qr (or others) operations keeping the SparseStore.是否有可能执行 qr(或其他)操作来保持 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());

    }

}

Currently there are no matrix decompositions that preserve sparseness.目前没有保留稀疏性的矩阵分解。

Not sure what you need or exactly what's in ojAlgo.不确定您需要什么或 ojAlgo 中的确切内容。 Can you multiply by the transposed matrix and then use an iterative solver?您可以乘以转置矩阵,然后使用迭代求解器吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM