本征库中的稀疏积A ^ T * A最优 [英] sparse sparse product A^T*A optim in Eigen lib

查看:104
本文介绍了本征库中的稀疏积A ^ T * A最优的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于多个相同的矩阵matA,例如

In the case of multiple of same matrix matA, like

matA.transpose()*matA, 

您不必计算所有结果乘积,因为结果矩阵是对称的(因此仅当m> n时),在我的特定情况下始终是对称的!正方形.

You don't have to compute all result product, because the result matrix is symmetric(so only if the m>n), in my specific case is always symmetric! square.

因此仅用于计算就足够了.前任.下三角部分,其余部分仅复制.....,因为第二和第三行的结果分别是col,类似于第三和第二行.....等等....

So its enough the compute only for. ex. lower triangular part and rest only copy..... because the results of the multiple 2nd and 3rd row, resp.col, is the same like 3rd and 2nd.....And etc....

所以我的问题是,存在方式如何告诉Eigen,只计算下部.并有选择地仅将产品保存到较低的trinaguler部分?

So my question is , exist way how to tell Eigen, to compute only lower part. and optionally save to only lower trinaguler part the product?

    DATA = SparseMatrix<double>((SparseMatrix<double>(matA.transpose()) * matA).pruned()).toDense();

推荐答案

根据文档,您可以使用以下方法评估矩阵的下三角:

According to the documentation, you can evaluate the lower triangle of a matrix with:

m1.triangularView<Eigen::Lower>() = m2 + m3;

或您的情况:

m1.triangularView<Eigen::Lower>() = matA.transpose()*matA;

(其中写着写到特定的三角形部分:(仅评估引用的三角形部分)").否则,在您写的那一行中 本征将计算整个稀疏矩阵matA.transpose()*matA.

(where it says "Writing to a specific triangular part: (only the referenced triangular part is evaluated)"). Otherwise, in the line you've written Eigen will calculate the entire sparse matrix matA.transpose()*matA.

关于保存生成的m1矩阵,与保存其类型的任何矩阵(Eigen::MatrixXtEigen::SparseMatrix<t>)相同.如果m1是稀疏的,则它仅是简单的matA.transpose()*matA的一半.如果m1是密集的,则它将是完整的方矩阵.

Regarding saving the resulting m1 matrix, it is the same as saving whatever type of matrix it is (Eigen::MatrixXt or Eigen::SparseMatrix<t>). If m1 is sparse, then it will be only half the size of a straightforward matA.transpose()*matA. If m1 is dense, then it will be the full square matrix.

这篇关于本征库中的稀疏积A ^ T * A最优的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆