Getting Started
The workflow for DataDrivenDiffEq.jl is similar to other SciML packages. You start by defining a DataDrivenProblem
and then dispatch on the solve
command to return a DataDrivenSolution
.
Here is an outline of the required elements and choices:
- Define a
DataDrivenProblem
using your data. - Optional: Choose a
Basis
. solve
the problem.
using DataDrivenDiffEq
using ModelingToolkit
using LinearAlgebra
using DataDrivenSparse
Generate a test problem
f(u) = u .^ 2 .+ 2.0u .- 1.0
X = randn(1, 100);
Y = reduce(hcat, map(f, eachcol(X)));
Create a problem from the data
problem = DirectDataDrivenProblem(X, Y, name = :Test)
Direct DataDrivenProblem{Float64} Test in 1 dimensions and 100 samples
Choose a basis
@variables u
basis = Basis(monomial_basis([u], 2), [u])
Model ##Basis#320 with 3 equations
States : u
Independent variable: t
Equations
φ₁ = 1
φ₂ = u
φ₃ = u^2
Solve the problem, using the solver of your choosing
res = solve(problem, basis, STLSQ())
"DataDrivenSolution{Float64}" with 1 equations and 3 parameters.
Returncode: Success
Residual sum of squares: 3.94138999850611e-18
Copy-Pasteable Code
using DataDrivenDiffEq
using ModelingToolkit
using LinearAlgebra
using DataDrivenSparse
f(u) = u .^ 2 .+ 2.0u .- 1.0
X = randn(1, 100);
Y = reduce(hcat, map(f, eachcol(X)));
problem = DirectDataDrivenProblem(X, Y, name = :Test)
@variables u
basis = Basis(monomial_basis([u], 2), [u])
println(basis) # hide
res = solve(problem, basis, STLSQ())
println(res) # hide
# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl
This page was generated using Literate.jl.