% Author: Hal Daume III

function [E, U, lambda] = PCA(X, K)

    mu = mean(X);                   % Data mean
    N = size(X, 1);                 % Number of data points
    X = X - repmat(mu, N, 1);       % Center the data to be zero-mean
    covX = X' * X;                  % Data covariance matrix    
    [U, lambda] = eigs(covX, K);    % Compute top K eigenvalues
    E = X * U;                      % Compute embedding
    