PCA.jl 365 Bytes
Newer Older
Fredrik Bagge Carlson's avatar
Fredrik Bagge Carlson committed
1
2
3
4
5
6
7
8
9
10
11
12
13
""" Performs PCA   PCA(W,doplot=false)"""
function PCA(W,doplot=false)
    W0 = mean(W,1);
    W = W-repmat(W0,size(W,1),1);
    (score,latent,C) = svd(W)
    score = score*diagm(latent)
    if doplot
        newplot(cumsum(latent)./sum(latent),"o")
        title("Fraction of variance explained")
        ylim([0,1])
    end
    C,score,latent,W0
end