Serving the Quantitative Finance Community

 
User avatar
MaxCohen
Topic Author
Posts: 0
Joined: June 13th, 2007, 2:44 pm

C++ PCA, eigen vectors and values

November 30th, 2012, 6:30 am

My original post was from May 2009...
 
User avatar
ExSan
Posts: 495
Joined: April 12th, 2003, 10:40 am

C++ PCA, eigen vectors and values

November 30th, 2012, 10:57 am

QuoteOriginally posted by: MaxCohenHi,I have set-up a basic C++ matrix class and need a to run Principal Component Analysis to give me all the eigen vetcors and values of a given matrix.Any body have some source code, I can use to do this?I don't want to use an existing library like boost to do this, but create my own!Cheers, Sam.Check Numerical Recipes in C, but the latest version? I tried previous version, but something is wrong with the code, so I am stuck too.If you find it, please send me a pdf / scan .
 
User avatar
Cuchulainn
Posts: 22933
Joined: July 16th, 2004, 7:38 am

C++ PCA, eigen vectors and values

November 30th, 2012, 11:45 am

QuoteOriginally posted by: ExSanQuoteOriginally posted by: MaxCohenHi,I have set-up a basic C++ matrix class and need a to run Principal Component Analysis to give me all the eigen vetcors and values of a given matrix.Any body have some source code, I can use to do this?I don't want to use an existing library like boost to do this, but create my own!Cheers, Sam.Check Numerical Recipes in C, but the latest version? I tried previous version, but something is wrong with the code, so I am stuck too.If you find it, please send me a pdf / scan .Don't write your own matrix classes. Personally, I am not impressed by NR, at all.
Last edited by Cuchulainn on November 29th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
daveangel
Posts: 5
Joined: October 20th, 2003, 4:05 pm

C++ PCA, eigen vectors and values

November 30th, 2012, 2:59 pm

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: ExSanQuoteOriginally posted by: MaxCohenHi,I have set-up a basic C++ matrix class and need a to run Principal Component Analysis to give me all the eigen vetcors and values of a given matrix.Any body have some source code, I can use to do this?I don't want to use an existing library like boost to do this, but create my own!Cheers, Sam.Check Numerical Recipes in C, but the latest version? I tried previous version, but something is wrong with the code, so I am stuck too.If you find it, please send me a pdf / scan .Don't write your own matrix classes. Personally, I am not impressed by NR, at all.I think even Messrs Press, Flannery would suggest that you should use pre-canned routines rather than their code for linear algebra
knowledge comes, wisdom lingers
 
User avatar
Cuchulainn
Posts: 22933
Joined: July 16th, 2004, 7:38 am

C++ PCA, eigen vectors and values

November 30th, 2012, 3:27 pm

QuoteOriginally posted by: daveangelQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: ExSanQuoteOriginally posted by: MaxCohenHi,I have set-up a basic C++ matrix class and need a to run Principal Component Analysis to give me all the eigen vetcors and values of a given matrix.Any body have some source code, I can use to do this?I don't want to use an existing library like boost to do this, but create my own!Cheers, Sam.Check Numerical Recipes in C, but the latest version? I tried previous version, but something is wrong with the code, so I am stuck too.If you find it, please send me a pdf / scan .Don't write your own matrix classes. Personally, I am not impressed by NR, at all.I think even Messrs Press, Flannery would suggest that you should use pre-canned routines rather than their code for linear algebraAny one use Boost Math Toolkit?
Last edited by Cuchulainn on November 29th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
zerdna
Posts: 1
Joined: July 14th, 2002, 3:00 am

C++ PCA, eigen vectors and values

December 25th, 2012, 8:38 pm

this depends on the size of the problem and the purpose. I guess if learning is the purpose than writing this type of code is ok to develop humility. If speed and performance on large matrices in the real world is the issue then you use SVD routines from Atlas optimized BLAS or MKL. The name of the better routine was dgessd last time i looked. There are various roundoff, numerical stability, and speed issues that maybe are not immediately appreciated by everyone. I wouldn't use boost as ublas were slow and not optimized, when i looked at it. NR code maybe is not pretty to look at, but they seem do the right things mathematically -- i suppose it's the next best free thing if you don't use LAPACK based code.
 
User avatar
Cuchulainn
Posts: 22933
Joined: July 16th, 2004, 7:38 am

C++ PCA, eigen vectors and values

December 26th, 2012, 4:29 pm

There are at least 2 interrelated issues here:1. The underlying data structuctures.2. Numerical linear algebra algorithms using 1ublas does not have 2. but in the directory release they try LU with disasterous results. My initial LU is 10 lines of code and is > 20 times faster whatever as seen hereNR C++ code is an insult IMO as it is just a wrapper for C which was ported from Fortran. ublas does have nice matrix proxies that makes it suitable for parallel processing and data decomposition patterns. E.g. break a matrix into 4 views with a dedicated thread for each view.Last time installing ATLAS on Win32 was a nightmare.In general, FD schemes need no matrices because they are tridiagonal and even then they are 400^2 at most, so it's a trade-off.For real speed use HPC Fortran and forget C++.It's not a black and white decision because the old engineer adage "Performance is good enough" should always be listened to. Faster <==> much more effort. A numerical analyst who can program could handcraft a solution approaching ATLAS performance I reckon. Sometimes it's better that way instead of the unfriendly installation program, old-style C code and stuff. In that sense they could learn a lot from Boost. 3. What is fast enough for the job at hand?
Last edited by Cuchulainn on December 25th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22933
Joined: July 16th, 2004, 7:38 am

C++ PCA, eigen vectors and values

December 26th, 2012, 4:51 pm

Last but not least, ublas is STL-compatible, e.g. you can use STL algorithms in ublas. Hoopla. This makes ublas very useful for postprocessing of output data. e.g. tell me where the largest error and its location in my fd solution. QuoteNR [...] they seem do the right things mathematically OK. But it's not the definitive source for the maths. At least, I don't enjoy the approach. Each to his own I suppose.There's no beating the 60s/70s books by the golden_age_of_numerical_analysis (aka Cold War) guys of the 60s and 70s. Both in English and Russian. They complemented each other's work so well.
Last edited by Cuchulainn on December 25th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
Etuka
Posts: 1
Joined: January 1st, 2002, 7:40 pm

C++ PCA, eigen vectors and values

December 28th, 2012, 2:15 pm

QuoteOriginally posted by: Cuchulainn There's no beating the 60s/70s books by the golden_age_of_numerical_analysis (aka Cold War) guys of the 60s and 70s. Both in English and Russian. They complemented each other's work so well.I think this would be a good place to stick some references in and spread the love...
 
User avatar
Cuchulainn
Posts: 22933
Joined: July 16th, 2004, 7:38 am

C++ PCA, eigen vectors and values

December 28th, 2012, 2:31 pm

QuoteOriginally posted by: EtukaQuoteOriginally posted by: Cuchulainn There's no beating the 60s/70s books by the golden_age_of_numerical_analysis (aka Cold War) guys of the 60s and 70s. Both in English and Russian. They complemented each other's work so well.I think this would be a good place to stick some references in and spread the love...Etuka,Would you like a list? OK Any specific requests?
Last edited by Cuchulainn on December 27th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
zerdna
Posts: 1
Joined: July 14th, 2002, 3:00 am

C++ PCA, eigen vectors and values

December 28th, 2012, 7:38 pm

I actually don't know of the great relevant work from old Russians. I won't be surprised -- as anyone who sat in conferences in the 90s knows, they apparently invented everything . It was all published in the Journal of Ukranian Physics, or some such, says the guy from the back in atrocious accent. Jokes aside, Russians did great things in numerical math like for example numerical convex optimization. As far as this field, Golub and Van Loan is a standard book. Jim Demmel's Applied Numerical Linear Algebra is another book. I didn't read Jim's book, but its based on grad class i took from him -- he is one of the designers and developers of LAPACK and ScaLAPACK, which is LAPACK parallel version.
 
User avatar
Cuchulainn
Posts: 22933
Joined: July 16th, 2004, 7:38 am

C++ PCA, eigen vectors and values

December 28th, 2012, 8:08 pm

For example, the exremely popular ADI Craig Sneyd method (1989) was invented in 1964 by A.A. Samarksi in 1964. And a number of Soviet journals are free online (in Russian), although some are already in English.It's probably impossible to get "MIR" books these days? I managed to get most of them in French.Herbert Keller has written some great books.
Last edited by Cuchulainn on December 27th, 2012, 11:00 pm, edited 1 time in total.