我想用ojalgo做最小二乘平差。问题是我的设计矩阵非常大(超过100kx100k),但非常稀疏。用ojalgo建立巨大的稀疏矩阵是没有问题的。还要做一些基本的数学运算。当我从SparseStore矩阵创建qr-对象时,似乎忽略了SparseStore矩阵信息,并且qr-对象被初始化为2D-DenseMatrix对象。当然比我的系统耗尽内存更重要。
是否有可能在保留SparseStore的情况下执行qr (或其他)操作。
谢谢你的帮忙,
最好的,罗尼
源代码:
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());
}
}发布于 2020-10-19 15:34:31
目前还没有保留稀疏性的矩阵分解。
不确定您需要什么,也不确定ojAlgo中到底有什么。你能乘以转置后的矩阵,然后使用迭代求解器吗?
https://stackoverflow.com/questions/64422681
复制相似问题