Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6975 Discussions

How to solve least squares problem? For dummies.

Mikhail_Matrosov
402 Views
Hello,

I'm trying to solve least squares problem. Given matrix A(mxn), m > n, minimize (Ax - b)2. MKL Reference suggests to use QR Factorization. And all calculation is done in several steps - factorization itself, normalizing matrix form, multiplying rhs, etc.

However, its a little complicated and I found no straightforward explanation on how to compute result x from given A and b. For now I don't even sure how to acquire matrix R. Should I manually multiply A with QT? Or should I extract it somehow from QR result?

I think it'd be pretty convenient to provide manual with simple code example of function

SolveLSP(int m, int n, float* A, float* b, float* x);

using LAPACKE_sgeqrf(), LAPACKE_sorgqr() etc. calls, which is exactly my problem. One may assume matrix_order to be LAPACK_ROW_MAJOR.

E.g. ippmQRDecomp reference is great. Even with picture and enough explanation on storage, though one should not be concerned of it granted with simple ippmQRBackSubst function.

Would you please grant me with such example or with some simple explanation of what functions should I call in what order?

Thanks a lot.
0 Kudos
1 Solution
mecej4
Honored Contributor III
402 Views
If you are interested only in obtaining a least-squares solution rather than in the intermediate results such as Q and R, please look at the LAPACKE_?gels routines, and the several examples in the ../mkl/examples/lapacke/source directory.

View solution in original post

0 Kudos
2 Replies
mecej4
Honored Contributor III
403 Views
If you are interested only in obtaining a least-squares solution rather than in the intermediate results such as Q and R, please look at the LAPACKE_?gels routines, and the several examples in the ../mkl/examples/lapacke/source directory.
0 Kudos
Mikhail_Matrosov
402 Views
This is the best answer I didn't even dare to hear :)

Thanks!
0 Kudos
Reply