[Numpy-discussion] confusion about eigenvector
Arnar Flatberg
arnar.flatberg@gmail....
Mon Mar 3 11:42:32 CST 2008
> i read in some document on the topic of eigenfaces that
> 'Multiplying the sorted eigenvector with face vector results in
> getting the
> face-space vector'
> facespace=sortedeigenvectorsmatrix * adjustedfacematrix
> (when these are numpy.matrices )
This will not work with numpy matrices.* is elementwise mult.
> that is why the confusion about transposing X inside
>
> facespace=dot(X.T,u[:,reorder])
>
> if i make matrices out of sortedeigenvectors, adjustedfacematrix
> then
> i will get facespace =sortedeigenvectorsmatrix * adjustedfacematrix
> which has a different set of elements than that obtained by
> dot(X.T, u[:,reorder]).
No, they are the same. u[:, reorder] *is* the sortedeigenvectormatrix,
and the transpose of a matrixproduct: (A*B).T == B.T*A, so your
facespace is just the transpose of mine.
I dont know why you are getting the end result wrong. Perhaps you are
reshaping wrong?
I'll try a complete example :-)
Get example data:
http://www.cs.toronto.edu/~roweis/data/frey_rawface.mat
-----
import scipy as sp
from matplotlib.pyplot import *
fn = "frey_rawface.mat"
data = sp.asarray(sp.io.loadmat(fn)['ff'], dtype='d').T
data = data - data.mean(0)
u, s, vt = sp.linalg.svd(data, 0)
# plot the first 6 eigenimages
for i in range(6):
subplot(2,3,i+1), imshow(vt[i].reshape((28,20)), cmap=cm.gray)
axis('image'), xticks([]), yticks([])
title("First 6 eigenfaces")
------
Arnar
More information about the Numpy-discussion
mailing list