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

Extract common functionality from SINDy to _BaseSINDy #562

Merged
merged 10 commits into from
Oct 18, 2024

Conversation

Jacob-Stevens-Haas
Copy link
Member

@Jacob-Stevens-Haas Jacob-Stevens-Haas commented Sep 24, 2024

Begin #351

This pull request begins the abstraction of the SINDy class, which handles a lot of methods with special cases, to a variety of classes that reflect fundamental differences between problem formulations. Here, I pull out _BaseSINDy, which contains basic information about the feature library, system dimension, and printing the equations.

Future PRs will make Weak and discrete their own classes, modify feature libraries to be amenable to jax, numpy, and cvxpy arrays, and introduce the Single-Step SINDy class and associated optimizer/problem setup.

This will eventually enable SSSindy.print, as well as a simpler discrete and
SINDyPI class
SINDy.equations(), equations(), print_model() were written with extra generality
that never ended up being used.  This commit removes such generality and
throws away these indirected helper functions in favor of a single method.
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 92.66055% with 8 lines in your changes missing coverage. Please review.

Project coverage is 95.26%. Comparing base (ddf8d6d) to head (22329dd).
Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
pysindy/pysindy.py 91.37% 5 Missing ⚠️
pysindy/feature_library/base.py 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #562      +/-   ##
==========================================
- Coverage   95.28%   95.26%   -0.02%     
==========================================
  Files          38       39       +1     
  Lines        4069     4099      +30     
==========================================
+ Hits         3877     3905      +28     
- Misses        192      194       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Also:
* fix sphinx cross-linking error
* remove unused print_model
@Jacob-Stevens-Haas
Copy link
Member Author

Hey Alan, I put you as a reviewer in case you want an eye into this process. This is the beginning of what we talked about in the last meeting.

@AHsu98, @MalachiteWind, I'm going to add you as collaborators so you can review these changes too.

@Jacob-Stevens-Haas Jacob-Stevens-Haas force-pushed the simultaneous branch 2 times, most recently from 98a475a to 0482105 Compare October 18, 2024 01:56
This includes things like reduce() and coef_
This was thought to be easy, because in many cases jax arrays were an
almost drop-in replacement for numpy arrays.  However, they are far less
amenable to subclassing.  Why does this matter?

The codebase gained a lot of readability with AxesArray allowing arrays
to dynamically know what their axes meant, even after indexing changed
their shape.  However, extending AxesArray to dynamically subclass either
numpy.ndarray or jax.Array is impossible - even a static subclass of the
latter is impossible.

Long term, we will need our own metadata type that carries around an array,
it's type package (numpy or jax.numpy or cvxpy.numpy), its bidirectional
mapping between axis index and axis meaning, and maybe even something from
sympy.

Short term, we should expose our general expectations for axis definitions
as global constants.  This is still error prone, as the constants are
incorrect for arrays that have changed shape due to indexing, but will
be far more readable than magic numbers.
@Jacob-Stevens-Haas Jacob-Stevens-Haas merged commit 2ca37cb into master Oct 18, 2024
6 of 8 checks passed
@Jacob-Stevens-Haas Jacob-Stevens-Haas deleted the simultaneous branch October 18, 2024 02:15
@Jacob-Stevens-Haas
Copy link
Member Author

I'm going to merge it, and turn the last commit into an issue

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

Successfully merging this pull request may close these issues.

1 participant