Monday, October 22, 2012

PCA Dimension Reduction In Matlab


X = columnwise_vector';
%row-wise [X rows are the number of samples and cols are the number of dimensions]

C = mean(X);
X = X - repmat(C, size(X,1),1); %normalize by removing mean

covar = cov(X); %compute covariance matrix

[p,D]=eigs(covar, numDim);

X_reduced = (X*p);
X_reduced = X_reduced';

No comments: