Nonlinear Time Continuous System
Similarly, we can use the Extended Dynamic Mode Decomposition via a nonlinear Basis of observables. Here, we will look at a rather famous example with a finite dimensional solution.
using DataDrivenDiffEq
using LinearAlgebra
using OrdinaryDiffEq
using DataDrivenDMD
using Plots
function slow_manifold(du, u, p, t)
du[1] = p[1] * u[1]
du[2] = p[2] * (u[2] - u[1]^2)
end
u0 = [3.0; -2.0]
tspan = (0.0, 5.0)
p = [-0.8; -0.7]
problem = ODEProblem{true, SciMLBase.NoSpecialize}(slow_manifold, u0, tspan, p)
solution = solve(problem, Tsit5(), saveat = 0.1);
plot(solution)Since we are dealing with a continuous system in time, we define the associated DataDrivenProblem accordingly using the measured states X, their derivatives DX and the time t.
prob = DataDrivenProblem(solution)
plot(prob)Additionally, we need to define the Basis for our lifting, before we solve the problem in the lifted space.
@parameters t
@variables u(t)[1:2]
Ψ = Basis([u; u[1]^2], u, independent_variable = t)
res = solve(prob, Ψ, DMDPINV(), digits = 2)"DataDrivenSolution{Float64}" with 2 equations and 3 parameters.
Returncode: Success
Residual sum of squares: 2.9578125985238936e-18We can also use different metrics on the DataDrivenSolution like the aic
aic(res)-4582.679556859201The aicc
aicc(res)-4582.434658900017The bic
bic(res)-4574.804638419348The loglikelihood
loglikelihood(res)2294.3397784296003And the number of parameters
dof(res)3Let's have a closer look at the Basis
basis = get_basis(res)Model ##Basis#314 with 2 equations
States : (u(t))[1] (u(t))[2]
Parameters : p₁ p₂ p₃
Independent variable: t
Equations
Differential(t)((u(t))[1]) = p₁*(u(t))[1]
Differential(t)((u(t))[2]) = p₂*(u(t))[2] + p₃*((u(t))[1]^2)And the connected parameters
get_parameter_map(basis)3-element Vector{Pair{SymbolicUtils.BasicSymbolic{Real}, Float64}}:
p₁ => -0.8
p₂ => -0.7
p₃ => 0.6999999999And plot the results
plot(res)Copy-Pasteable Code
using DataDrivenDiffEq
using LinearAlgebra
using OrdinaryDiffEq
using DataDrivenDMD
function slow_manifold(du, u, p, t)
du[1] = p[1] * u[1]
du[2] = p[2] * (u[2] - u[1]^2)
end
u0 = [3.0; -2.0]
tspan = (0.0, 5.0)
p = [-0.8; -0.7]
problem = ODEProblem{true, SciMLBase.NoSpecialize}(slow_manifold, u0, tspan, p)
solution = solve(problem, Tsit5(), saveat = 0.1);
prob = DataDrivenProblem(solution)
@parameters t
@variables u(t)[1:2]
Ψ = Basis([u; u[1]^2], u, independent_variable = t)
res = solve(prob, Ψ, DMDPINV(), digits = 2)
# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jlThis page was generated using Literate.jl.