12
Outline Outline • Announcements Add/drop by Monday HWI on the web Principal Components Analysis (PCA) Linking to libraries

Outline

  • Upload
    mabli

  • View
    22

  • Download
    0

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: Outline

OutlineOutline

• Announcements– Add/drop by Monday– HWI on the web

• Principal Components Analysis (PCA)• Linking to libraries

Page 2: Outline

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

Page 3: Outline

PCAPCA

• Example: Temperature in NW Atlantic

Page 4: Outline

PCAPCA

Page 5: Outline

PCAPCA

Rgn 1 Rgn 2 … Rgn 8

C =

Cov=1/(m-1)*CT*C

Cov is n-by-n

• Matrix of data: n

m

Page 6: Outline

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

Page 7: Outline

PCAPCA

Page 8: Outline

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

Page 9: Outline

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

Page 10: Outline

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?

Page 11: Outline

Compiling & LinkingCompiling & Linkingprog.c

for (j=0;j<5){ sin(x[j]);}

prog#($**@)@__!({ø∆˜ß√ˆœπ˚Œ¨Ω√≈˜¡£¢∞

cc prog.c -oprog

Transnslation

prog.o#($**@)@__!(Œ¨Ω√≈˜¡£¢∞

Linkprintf.o

#($**@)@__!(Œ¨Ω√≈˜¡£¢∞

#($**@)@__!(Œ¨Ω√≈˜¡£¢∞

sin.o

Page 12: Outline

• 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