Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples on how to use CCA? #111

Open
xiaodaigh opened this issue Nov 19, 2019 · 1 comment
Open

Examples on how to use CCA? #111

xiaodaigh opened this issue Nov 19, 2019 · 1 comment

Comments

@xiaodaigh
Copy link

I can't figure out how use CCA in this package

function canonicalcor(x::AbstractMatrix, y::AbstractMatrix)
    ma = inv(cov(x))*cov(x, y)*inv(cov(y))*cov(y,x)
    mb = inv(cov(y))*cov(y, x)*inv(cov(x))*cov(x,y)
    evx = eigvecs(ma)
    evy = eigvecs(mb)
    abs(cor(x*evx[:, end], y*evy[:, end]))
    #[-cor(x*evx, y*evy) for (evx, evy) in zip(eachcol(evx), eachcol(evy))]
end
canonicalcor(x, y)

I just copied the formula from wikiepdia and it agrees with the results in R.

@wildart
Copy link
Collaborator

wildart commented Nov 21, 2019

Let X and Y be two samples of dimension 5 and 6 correspondingly. Package accepts data in column-major order, so samples are columns.

julia> size(X)
(5, 1000)

julia> size(Y)
(6, 1000)

julia>M = fit(CCA,X,Y; method=:svd, outdim=1)
CCA (xindim = 5, yindim = 6, outdim = 1)

julia> a = xprojection(M);

julia> b = yprojection(M);

julia> correlations(M)
1-element Array{Float64,1}:
 0.9921900042447322

julia> cor(X'a, Y'b) # need to transpose because col-major order
1×1 Array{Float64,2}:
 0.992190004244732

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants