Skip to content

Instantly share code, notes, and snippets.

@vtta
Last active May 1, 2019 18:18
Show Gist options
  • Save vtta/f94f71bb8a1c39d6116de84300b473b5 to your computer and use it in GitHub Desktop.
Save vtta/f94f71bb8a1c39d6116de84300b473b5 to your computer and use it in GitHub Desktop.
simple K-L transform algorithm implemented in Octave
function Y=KLTransform(X, d)
[sampleNum, featureNum] = size(X);
m = mean(X);
for i = 1:sampleNum
X(i,:) = X(i,:) - m;
end
C = cov(X);
[V, D] = eig(C);
S = [diag(D), V];
S = sortrows(S, -1);
S = S(1:d, 2:end);
Y = (S*X')';
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment