# Model discovery using Sparse Regression on UDE model

**URL:** <https://discourse.julialang.org/t/model-discovery-using-sparse-regression-on-ude-model/106698>\
**Category:** Modelling & Simulations\
**Tags:** diffeq, sciml\
**Created:** [November 25, 2023, 1:31am UTC](https://discourse.julialang.org/t/model-discovery-using-sparse-regression-on-ude-model/106698 "2023-11-25T01:31:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsh19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gsh19/32/49350_2.png) [@gsh19](https://discourse.julialang.org/u/gsh19)\
**Post date:** [November 25, 2023, 1:31am UTC](https://discourse.julialang.org/t/model-discovery-using-sparse-regression-on-ude-model/106698/1 "2023-11-25T01:31:37Z")

</div>

Hi everyone,

I am working on modeling the unknown physics of a non-autonomous system. The system has 5 states and 2 control inputs. The dynamics of states 1 to 3 are known precisely but those of states 4 and 5 are unknown. I collected some simulation data and modeled the unknown dynamics with a feedforward neural network. Upon training, the neural network approximates the unknown physics quite well as shown below.

![Screenshot 2023-11-24 at 8.14.08 PM](https://global.discourse-cdn.com/julialang/original/3X/c/7/c717114246130ab1614da00352f1f2ab0bc3e2e8.png)  
 ![Screenshot 2023-11-24 at 8.12.04 PM](https://global.discourse-cdn.com/julialang/original/3X/1/1/11dc1e90fd950ed63d7d18b4155492dd6ea15336.png)

Now my next step is to use Sparse Regression for model disvovery. I am using the following code

```julia
@variables u[1:5] c[1:2]
u = collect(u)
c = collect(c)

h = Num[polynomial_basis(u, 2); polynomial_basis(c, 2)]
basis = Basis(h, u, controls = c)
## Ŷ is the neural network output for the sequence of states X̂
nn_problem = DirectDataDrivenProblem(X̂[:,1:end-1], Ŷ, U=U)

sampler = DataProcessing(split = 0.8, shuffle = true, batchsize = 30, rng = rng)
λs = exp10.(-10:0.1:0)
opt = STLSQ(λs)
res = solve(nn_problem, basis, opt,
            options = DataDrivenCommonOptions(data_processing = sampler, digits = 1))

nn_eqs = get_basis(res)
# Evaluate for some state and control input 
nn_eqs(X, get_parameter_map(nn_eqs), U[:,1])

```

but I get this error

```julia
MethodError: no method matching (::Basis{false, true})(::Vector{Float64}, ::Vector{Pair{Sym{Real, Base.ImmutableDict{DataType, Any}}, Float64}}, ::Vector{Float64})

```

I would really appreciate guidance to mitigate this error.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 7, 2024, 1:44pm UTC](https://discourse.julialang.org/t/model-discovery-using-sparse-regression-on-ude-model/106698/2 "2024-04-07T13:44:05Z")

</div>

I would need a full working example in order to recreate the bug and offer better help.
