120 likes | 201 Views
Outline. Announcements Add/drop by Monday HWI on the web Principal Components Analysis (PCA) Linking to libraries. PCA. Many scientific problems are complicated High-dimensional (lots of interesting parameters) Observations from mulitple instruments/locations
E N D
Outline Announcements Add/drop by Monday HWI on the web Principal Components Analysis (PCA) Linking to libraries
PCA Many scientific problems are complicated High-dimensional (lots of interesting parameters) Observations from mulitple instruments/locations PCA is a method for reducing the dimensionality of a system by exploiting covariance among variables PCA identifies linear combinations (vectors) that represent “interesting” features common to the data sets
Matrix of data: PCA n m Cov=1/(m-1)*CT*C Cov is n-by-n
PCA • Let • v1, v2, …, vN be the eigenvectors of Cov • 1, 2, …, N be the corresponding eigenvalues • Assume 1>2> …> N • Then, • C* v1 is a new time-series representing 1/(1+ 2+ …+ N ) percent of the total variance • If you’re lucky, v1 & v2 will represent a lot of the variance and can be used instead of the entire system
Load m-by-n data matrix C Compute Cov=1/(m-1)*CT*C BLAS Level 3 routine SSYRK computes a*A*AT+b*v a*AT*A+b*v Compute eigenvalues and eigenvectors of Cov LAPACK routine SSYEV computes eigenvectors and eigenvalues for symmetric matrices PCA Summary
We could download code for BLAS and LAPACK and compile with our code Slow (BLAS and LAPACK are big) Ideally, we would compile BLAS & LAPACK once to object code (.o) and link Saves compile time, easier to maintain Accessing Libraries
UNIX Libraries Pre-built libraries (commercial or otherwise) are stored as “archives” on UNIX machines lib<NAME>.a libblas.a -- BLAS routines liblapack.a--LAPACK routines System libraries are in directories like /lib and /usr/lib archives are actually collections of object code (.o) How do we access routines in libraries?
Compiling & Linking prog.c prog prog.o printf.o for (j=0;j<5){ sin(x[j]); } #($**@)@__!( {ø∆˜ß√ˆœπ˚ Œ¨Ω√≈˜¡£¢∞ #($**@)@__!( Œ¨Ω√≈˜¡£¢∞ #($**@)@__!( Œ¨Ω√≈˜¡£¢∞ #($**@)@__!( Œ¨Ω√≈˜¡£¢∞ sin.o cc prog.c -oprog Transnslation Link
1) Compile the code you have (use -c) 2) Link your code together and link to the libraries you need g77 <YOUR OBJECTS> {-L<LIBPATH>} -lname -L sets directory where linker will look for libraries System libraries (/usr/lib, etc.) automatically included, so -L not necessary -lname links to libname.a system libraries (or LIBPATH) Building with libraries