[英]Sparse Matrix Decomposition in ojalgo
我想用 ojalgo 做最小二乘调整。 问题是我的 Designmatrix 非常大(超过 100kx100k)但非常稀疏。 用 ojalgo 建立巨大的稀疏矩阵是没有问题的。 还要做一些基本的数学运算。 当我从 SparseStore 矩阵创建 QR 对象时,似乎忽略了 SparseStore 矩阵信息,并且 qr 对象被初始化为 2D-DenseMatrix 对象。 当然比我的系统内存不足。
是否有可能执行 qr(或其他)操作来保持 SparseStore。
谢谢你的帮助,
最好的,罗尼
源代码:
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());
}
}
目前没有保留稀疏性的矩阵分解。
不确定您需要什么或 ojAlgo 中的确切内容。 您可以乘以转置矩阵,然后使用迭代求解器吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.