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

truncated_svd() is unable to handle complex matrices #367

Open
clairevalva opened this issue Jul 6, 2022 · 3 comments
Open

truncated_svd() is unable to handle complex matrices #367

clairevalva opened this issue Jul 6, 2022 · 3 comments

Comments

@clairevalva
Copy link

truncated_svd appears to be unable to handle complex matrices (both with the method of truncation by explicit rank or tolerance). The following code which uses truncated_svd() via DMDSVD() fails.

using DataDrivenDiffEq
freq1 = 2
freq2 = 3
freq3 = 11

dt = 0.1
t = 0:dt:30

x = exp.(1im*freq1*t);
y = exp.(1im*freq2*t);
z = exp.(1im*freq3*t);

X = hcat(x,y,z)';

problem = DiscreteDataDrivenProblem(X, t);
res = solve(problem, DMDSVD());

with errors:

 [1] min(x::Float64, y::ComplexF64)
   @ Base ./operators.jl:433
 [2] truncated_svd(A::Matrix{ComplexF64}, truncation::Float64)
   @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/s9jl3/src/koopman/algorithms.jl:3
@AlCap23
Copy link
Collaborator

AlCap23 commented Jul 7, 2022

Currently, we assume(d) the input is Real.

A quick fix would be to compare the magnitude and truncation:

function truncated_svd(A::AbstractMatrix{T}, truncation::Real) where T <: Number
    truncation = min(norm(convert(T, truncation)), norm(one(T)))
    U, S, V = svd(A)
    r = vec(S .> truncation*maximum(S))
    U = U[:, r]
    S = S[r]
    V = V[:, r]
    return U, S, V
end

@ChrisRackauckas
Copy link
Member

We should probably throw an error message much sooner then that makes it clear that complex isn't supported here.

@clairevalva
Copy link
Author

An error sooner would be nice :)
(But at least for the case of DMDSVD, there is no particular reason intrinsic to the algorithm itself that requires real input.)

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

3 participants