How to use DataDrivenDiffEq.jl for simple Sparse Identification without ODE

I try to estimate an expression of y=sin(w+x) where I need to have a parameter of w. It gives an error during solve step. I know it is related to the parameter w but has no clue how to debug.

I saw examples with differential equations but not with a simple “DirectDataDrivenProblem”.

Here is my code:

using DataDrivenDiffEq
using ModelingToolkit
using DataDrivenSparse
X = rand(1,100)
Y = rand(1,100)
problem = DirectDataDrivenProblem(X, Y)
@variables u[1:1]
@parameters w[1:1]
basis = Basis([sin.(u[1]+w[1]);], u, parameters=w)
println(basis)
res = solve(problem, basis, STLSQ())
BoundsError: attempt to access 0-element view(::Vector{Float64}, :) with eltype Float64 at index [1]

Thanks for help!

Right now the Sparse Regression does not support unknown parameter values ( might be in future releases using either MAP estimation or Bayesian or MINLP ). So you need to provide a parameter value inside your basis.

problem = DirectDataDrivenProblem(X, Y, p = [1.0])

I’ll write a check for that. Sorry.

I would use symbolic regression for now.

1 Like

Thank you!That makes sense.

I will also try the symbolic regression