Decent C++ library for matrix manipulation and calculating Eigenvalues/vectors

H

Havatcha

Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.
 
B

Bill Shortall

Havatcha said:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.

what platform and compiler are you using?
 
M

Mark P

Havatcha said:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.

There's a collection of Fortran libraries for linear algebra called
LAPACK. I'm pretty sure it's free though I can't testify to its ease of
use. At the very least you'll have to get your compiler to link C++
code to Fortran objects.

A google search reveals that there are packages LAPACK++ and CLAPACK
which appear to be C++ and C code.
 
E

E. Robert Tisdale

Havatcha said:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.

Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/

Then take a look at
The Object-Oriented Numerics Page

http://www.oonumerics.org/oon/
 
Y

Yuriy Solodkyy

Try this:

The Matrix Template Library (MTL)
http://www.osl.iu.edu/research/mtl/

The Matrix Template Library (MTL) is a high-performance generic
component library that provides comprehensive linear algebra
functionality for a wide variety of matrix formats.

As with the Standard Template Library (STL), MTL uses a five-fold
approach, consisting of generic functions, containers, iterators,
adaptors, and function objects, all developed specifically for high
performance numerical linear algebra. Within this framework, MTL
provides generic algorithms corresponding to the mathematical operations
that define linear algebra. Similarly, the containers, adaptors, and
iterators are used to represent and to manipulate concrete linear
algebra objects such as matrices and vectors.

To many scientific computing users, however, the advantages of an
elegant programming interface are secondary to issues of performance.
Generic programming is a powerful tool in this regard as well -
performance tuning can itself be described in a generic fashion. These
performance tuning abstractions are realized in a generic low-level
library - the Basic Linear Algebra Instruction Set (BLAIS). Experimental
results show that MTL with the BLAIS achieves performance that is as
good as, or better than, vendor-tuned libraries. Thus, MTL demonstrates
that the proper abstractions can be used to achieve high levels of
performance, contrary to conventional wisdom. In addition, MTL requires
orders of magnitude fewer lines of code for its implementation, with the
concomitant savings in development and maintenance effort.

Yuriy
 
H

Havatcha

Bill said:
what platform and compiler are you using?


Good point, GCC3.3 and Linux.

Looks like there are a few interesting libraries to choose from already
on the thread, thanks everyone for your help.
 
B

Bill Shortall

Havatcha said:
Good point, GCC3.3 and Linux.

Looks like there are a few interesting libraries to choose from already
on the thread, thanks everyone for your help.

Linear algebra libs and eigenvectors rank close to root canal work
in the

heirarcy of assignments C++ programmers avoid. There isn't even the most

remote possibility you will find a library that is

1 written entirely in C++
2 fully featured i.e. has equation solving, decompositions like the
SVD and QR , and eigenvalues symmetric & non symmetric
3 includes the source code
4 free.

There is however the very good probability that you will spend a LOT of

time messing arround with the libs out there and get nothing for your
efforts.

Many of the libs write the kernel in C or C++ and then try to link it to
the old

LAPACK libs written in fortran. Unfortunately they don't include the final
linklib

file so you have to get yourself a fortran compiler, C++ compiler, and

compatable linker for the two .. not easy. LAPACK has many many thousands
of lines

All of the free libs out there have some sort of problem. My advise:

1. buy MATLAB and the toolbox you need for your problem.

2. try the Gnu Scientific Library ( GSL) it's written in C not C++
and it won't compile on windows; but it has the symmetric eigenvalues
and SVD you need for your SCA. It even has a big thick manual in print.

3. Look at Quantlib. It's in C++, free ,very well written, and does have
the
SVD ( not eigens) but its not exactly a Linear Algebra Package .
You will have to pick those parts out. You might get it running in two
weeks.
www.quantlib.org

4. talk to the people who have writen C++ LAPACK combinations and see if
they
will do the fortran compilations and linking for you


5. Do not let the thought of writing it yourself reside in your memory for
more than a nanosecond.

Good luck,.... Bill
 
G

Greg Schmidt

Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and caculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.

You may find some useful resources at http://www.oonumerics.org/
 
R

Robert Davies

Havatcha said:
Does anyone know of a decent (free/easy to use) C++ library for
manipulating matrices and calculating eigenvalues, eigenvectors and so
on? I intend to add some Principal Component Analysis functionality to
some software.

Any recommendations appreciated.

I think newmat11 is good for this kind of thing, but since I wrote it
this is not an unbiased opinion.

See http://www.robertnz.com

Robert
 
L

Lionel B

Bill Shortall said:
Linear algebra libs and eigenvectors rank close to root canal work
in the heirarcy of assignments C++ programmers avoid. There isn't
even the most remote possibility you will find a library that is

1 written entirely in C++
2 fully featured i.e. has equation solving, decompositions like the
SVD and QR , and eigenvalues symmetric & non symmetric
3 includes the source code
4 free.

There is however the very good probability that you will spend a LOT of
time messing arround with the libs out there

I'm with you so far...
and get nothing for your efforts.

Why? The learning curve may be steep but it's not rocket science...
Many of the libs write the kernel in C or C++ and then try to link it to
the old LAPACK libs written in fortran.

.... actually, LAPACK is probably very widely used in rocket science ;-)

Anyhow, old it may be, but LAPACK (with the BLAS linear algebra kernel) is *very* efficient, exceedingly well debugged,
stable and probably among the most "tried and tested" software in existence. LAPACK still represents the state of the
art in efficient linear algebra manipulation. It is not pretty, nor is the programming interface particularly friendly
(that may be an understatement), but if you are serious about linear numerics it may well be worth getting to grips
with. You will certainly end up learning (possibly more than you wanted to know) about linear algebra computing.
Unfortunately they don't include the final linklib file so you have to get
yourself a fortran compiler, C++ compiler, and compatable linker for the
two .. not easy.

Seeing as the OP has GCC he/she already has a fortran compiler (g77), C compiler (gcc), C++ compiler (g++), compatible
linker (ld) and will indeed be able to build and link with fortran LAPACK.

Many processor/compiler vendors provide highly optimised BLAS and/or LAPACK implementations. There is also the open
source ATLAS project (http://math-atlas.sourceforge.net/) which can build BLAS + (a subset of) LAPACK libraries -
automatically tuned for your platform - and includes a C (although not C++) interface. It is simple to build with GCC (I
have done so under Linux and also under Cygwin on Win32).

Regards,
 
H

Havatcha

Linear algebra libs and eigenvectors rank close to root canal work
in the

heirarcy of assignments C++ programmers avoid. There isn't even the most

remote possibility you will find a library that is

1 written entirely in C++
2 fully featured i.e. has equation solving, decompositions like the
SVD and QR , and eigenvalues symmetric & non symmetric
3 includes the source code
4 free.

I had started to come to that conclusion, and since time is pressing, I
will be using Octave (www.octave.org) instead for the calculations with
a few system() calls and string parsing. Clunky, but less of a headache.
 
B

Bill Shortall

Lionel B said:
I'm with you so far...


Why? The learning curve may be steep but it's not rocket science...


... actually, LAPACK is probably very widely used in rocket science ;-)

Anyhow, old it may be, but LAPACK (with the BLAS linear algebra kernel) is
*very* efficient, exceedingly well debugged,
stable and probably among the most "tried and tested" software in
existence. LAPACK still represents the state of the
art in efficient linear algebra manipulation. It is not pretty, nor is the
programming interface particularly friendly
(that may be an understatement), but if you are serious about linear
numerics it may well be worth getting to grips
with. You will certainly end up learning (possibly more than you wanted to
know) about linear algebra computing.
Seeing as the OP has GCC he/she already has a fortran compiler (g77), C
compiler (gcc), C++ compiler (g++), compatible
linker (ld) and will indeed be able to build and link with fortran LAPACK.

Many processor/compiler vendors provide highly optimised BLAS and/or
LAPACK implementations. There is also the open
source ATLAS project (http://math-atlas.sourceforge.net/) which can build
BLAS + (a subset of) LAPACK libraries -
automatically tuned for your platform - and includes a C (although not
C++) interface. It is simple to build with GCC (I
have done so under Linux and also under Cygwin on Win32).

Regards,

LAPACK is a great system; but I believe
that getting it up and running is too
much to expect for a C++ programmer especially if his Fortran is rusty,

You didn't say which C++ main library you linked to - MTL, IT++ ?? How
long did it take you to do it? What are the problems.?

Regards...Bill
 
L

Lionel B

Bill Shortall said:
Lionel B said:
[...]

Many processor/compiler vendors provide highly optimised BLAS and/or
LAPACK implementations. There is also the open
source ATLAS project (http://math-atlas.sourceforge.net/) which can build
BLAS + (a subset of) LAPACK libraries -
automatically tuned for your platform - and includes a C (although not
C++) interface. It is simple to build with GCC (I
have done so under Linux and also under Cygwin on Win32).

LAPACK is a great system; but I believe
that getting it up and running is too
much to expect for a C++ programmer especially if his Fortran is rusty,

I found getting ATLAS[*] up and running to be as simple as typing "make" and "make install" and answering a few prompts
(it can be a rather lengthy process - about 6-8 hours on my P4 (!) - as ATLAS tunes itself by running screeds of timing
tests). At the end of the install you're set up with the atlas/blas/lapack libraries and C headers cblas.h and
clapack.h. The function calls in these headers are reasonably documented and correspond exactly to the legacy Fortran
BLAS and LAPACK interface - but you don't need to know any Fortran at all - it's straight C (you'll need to wrap the
headers in extern "C" to use in C++).
You didn't say which C++ main library you linked to - MTL, IT++ ?? How
long did it take you to do it? What are the problems.?

The point to note is that BLAS/LAPACK handle (dense) matrices as simple 1-d arrays (of float, double or complex type);
as long as your C++ matrix library can handle this storage format (row- or column-major is ok), implementing an
interface shouldn't be too problematic. I generally use my own rather basic matrix library, but I have in the past
successfully hacked Blitz++ (http://www.oonumerics.org/blitz/) to interface to a few BLAS/LAPACK routines - that wasn't
too difficult. The trickiest part is probably matching up the strides, transpose states, order, etc. with your library.

Efficiency-wise alone it pays off; I've found straight matrix multiplication via the ATLAS/BLAS gemm() call to be orders
of magnitude faster than I could code it in pure C or C++. Even beats Matlab hands down on my system...

[*] Be aware that ATLAS doesn't implement the full LAPACK (although I believe there's work underway to extend it).
Enough to do eigenvalues, solve equations, invert matrices, etc, though. [There are instructions in the ATLAS docs on
how to set up a full Fortran LAPACK so that it will use the ATLAS BLAS, but that sounded a little hairy... haven't tried
it].

Cheers,
 
Joined
Jun 8, 2007
Messages
1
Reaction score
0
how to use in VC++

I am in a need of matrix operations in my project which is a Dialog Based MFC project in VC++.

I tried using MTL. But since I wanted to use geev() for calculating Eigen Values, it requires to include mtl2lapack.h. VC++ says there's no tool available to compile the .h file. How do I solve this problem??

I also tried using NewMat. It gives me a lot of linkage error. Can somebody help me on how to use NewMat functions in already existing VC++ project/wprkspace?

Awaiting Reply.

-Ram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top