I’m trying to fit a data-driven differential equation system via DataDrivenDiffEq. DMD and Sindy work fine, but symbolic regression fails. Any ideas what’s wrong?
# Load libraries
using OrdinaryDiffEq
using DataDrivenDiffEq
using DataDrivenSparse
using DataDrivenSR
using ModelingToolkit
# Define the SIR model
function sir_ode(u,p,t)
(s,i,r) = u
(β,γ) = p
ds = -β*s*i
di = β*s*i - γ*i
dr = γ*i
[ds,di,dr]
end
p = [0.5,0.25]
u0 = [0.99, 0.01, 0.0]
tspan = (0.0, 40.0)
δt = 1
solver = ExplicitRK()
sir_prob = ODEProblem(sir_ode, u0, tspan, p)
sir_sol = solve(sir_prob, solver, saveat = δt)
# Define the data-driven problem
dd_prob = DataDrivenProblem(sir_sol)
# Define the basis
@parameters t
@variables (u(t))[1:3]
Ψ = Basis([u; u[1]*u[2]], u, independent_variable = t)
## Sparse regression (works)
res_sparse = solve(dd_prob, Ψ, STLSQ(),digits=1)
## Symbolic regression
eqsearch_options = SymbolicRegression.Options(binary_operators = [+, *],
loss = L1DistLoss(),
verbosity = -1, progress = false, npop = 30,
timeout_in_seconds = 60.0)
eqs = EQSearch(eq_options = eqsearch_options)
res_sr = solve(dd_prob, Ψ, eqs)
# Throws error
# ERROR: BoundsError: attempt to access 0-element Vector{Any} at index [1]
# Stacktrace:
# [1] getindex
# @ ./essentials.jl:13 [inlined]