Eigen's LeastSquaresConjugateGradient solver: using Incomplete Cholesky preconditioner and specifying coefficient starting values

↘锁芯ラ 提交于 2019-12-08 07:26:23

问题


To solve a rectangular sparse linear system of equations I would like to use Eigen's LeastSquaresConjugateGradient. Aside from the default Jacobi and Identity preconditioner I was wondering though if it is possible to also use Incomplete Cholesky as a preconditioner within LeastSquaresConjugateGradient?

The Rcpp code I have and which uses the default Jacobi ([LeastSquareDiagonalPreconditioner) preconditioner is:

library(inline)
library(RcppEigen)

solve_sparse_lsconjgrad <- cxxfunction( signature(input_ = "list"), '
    using Eigen::VectorXd;
    using Eigen::MatrixXd;
    using Eigen::Lower;
    using Eigen::Map;
    using Eigen::SparseMatrix;
    using Eigen::IdentityPreconditioner;
    // using Eigen::IncompleteCholesky;
    using Eigen::LeastSquaresConjugateGradient;
    List input(input_);
    const Map<SparseMatrix<double> > m1 = input[0]; // X
    const Map<VectorXd>              v1 = input[1]; // y
    const Map<VectorXd>              x = input[2]; // initial coefficient guess
    SparseMatrix<double>             m2(m1.cols(), m1.cols());
    m2.selfadjointView<Lower>().rankUpdate(m1.adjoint());
    Eigen::LeastSquaresConjugateGradient<SparseMatrix<double> > solver; 
    solver.setMaxIterations(100);
    solver.setTolerance(1E-20);
    solver.compute(m1);
    VectorXd                        res = solver.solveWithGuess(v1, x); 
    return List::create(_["res"]   = res,
                        _["rows"]  = double(solver.rows()),
                        _["cols"]  = double(solver.cols()));
',
                                      plugin = "RcppEigen")

Usage is

solve_sparse_lsconjgrad(list(X, y, coefficient_starting_values))

But how should I modify this to use IncompleteCholesky as a preconditioner instead? In another stack overflow question I saw that one needs to define

typedef LeastSquaresConjugateGradient<SparseMatrix<double>, IncompleteCholesky<double> > ICCG;

but I was unsure then how to use that in the code above. Any thoughts? I was also wondering if I am passing my initial coefficient estimates correctly, because I notice that if I solve my problem once and use the obtained coefficients as starting values in a new fit that I am hardly getting any speed benefits, which I thought is strange...

来源:https://stackoverflow.com/questions/57926675/eigens-leastsquaresconjugategradient-solver-using-incomplete-cholesky-precondi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!