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

Calculation of Rotation Matrix is a bit misleading... #2

Closed
kadir-gunel opened this issue Apr 30, 2022 · 2 comments
Closed

Calculation of Rotation Matrix is a bit misleading... #2

kadir-gunel opened this issue Apr 30, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@kadir-gunel
Copy link
Owner

function mapOrthogonal(X::T, Y::T; λ::Float32=Float32(1)) where {T}
    F = CUDA.CUBLAS.svd(X * Y')
    W = permutedims(F.U * F.Vt * cuinv((X * X') + λ .* CuMatrix{Float32}(I, 300, 300)))
    return W, F.S
end

The above code snippet is kind of misleading. Thinking in theory lead me to think that the matrix multiplication inside the decomposition operation X * Y' is wrong. Because what we do is that we rotate the source space towards the target space where as this operation leads to opposite direction!

We should calculate the rotation operation based on X and not Y!

To do so :

  1. Just transpose the operation : X * Y' to Y * X'.
  2. Probably, we need to shift the Vt and U operations.
  3. Debug for verification.
@kadir-gunel kadir-gunel self-assigned this Apr 30, 2022
@kadir-gunel kadir-gunel added the enhancement New feature or request label Apr 30, 2022
@kadir-gunel kadir-gunel pinned this issue Apr 30, 2022
@kadir-gunel
Copy link
Owner Author

Probably the correct operation would be as follows :

function mapOrthogonal(X::T, Y::T; λ::Float32=Float32(1)) where {T}
    F = CUDA.CUBLAS.svd(Y * X')
    W = permutedims(F.U' * F.V * cuinv((X * X') + λ .* CuMatrix{Float32}(I, 300, 300)))
    return W, F.S
end

@kadir-gunel
Copy link
Owner Author

I have changed the code as the following :

function mapOrthogonal(X::CuMatrix, Y::CuMatrix)
    d, n = size(X)

    XY = CuMatrix{Float32}(undef, d, d)
    W = CuMatrix{Float32}(undef, d, d)

    gemm!('N', 'T', cu(Float32(1)), X, Y, cu(Float32(0)), XY)

    F = svd(XY)

    gemm!('N', 'N', cu(Float32(1)), F.U, F.Vt, cu(Float32(0)), W)

    return permutedims(W)
end

I directly call the cuBLAS methods, additionally there is no regularization.

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

No branches or pull requests

1 participant