# Constrained SINDy

**URL:** <https://discourse.julialang.org/t/constrained-sindy/83105>\
**Category:** General Usage\
**Created:** [June 21, 2022, 7:19am UTC](https://discourse.julialang.org/t/constrained-sindy/83105 "2022-06-21T07:19:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccccc](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@ccccc](https://discourse.julialang.org/u/ccccc)\
**Post date:** [June 21, 2022, 7:19am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/1 "2022-06-21T07:19:26Z")

</div>

I know many of the differential equations in a DAE already, and I’m trying to identify the others, using DataDrivenDiffEq. I’m not sure how to constrain the model so that it doesn’t search for all of the equations. Does anyone know how to do this?  
Thanks

---

<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:** [June 21, 2022, 9:28am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/2 "2022-06-21T09:28:46Z")

</div>

Use a singular mass matrix?

---

<div class="post-metadata">

**Author:** ![ccccc](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@ccccc](https://discourse.julialang.org/u/ccccc)\
**Post date:** [June 21, 2022, 10:40am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/3 "2022-06-21T10:40:07Z")

</div>

Thanks. Only some of the known equations are the algebraic constraints. Is there a way to just type in which equations I already know?

p.s. I’m using modelingtoolkit with structural\_simplify, it seems the same as the mass matrix format…?

---

<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:** [June 22, 2022, 10:39pm UTC](https://discourse.julialang.org/t/constrained-sindy/83105/4 "2022-06-22T22:39:20Z")

</div>

The universal differential equations paper shows how using a neural network intermediate allows for introducing known knowledge into the symbolic regression process:

> **[Universal Differential Equations for Scientific Machine Learning](https://arxiv.org/abs/2001.04385)**
>
> In the context of science, the well-known adage "a picture is worth a thousand words" might well be "a model is worth a thousand datasets." In this manuscript we introduce the SciML software ecosystem as a tool for mixing the information of physical...

That’s a very general approach to it. I think for just the simplest ODE case you can probably do it via mass matrices, yes, but at least the NN tricks will work in any case.

@Julius_Martensen do you have an example of direct constraints?

---

<div class="post-metadata">

**Author:** ![ccccc](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@ccccc](https://discourse.julialang.org/u/ccccc)\
**Post date:** [June 23, 2022, 6:15am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/5 "2022-06-23T06:15:20Z")

</div>

This looks completely amazing, thank you for making this! There are so many possibilities with this…

Maybe I’m just not imagining well what can be done with mass matrices. But this is all new for me, so i’ll have a think. Anyway, I definitely want to learn this NN approach so i’ll start on that.

---

<div class="post-metadata">

**Author:** ![Julius\_Martensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/julius_martensen/32/17077_2.png) [@Julius\_Martensen](https://discourse.julialang.org/u/Julius_Martensen)\
**Post date:** [June 23, 2022, 6:35am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/6 "2022-06-23T06:35:17Z")

</div>

There is [a paper](https://arxiv.org/pdf/1611.03271.pdf) on using direct constraints for the equations, I just haven’t got the time to implement this properly. Additionally, you might consider using Convex.jl or even JuMP for more complex equations.

If you know some of the equations before, I would just preprocess the data as much as possible ( so only create a problem for the unknown equations ). Also, a splitting for the constraints would make sense and try to infer those with an implicit sparse regression.

---

<div class="post-metadata">

**Author:** ![ccccc](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@ccccc](https://discourse.julialang.org/u/ccccc)\
**Post date:** [June 23, 2022, 7:16am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/7 "2022-06-23T07:16:15Z")

</div>

Thanks, i’ll check these out and try to figure out a way…

---

<div class="post-metadata">

**Author:** ![MarcusGalea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcusgalea/32/43689_2.png) [@MarcusGalea](https://discourse.julialang.org/u/MarcusGalea)\
**Post date:** [April 24, 2024, 11:21am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/8 "2024-04-24T11:21:38Z")

</div>

Has a framework for direct constraints been implemented into DataDrivenDiffEq?

---

<div class="post-metadata">

**Author:** ![Julius\_Martensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/julius_martensen/32/17077_2.png) [@Julius\_Martensen](https://discourse.julialang.org/u/Julius_Martensen)\
**Post date:** [May 10, 2024, 5:34am UTC](https://discourse.julialang.org/t/constrained-sindy/83105/9 "2024-05-10T05:34:07Z")

</div>

Nope. We are (still) in the early stages of a successor for DataDrivenDiffEq.jl , which will rather resort to use Optimization.jl for solving all related inference problems ( e.g. the MINLP formulation of SINDy ). With this, constraints are naturally supported and it works in my experience better than all of the other methods w.r.t. sparsity of the solution.

However, I need to finish my thesis 😅
