This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using HouseholderQR to solve for specified number of factors

Tags: None
(comma "," separated)
ansar
Registered Member
Posts
15
Karma
0
I am trying to solve a linear least squares problem using HouseholderQR.

The system of equations is:
Ax=b
Where A is an m*n design matrix.
I decompose A using Householder QR. Now I would like to solve my system for 1,2,3,4...k factors where k<=n

In Eigen, given a QR object, is it possible for me to specify the number of columns(k) to use of the QR decomposition for solving?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You will have to write your own solving code:

Code: Select all
   c = b;
   c.applyOnTheLeft(householderSequence( qr.matrixQR().leftCols(k),  qr.hCoeffs().head(k)).transpose() );
   qr.matrixQR()
       .topLeftCorner(k, k)
       .template triangularView<Upper>()
       .solveInPlace(c.topRows(k));

    x.topRows(k) = c.topRows(k);
    x.bottomRows(x.row(s)-k).setZero();
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
btw, what's the use case for that?


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]