Post on 31-Jan-2016
description
OutlineOutline
• Announcements– Add/drop by Monday– HWI on the web
• Principal Components Analysis (PCA)• Linking to libraries
PCAPCA
• 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
PCAPCA
• Example: Temperature in NW Atlantic
PCAPCA
PCAPCA
Rgn 1 Rgn 2 … Rgn 8
C =
Cov=1/(m-1)*CT*C
Cov is n-by-n
• Matrix of data: n
m
PCAPCA
• 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
PCAPCA
PCA SummaryPCA Summary
• 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
Accessing LibrariesAccessing Libraries
• 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
UNIX LibrariesUNIX 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 & LinkingCompiling & Linkingprog.c
for (j=0;j<5){ sin(x[j]);}
prog#($**@)@__!({ø∆˜ß√ˆœπ˚Œ¨Ω√≈˜¡£¢∞
cc prog.c -oprog
Transnslation
prog.o#($**@)@__!(Œ¨Ω√≈˜¡£¢∞
Linkprintf.o
#($**@)@__!(Œ¨Ω√≈˜¡£¢∞
#($**@)@__!(Œ¨Ω√≈˜¡£¢∞
sin.o
• 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 librariesBuilding with libraries