首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从SuiteSparseQR_factorization对象中查找(Q,R)?

如何从SuiteSparseQR_factorization对象中查找(Q,R)?
EN

Stack Overflow用户
提问于 2019-09-18 03:17:35
回答 1查看 75关注 0票数 0

在SuiteSparse的C++接口中,我可以使用

代码语言:javascript
复制
SuiteSparseQR_factorization <double> *QR;
QR = SuiteSparseQR_factorize(A) ;

计算矩阵A的QR分解,以便我可以重用QR进行进一步计算。但是我想知道我能不能直接从这个QR对象中得到真正的Q,R?

EN

回答 1

Stack Overflow用户

发布于 2020-06-07 18:14:23

SuiteSparse很棒,但它的界面可能会让人感到困惑。不幸的是,涉及SuiteSparseQR_factorization结构的方法似乎是最方便的,但在实践中对我来说效果并不是很好。例如,先使用SuiteSparseQR_factorize,然后使用带有稀疏矩阵输入参数的SuiteSparseQR_qmult,实际上会首先将其转换为密集矩阵,这似乎完全没有必要!

相反,您可以使用

代码语言:javascript
复制
template <typename Entry> SuiteSparse_long SuiteSparseQR
(
    // inputs, not modified
    int ordering,           // all, except 3:given treated as 0:fixed
    double tol,             // only accept singletons above tol

    SuiteSparse_long econ,  // number of rows of C and R to return; a value
                            // less than the rank r of A is treated as r, and
                            // a value greater than m is treated as m.

    int getCTX,             // if 0: return Z = C of size econ-by-bncols
                            // if 1: return Z = C' of size bncols-by-econ
                            // if 2: return Z = X of size econ-by-bncols

    cholmod_sparse *A,      // m-by-n sparse matrix

    // B is either sparse or dense.  If Bsparse is non-NULL, B is sparse and
    // Bdense is ignored.  If Bsparse is NULL and Bdense is non-NULL, then B is
    // dense.  B is not present if both are NULL.
    cholmod_sparse *Bsparse,
    cholmod_dense *Bdense,

    // output arrays, neither allocated nor defined on input.

    // Z is the matrix C, C', or X
    cholmod_sparse **Zsparse,
    cholmod_dense  **Zdense,
    cholmod_sparse **R,     // the R factor
    SuiteSparse_long **E,   // size n; fill-reducing ordering of A.
    cholmod_sparse **H,     // the Householder vectors (m-by-nh)
    SuiteSparse_long **HPinv,// size m; row permutation for H
    cholmod_dense **HTau,   // size nh, Householder coefficients

    // workspace and parameters
    cholmod_common *cc
) ;

此方法将执行因子分解,然后可选地输出(除其他外) R、矩阵乘积Z= Q^T *B(或其转置-- B^T * Q)或线性系统的解。要得到Q,请将B定义为单位矩阵。下面是一个获取Q和R的示例。

代码语言:javascript
复制
cholmod_common Common, * cc;
cc = &Common;
cholmod_l_start(cc);
cholmod_sparse *A;//assume you have already defined this
int ordering = SPQR_ORDERING_BEST;
double tol = 0;
Long econ = A->nrow;
int getCTX = 1;// Z = (Q^T * B)^T = B^T * Q
cholmod_sparse *B = cholmod_l_speye(A->nrow, A->nrow, CHOLMOD_REAL, cc);//the identity matrix
cholmod_sparse *Q, *R;//output pointers to the Q and R sparse matrices

SuiteSparseQR<double>(ordering, tol, econ, getCTX, A, B, NULL, &Q, NULL, &R, NULL, NULL, NULL, NULL, cc);

如果您希望任何其他输出在不使用显式形成的Q和/或R的情况下执行后续操作,则需要用NULL替换额外的指针,然后调用SuiteSparseQR_qmult

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57980714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档