Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessible internals for sparse regression under SINDy #373

Open
yewalenikhil65 opened this issue Aug 25, 2022 · 10 comments
Open

Accessible internals for sparse regression under SINDy #373

yewalenikhil65 opened this issue Aug 25, 2022 · 10 comments

Comments

@yewalenikhil65
Copy link
Contributor

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 ?

@AlCap23
Copy link
Collaborator

AlCap23 commented Nov 19, 2022

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.

@yewalenikhil65
Copy link
Contributor Author

Y = hcat(map(f, eachcol(X))...)

Is this Ya candidate_matrix or basis_matrix ??

@AlCap23
Copy link
Collaborator

AlCap23 commented Nov 19, 2022

Ah, sorry! DataDrivenSparse 😅

Have to find my way through the sublibs

@yewalenikhil65
Copy link
Contributor Author

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
Copy link
Contributor Author

@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)

@AlCap23
Copy link
Collaborator

AlCap23 commented Nov 19, 2022

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

@yewalenikhil65
Copy link
Contributor Author

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

Yea.. but DataDrivenSparse is still not found .

@AlCap23
Copy link
Collaborator

AlCap23 commented Nov 19, 2022

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/

@yewalenikhil65
Copy link
Contributor Author

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)

@AlCap23
Copy link
Collaborator

AlCap23 commented Nov 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants