DataDrivenDiffEq.jl icon indicating copy to clipboard operation
DataDrivenDiffEq.jl copied to clipboard

Accessible internals for sparse regression under SINDy

Open yewalenikhil65 opened this issue 3 years ago • 10 comments

I have precalculated estimate of candidate_matrix and also Derivative matrix… How do i use sparse regression to solve for sparse coefficient matrix ?? solve on SINDy assumes basis in symbolic form… But i have basis as candidate_matrix stored in a csv file…

Can we make little more flexible internals to achieve this ?

yewalenikhil65 avatar Aug 25 '22 11:08 yewalenikhil65

With #371 you can use the optimizer directly on the data ( see the tests in /lib/DataDrivenSR/test ).

X, DX = data
res = opt(X, DX, [options = DataDrivenCommonOptions()])

Which returns a tuple of coefficients, thresholds and iterations used.

AlCap23 avatar Nov 19 '22 06:11 AlCap23

https://github.com/SciML/DataDrivenDiffEq.jl/blob/11b21b255cac81ab4e10e006aff1af76a17bb7f9/lib/DataDrivenSR/test/runtests.jl#L14

Is this Ya candidate_matrix or basis_matrix ??

yewalenikhil65 avatar Nov 19 '22 07:11 yewalenikhil65

Ah, sorry! DataDrivenSparse 😅

Have to find my way through the sublibs

AlCap23 avatar Nov 19 '22 09:11 AlCap23

Ah, sorry! DataDrivenSparse sweat_smile

Have to find my way through the sublibs

I cannot update to 1.0.0.. possibly something clashing with existing packages ?


(SciML) pkg> st
Status `~/SciML/Project.toml`
  [c29ec348] AbstractDifferentiation v0.4.3
  [052768ef] CUDA v3.12.0
  [479239e8] Catalyst v12.3.1
⌃ [2445eb08] DataDrivenDiffEq v0.8.6
  [6748aba7] DeepEquilibriumNetworks v0.2.3
  [aae7a2af] DiffEqFlux v1.52.0
  [0c46a032] DifferentialEquations v7.6.0
  [587475ba] Flux v0.13.7
  [f6369f11] ForwardDiff v0.10.33
  [b2108857] Lux v0.4.34
  [961ee093] ModelingToolkit v8.33.1
  [429524aa] Optim v1.7.3
  [3bd65402] Optimisers v0.2.10
  [7f7a1694] Optimization v3.9.2
  [1dea7af3] OrdinaryDiffEq v6.31.2
  [91a5bcdd] Plots v1.36.2
  [1ed8b502] SciMLSensitivity v7.11.0
  [0c5d862f] Symbolics v4.13.0
  [e88e6eb3] Zygote v0.6.49
  [9a3f8284] Random
Info Packages marked with ⌃ have new versions available


yewalenikhil65 avatar Nov 19 '22 12:11 yewalenikhil65

@AlCap23 never mind.. I created newer enviornment for 1.0.0

What is DataDrivenSparse ? It is throwing following error

julia> using DataDrivenDiffEq

julia> using DataDrivenSparse
ERROR: ArgumentError: Package DataDrivenSparse not found in current path.
- Run `import Pkg; Pkg.add("DataDrivenSparse")` to install the DataDrivenSparse package.
Stacktrace:
 [1] macro expansion
   @ ./loading.jl:1163 [inlined]
 [2] macro expansion
   @ ./lock.jl:223 [inlined]
 [3] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1144

(DataDrivenDiffEq) pkg> add DataDrivenSparse
ERROR: The following package names could not be resolved:
 * DataDrivenSparse (not found in project, manifest or registry)


yewalenikhil65 avatar Nov 19 '22 13:11 yewalenikhil65

It is registered as of this morning, but might take a while. Did you do ] registry update ?

AlCap23 avatar Nov 19 '22 13:11 AlCap23

It is registered as of this morning, but might take a while. Did you do ] registry update ?

Yea.. but DataDrivenSparse is still not found .

yewalenikhil65 avatar Nov 19 '22 13:11 yewalenikhil65

Otherwise you could just use a direct DataDrivenProblem with a unit basis ( or without any basis and a sparse regression ). This will now create a basis with n states where the n is the number of features.

The docs are not quite updated, but going to the deployment of documenter might help.

https://datadriven.sciml.ai/dev/

AlCap23 avatar Nov 19 '22 13:11 AlCap23

Actually, i have basis matrix \theta pre-evaluated in matrix of numbers(these came from simulation).. My question was about to use it directly, so as to minimize || X_dot - \theta*X ||.. just exactly what SINDY does ! Our usual way in DataDrivenDiffEq is to construct basis from X state variables(from closed form functions)

yewalenikhil65 avatar Nov 19 '22 16:11 yewalenikhil65

You can just use the algorithm than or solve the problem without a basis using a direct problem with prob = DirectDataDrivenProblem(theta,DX).

AlCap23 avatar Nov 24 '22 06:11 AlCap23