开发者

Lapackpp vs Boost BLAS

for start, i am newbie in C++.

i am writing a program for my Master thesis which part of it suppose to solve regression in a recursive way.

I would like to solve:

Ax = y

In my case computation speed is not neglectable, that is way i would like to know if Boost::BLAS using

x = (A^T A)^{-1}A^Ty

will require less computation time then Lapackpp (I am using gentoo).

P.S. I was able to find at Lapackpp project site Class documentations but not exampl开发者_运维百科es. Could someone provides me some examples in case Lapack is faster then Boost::BLAS

Thanks


From a numerical analysis standpoint, you never want to write code that

  • Explicitly inverts a matrix, or
  • Forms the matrix of normal equations (A^T A) for a regression

Both of these are more work and less accurate (and likely less stable) than the alternatives that solve the same problem directly.

Whenever you see some math showing a matrix inversion, that should be read to mean "solve a system of linear equations", or factor the matrix and use the factorization to solve the system. Both BLAS and Lapack have routines to do this.

Similarly, for the regression, call a library function that computes a regression, or read how to do it yourself. The normal equations method is the textbook wrong way to do it.


High level interface and low level optimizations are two different things.

LAPACK and uBLAS provide high level interface and un-optimized low level implementation. Hardware optimized low level routines (or bindings) should come from somewhere else. Once bindings are provided, LAPACK and uBLAS can use optimized low level routines instead of their own un-optimized implementations.

For example, ATLAS provides optimized low level routines, but only limited high level (level 3 BLAS and etc) interface. You can bind ATLAS to LAPACK. Then LAPACK would use ATLAS for low level work. Think of LAPACK as a senior manager who delegates technical work to experienced engineers (ATLAS). The same for uBLAS. You can bind uBLAS and MKL. The result would be optimized C++ library. Check the documentation and use google to figure out how to do it.


Do you really need to implement with C++? Would for example python/ numpy be an alternative for you? And for recursive regression (least squares) I'll recommend to look for MIT Professor Strang's lectures on linear algebra and/ or his books.


Armadillo wraps BLAS and LAPACK in a nice C++ interface, and provides the following Matlab-like functions directly related to your problem:

  • solve(), to solve a system of linear equations
  • pinv(), pseudo-inverse (which uses SVD internally)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜