PCA.jl 449 Bytes
Newer Older
1
2
""" Performs PCA   PCA(W)"""
function PCA(W)
Fredrik Bagge Carlson's avatar
Fredrik Bagge Carlson committed
3
4
5
6
7
8
    W0 = mean(W,1);
    W = W-repmat(W0,size(W,1),1);
    (score,latent,C) = svd(W)
    score = score*diagm(latent)
    C,score,latent,W0
end
Fredrik Bagge Carlson's avatar
Fredrik Bagge Carlson committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22


using MLKernels
function kernelPCA(X; α=1.0)
    κ = GaussianKernel(α)
    K = kernelmatrix(κ,X)
    N = size(K)[1]
    In = fill(1/N,(N,N))
    K = K-In*K - K*In + In*K*In # Make sure mean is zero

    (D,V) = eig(K)
    Kpc = K*V
    Kpc,D,V
end