Download data, pca and lda eigenface stuff from http://www.idiap.ch/~marcel/Databases/frontalfaces/main.html

#
# computes PCA matrix using #trainPCA#
#
> tar -zxvf data-eigenface.tar.gz
> tar -zxvf pca-eigenface.tar.gz
> ls -1 `pwd`/data/*.bindata > files.list
> trainPCA files.list 1280 -verbose -save pca/model.pca

#
# visualize Eigenfaces using #pca2pgm#
#
> pca2pgm pca/model.pca 32 40 -verbose -verbose_level 1 -eigenface 10
> ls *.pgm

#
# project data into PCA subspace one file using #bindata2pca#
#
> bindata2pca data/003.bindata pca/model.pca 1280 -variance 0.5 -verbose -verbose_level 1 -o pca/003.bindata

Projection bindata file into PCA space (1280 -> 12) ...
Loading PCA model: pca/model.pca ...
Total variance = 57.6157
Eigenvalue max = 6.54322
Eigenvalue min = -5.34598e-16
0.5 per cent of variance => 12 Eigenvectors selected
n_inputs : 1280
n_patterns : 6

#
# Reconstruct an image using #bindata2ipca#
#
> bindata2pgm data/003.bindata 32 40 -unnorm
> bindata2ipca data/003.bindata pca/model.pca 1280 -verbose -verbose_level 1 -variance -1

Loading PCA model: pca/model.pca ...
Keeping all eigenvectors: 1280
Copying eigenvectors ...
Transpose the eigenvectors matrix ...
n_inputs : 1280
n_patterns : 6
Projection bindata file into PCA space (1280 -> 1280) ...
 mse = 5.05303e-14
 mse = 4.89166e-14
 mse = 5.52089e-14
 mse = 5.25584e-14
 mse = 4.2167e-14
 mse = 4.40198e-14
Total MSE = 4.89002e-14

> bindata2ipca data/003.bindata pca/model.pca 1280 -verbose -verbose_level 1 -variance 0.9

Loading PCA model: pca/model.pca ...
Total variance = 57.6157
Eigenvalue max = 6.54322
Eigenvalue min = -5.34598e-16
0.9 per cent of variance => 136 Eigenvectors selected
Copying eigenvectors ...
Transpose the eigenvectors matrix ...
n_inputs : 1280
n_patterns : 6
Projection bindata file into PCA space (1280 -> 136) ...
 mse = 0.0046822
 mse = 0.0046822
 mse = 0.00511003
 mse = 0.00511003
 mse = 0.00365963
 mse = 0.00365963
Total MSE = 0.00448395

> bindata2pgm ipca.bindata 32 40 -unnorm
> ls *.pgm

> bindata2ipca data/003.bindata pca/model.pca 1280 -verbose -verbose_level 1 -variance 0.6

Loading PCA model: pca/model.pca ...
Total variance = 57.6157
Eigenvalue max = 6.54322
Eigenvalue min = -5.34598e-16
0.6 per cent of variance => 19 Eigenvectors selected
Copying eigenvectors ...
Transpose the eigenvectors matrix ...
n_inputs : 1280
n_patterns : 6
Projection bindata file into PCA space (1280 -> 19) ...
 mse = 0.0203495
 mse = 0.0203496
 mse = 0.0272404
 mse = 0.0272404
 mse = 0.0139989
 mse = 0.0139989
Total MSE = 0.0205296

> bindata2pgm ipca.bindata 32 40 -unnorm
> ls *.pgm

> bindata2ipca data/003.bindata pca/model.pca 1280 -verbose -verbose_level 1 -variance 0.4

Loading PCA model: pca/model.pca ...
Total variance = 57.6157
Eigenvalue max = 6.54322
Eigenvalue min = -5.34598e-16
0.4 per cent of variance => 7 Eigenvectors selected
Copying eigenvectors ...
Transpose the eigenvectors matrix ...
n_inputs : 1280
n_patterns : 6
Projection bindata file into PCA space (1280 -> 7) ...
 mse = 0.0266148
 mse = 0.0266148
 mse = 0.0362658
 mse = 0.0362657
 mse = 0.0195848
 mse = 0.0195848
Total MSE = 0.0274884


> bindata2pgm ipca.bindata 32 40 -unnorm
> ls *.pgm

#
# The reconstruction error increases while the variance decreases
#
#   variance       MSE          # Eigenfaces
#     1.0        4.89002e-14        1280
#     0.9        0.00448395         136
#     0.6        0.0205296          19
#     0.4        0.0274884          7
#

#
# project data into PCA subspace all files using #bindata2pca#
#
> foreach c (`cat data/id.list`)
bindata2pca data/${c}.bindata pca/model.pca 1280 -variance 0.5 -verbose -verbose_level 1 -o pca/${c}.bindata
end

#
# computes LDA matrix using #trainLDA#
#

> tar -zxvf lda-eigenface.tar.gz
> ls -1 `pwd`/pca/*.bindata > pcafiles.list
> trainLDA pcafiles.list 12 -verbose -verbose_level 1 -classprovided -save model.lda

#
# project PCA data into LDA subspace one file using #bindata2lda#
#
> bindata2lda pca/003.bindata lda/model.lda 12 -variance 0.9 -verbose -verbose_level 1 -o lda/003.bindata
or
> bindata2lda pca/003.bindata lda/model.lda 12 -n_output 4 -verbose -verbose_level 1 -o lda/003.bindata

> readbindata lda/003.bindata -verbose
2.62094 0.542036 -3.01483 -0.58694 
2.62094 0.542036 -3.01483 -0.586771 
1.90149 -1.78666 0.413847 -2.16976 
1.90149 -1.78666 0.413847 -2.16974 
2.03724 0.533189 -1.09041 -0.811657 
2.03724 0.533189 -1.09041 -0.811561 

> bindata2lda pca/004.bindata lda/model.lda 12 -n_output 4 -verbose -verbose_level 1 -o lda/004.bindata
> readbindata lda/004.bindata -verbose
0.723977 1.59523 2.14267 -0.737938 
0.723977 1.59523 2.14267 -0.737825 
0.492157 1.11423 2.67814 -0.546292 
0.492157 1.11423 2.67814 -0.546134 
0.616704 1.34138 2.84853 -0.853059 
0.616704 1.34138 2.84853 -0.85286 


#
# project image data into PCAxLDA subspace one file using #bindata2pcalda#
#
> bindata2pcalda data/003.bindata pca/model.pca lda/model.lda 1280 -o pcalda.bindata -variancepca 0.5 -noutputlda 4 -verbose -verbose_level 1

Loading PCA model: pca/model.pca ...
Total variance = 57.6157
Eigenvalue max = 6.54322
Eigenvalue min = -5.34598e-16
0.5 per cent of variance => 12 Eigenvectors selected

Loading LDA model: lda/model.lda ...
Total variance = 2.64757
Eigenvalue max = 0.649401
Eigenvalue min = -4.07529e-16
0.95 per cent of variance => 9 Eigenvectors selected
n_inputs : 1280
n_patterns : 6
Projection bindata file into PCAxLDA space (1280 -> 4) ...

> readbindata pcalda.bindata -verbose
2.62094 0.542036 -3.01483 -0.58694 
2.62094 0.542036 -3.01483 -0.586771 
1.90149 -1.78666 0.413847 -2.16976 
1.90149 -1.78666 0.413847 -2.16974 
2.03724 0.533189 -1.09041 -0.811657 
2.03724 0.533189 -1.09041 -0.811561 

#
# Plot PCA
#
> foreach c (003 004 005 006 009)
readbindata pca/${c}.bindata -verbose > pca/${c}.txt
end

> cd pca
> gnuplot plot.gnu
> gv plot.ps

#
# Plot LDA
#
> foreach c (003 004 005 006 009)
bindata2lda pca/${c}.bindata lda/model.lda 12 -n_output 4 -o lda/${c}.bindata
end

> foreach c (003 004 005 006 009)
readbindata lda/${c}.bindata -verbose > lda/${c}.txt
end

> cd lda
> gnuplot plot.gnu
> gv plot.ps