SciML / DataDrivenDiffEq.jl

Data driven modeling and automated discovery of dynamical systems for the SciML Scientific Machine Learning organization
https://docs.sciml.ai/DataDrivenDiffEq/stable/
MIT License
405 stars 57 forks source link

`generator` should be used instead of `operator` in the Nonlinear System with Extended Dynamic Mode Decomposition example in the tutorial #292

Closed hurak closed 2 years ago

hurak commented 2 years ago

Just a minor thing. I guess that generator should be used instead of operator in Nonlinear System with Extended Dynamic Mode Decomposition example in Nonlinear Systems tutorial. See below how the last command – operator – is throwing an error:

julia> using DataDrivenDiffEq

julia> using LinearAlgebra

julia> using ModelingToolkit

julia> using OrdinaryDiffEq

julia> using Plots

julia> function slow_manifold(du, u, p, t)
           du[1] = p[1] * u[1]
           du[2] = p[2] * (u[2] - u[1]^2)
       end
slow_manifold (generic function with 1 method)

julia> u0 = [3.0; -2.0]
2-element Vector{Float64}:
  3.0
 -2.0

julia> tspan = (0.0, 5.0)
(0.0, 5.0)

julia> p = [-0.8; -0.7]
2-element Vector{Float64}:
 -0.8
 -0.7

julia> problem = ODEProblem(slow_manifold, u0, tspan, p)
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 5.0)
u0: 2-element Vector{Float64}:
  3.0
 -2.0

julia> solution = solve(problem, Tsit5(), saveat = 0.01)
retcode: Success
Interpolation: 1st order linear
t: 501-element Vector{Float64}:
 0.0
 0.01
 0.02
 0.03
 0.04
 ⋮
 4.96
 4.97
 4.98
 4.99
 5.0
u: 501-element Vector{Vector{Float64}}:
 [3.0, -2.0]
 [2.976095744391066, -1.9237690194114831]
 [2.9523819599137235, -1.8490583416341624]
 [2.9288571290288594, -1.7758416785688533]
 [2.9055197461129563, -1.7040931633410021]
 ⋮
 [0.05673587686684954, 0.15276498931098387]
 [0.05628380073013488, 0.15172164415976697]
 [0.05583532666773161, 0.15068522325451336]
 [0.0553904260177249, 0.1496556838534019]
 [0.05494907036555886, 0.1486329834178036]

julia> prob = ContinuousDataDrivenProblem(solution)
Continuous DataDrivenProblem{Float64}

julia> @variables u[1:2]
1-element Vector{Symbolics.Arr{Num, 1}}:
 u[1:2]

julia> Ψ = Basis([u; u[1]^2], u)
Model ##Basis#272 with 3 equations
States (2):
  u[1]
  u[2]
Parameters (0):

julia> res = solve(prob, Ψ, DMDPINV(), digits = 1)
"Explicit Result"

julia> system = result(res)
Model ##Koopman#277 with 2 equations
States (2):
  u[1]
  u[2]
Parameters (3):
  p[1]
  p[2]
  p[3]

julia> operator(system)
ERROR: AssertionError: Koopman is continouos.
Stacktrace:
 [1] operator(k::Koopman{Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}, Matrix{Float64}, Matrix{Float64}, Matrix{Float64}})
   @ DataDrivenDiffEq ~/.julia/packages/DataDrivenDiffEq/AGBrC/src/koopman/type.jl:212
 [2] top-level scope
   @ none:1

If generator is used instead, things are fine:

julia> generator(system)
Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}
values:
3-element Vector{Float64}:
 -1.5999999999999988
 -0.8000000000000025
 -0.6999999999999966
vectors:
3×3 Matrix{Float64}:
  4.98145e-16  -1.0          1.07363e-14
  0.613941     -8.53994e-14  1.0
 -0.789352      1.24545e-14  4.99523e-15