DataDrivenDiffEq.jl
DataDrivenDiffEq.jl copied to clipboard
Creating and solving an ODEProblem from a Koopman after DMDSVD
using DataDrivenDiffEq, LinearAlgebra, ModelingToolkit, OrdinaryDiffEq
x = rand(2, 100)
t = 1.:100
prob = DiscreteDataDrivenProblem(x, t)
res = solve(prob, DMDSVD(), digits = 1)
system = result(res)
prob2 = ODEProblem(system, x[:, 1], (t[1], t[end]))
sol2 = solve(prob2, Tsit5(); saveat=t)
I would expect system to be able to be recreated back into an ODEProblem and solved.
I was trying to solve the generated system to be able to calculate the error between the original data and the Koopman system.
Error and status
(jl_lcYs90) pkg> st
Status `/private/var/folders/sk/h402gsld7mx_v605wv7bblsc0000gn/T/jl_lcYs90/Project.toml`
[2445eb08] DataDrivenDiffEq v0.6.5
[961ee093] ModelingToolkit v5.26.0
[1dea7af3] OrdinaryDiffEq v5.63.2
[37e2e46d] LinearAlgebra
julia> sol2 = solve(prob2, Tsit5(); saveat=t)
ERROR: MethodError: no method matching *(::Type{Core.MethodMatch}, ::Float64)
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any...) at operators.jl:655
*(::StridedArray{P}, ::Real) where P<:Dates.Period at /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/Dates/src/deprecated.jl:44
*(::Union{SparseArrays.SparseVector{Tv, Ti}, SubArray{Tv, 1, <:SparseArrays.AbstractSparseMatrixCSC{Tv, Ti}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, false}, SubArray{Tv, 1, <:SparseArrays.AbstractSparseVector{Tv, Ti}, Tuple{Base.Slice{Base.OneTo{Int64}}}, false}} where {Tv, Ti}, ::Number) at /Users/sabae/src/julia/usr/share/julia/stdlib/v1.7/SparseArrays/src/sparsevector.jl:1474
...
Stacktrace:
[1] macro expansion
@ ~/.julia/packages/SymbolicUtils/2UXNG/src/code.jl:325 [inlined]
[2] macro expansion
@ ~/.julia/packages/Symbolics/H8dtg/src/build_function.jl:359 [inlined]
[3] macro expansion
@ ~/.julia/packages/SymbolicUtils/2UXNG/src/code.jl:283 [inlined]
[4] macro expansion
@ ~/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:129 [inlined]
[5] macro expansion
@ ./none:0 [inlined]
[6] generated_callfunc
@ ./none:0 [inlined]
[7] (::RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :ˍ₋arg3), Symbolics.var"#_RGF_ModTag", Symbolics.var"#_RGF_ModTag", (0xcb89e00f, 0xc684b487, 0xf40a4ba9, 0xa75e4fcd, 0x25399985)})(::Vector{Float64}, ::Vector{Float64}, ::Vector{Any}, ::Float64)
@ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/KrkGo/src/RuntimeGeneratedFunctions.jl:117
[8] (::DataDrivenDiffEq.var"#f#2")(du::Vector{Float64}, u::Vector{Float64}, p::Vector{Any}, t::Float64)
@ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/8WqtV/src/basis.jl:94
[9] (::DataDrivenDiffEq.var"#f#2")(du::Vector{Float64}, u::Vector{Float64}, p::SciMLBase.NullParameters, t::Float64)
@ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/8WqtV/src/basis.jl:128
[10] (::Koopman{Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}, Vector{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}})(::Vector{Float64}, ::Vararg{Any})
@ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/8WqtV/src/basis.jl:438
[11] ODEFunction
@ ~/.julia/packages/SciMLBase/UIp7W/src/scimlfunctions.jl:334 [inlined]
[12] initialize!(integrator::OrdinaryDiffEq.ODEIntegrator{Tsit5, true, Vector{Float64}, Nothing, Float64, SciMLBase.NullParameters, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, Koopman{Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}, Vector{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Any}, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5, OrdinaryDiffEq.InterpolationData{ODEFunction{true, Koopman{Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}, Vector{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Any}, Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}}, DiffEqBase.DEStats}, ODEFunction{true, Koopman{Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}, Vector{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Any}, Nothing}, OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, OrdinaryDiffEq.DEOptions{Float64, Float64, Float64, Float64, PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(opnorm), Nothing, CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, Nothing, Nothing, Int64, Tuple{}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, Tuple{}}, Vector{Float64}, Float64, Nothing, OrdinaryDiffEq.DefaultInit}, cache::OrdinaryDiffEq.Tsit5Cache{Vector{Float64}, Vector{Float64}, Vector{Float64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}})
@ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/toaY0/src/perform_step/low_order_rk_perform_step.jl:623
[13] __init(prob::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, SciMLBase.NullParameters, ODEFunction{true, Koopman{Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}, Vector{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Any}, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::Tsit5, timeseries_init::Tuple{}, ts_init::Tuple{}, ks_init::Tuple{}, recompile::Type{Val{true}}; saveat::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, tstops::Tuple{}, d_discontinuities::Tuple{}, save_idxs::Nothing, save_everystep::Bool, save_on::Bool, save_start::Bool, save_end::Nothing, callback::Nothing, dense::Bool, calck::Bool, dt::Float64, dtmin::Nothing, dtmax::Float64, force_dtmin::Bool, adaptive::Bool, gamma::Rational{Int64}, abstol::Nothing, reltol::Nothing, qmin::Rational{Int64}, qmax::Int64, qsteady_min::Int64, qsteady_max::Int64, beta1::Nothing, beta2::Nothing, qoldinit::Rational{Int64}, controller::Nothing, fullnormalize::Bool, failfactor::Int64, maxiters::Int64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), internalopnorm::typeof(opnorm), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), userdata::Nothing, allow_extrapolation::Bool, initialize_integrator::Bool, alias_u0::Bool, alias_du0::Bool, initializealg::OrdinaryDiffEq.DefaultInit, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/toaY0/src/solve.jl:456
[14] #__solve#477
@ ~/.julia/packages/OrdinaryDiffEq/toaY0/src/solve.jl:4 [inlined]
[15] #solve_call#44
@ ~/.julia/packages/DiffEqBase/Rmj4o/src/solve.jl:61 [inlined]
[16] #solve_up#46
@ ~/.julia/packages/DiffEqBase/Rmj4o/src/solve.jl:87 [inlined]
[17] #solve#45
@ ~/.julia/packages/DiffEqBase/Rmj4o/src/solve.jl:73 [inlined]
[18] top-level scope
@ REPL[28]:1
Maaaaybe #310