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

Support complex matrices? #6

Closed
ssfrr opened this issue Feb 21, 2020 · 3 comments
Closed

Support complex matrices? #6

ssfrr opened this issue Feb 21, 2020 · 3 comments

Comments

@ssfrr
Copy link

ssfrr commented Feb 21, 2020

I'm not sure if the underyling algorithm is amenable to supporting complex matrices. If so do you think it's an easy add to the package? Currently it throws an error trying to get eps(::Complex)

MWE:

u = randn(ComplexF64, 100)
v = randn(ComplexF64, 20)
D = u*v' .+ randn.(ComplexF64) .* 0.1
A, E, s, sv = rpca(D)
@baggepinnen
Copy link
Owner

I have not considered complex matrices, but there is not reason not to allow them right away! I'll have a look and see what we can do

@baggepinnen
Copy link
Owner

baggepinnen commented Feb 21, 2020

The following now works on master v1.3.1

           u = randn(ComplexF64, 100)
            v = randn(ComplexF64, 20)
            E = randn(ComplexF64,100,20) .* 10 .* (rand.() .< 0.01)
            A = u*v'
            D = A .+ E
            Ah, Eh, s, sv = rpca(D)
            @test sum(abs2, Eh-E)/sum(abs2, E) < 1e-5
            @test sum(abs2, Ah-A)/sum(abs2, A) < 1e-5

I had to find a replacement for the soft thresholding operator for complex numbers, the following seems to work okay but not much thought has gotten into it

@inline function soft_th(x::Complex, ϵ)
    m,a = abs(x), angle(x)
    m = max(m-ϵ,zero(m)) + min(m+ϵ,zero(m))
    m*cis(a)
end

@ssfrr
Copy link
Author

ssfrr commented Feb 22, 2020

Great, thanks! I’ll try it out and see if this improves things over regular PCA for my problem.

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