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

Make TrappingSR3 a subclass of ConstrainedSR3 #435

Merged
merged 14 commits into from
Apr 14, 2024

Conversation

Jacob-Stevens-Haas
Copy link
Member

This PR simplifies TrappingSR3, reducing it by about 250 lines. It changes the base class to ConstrainedSR3, deferring all calls to cvxpy to that superclass. It also makes the main algorithm clearer, so that its easier to see how different initialization arguments affect the choice of math involved (mostly because I couldn't quite understand this from the docstring). As a related effect, the _reduce method more closely matches the algorithm in the paper.

The plan is to eventually utilize superclass for combining and applying constraints, since that class is capable of doing both equality and inequality constraints, which will make it easier to include the constraints and helper functions of example 8 into trapping_sr3.py

Change base class from SR3 to ConstrainedSR3
Also: Rename single-letter variable to meaningful
If False, code skips all optimization methods.  It isn't used in any example,
it's just a vestige of earlier work.  The section commented "update w" doesn't
modify any variables called "w"
Also removes tolerance specifications from backup optimization due to name
changes

In some versions of SCS, (e.g. 3.2.3), the change from max_iter to max_iters
raises a ValueError instead of a TypeError
Goal is to make it clear when trapping is solving for coefficients and when it's
solving for the updated trapping center.

* Renamed "m" "trap_ctr".
* Extracts solving for coef_prev from solve_cvxpy_direct, renaming latter to make
    its reduced role in solving for just the trapping center
* Removes unused args
The "failed to converge warning" was emitted whenever max iteration was reached,
regardless of whether convergence was achieved.  The previous test only was able
to assert convergence warning because it was written to successfully converge
after 1 iteration, with a max iteration of 1.

Also, removed test_sr3_warn and incorporated into test_fit_warn, with which it
was 95% redundant already.  This also required setting some variables outside
a loop in order to access them later - a required practice for mypy and other
type checkers.
This allows them to be used by set_params, part of the scikit-learn API
…ping

This makes the algorithm in code look like algorithm in paper
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (2633ee0) 93.87% compared to head (639ea9d) 94.31%.
Report is 1 commits behind head on master.

Files Patch % Lines
pysindy/optimizers/trapping_sr3.py 93.39% 7 Missing ⚠️
pysindy/optimizers/constrained_sr3.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
+ Coverage   93.87%   94.31%   +0.43%     
==========================================
  Files          37       37              
  Lines        3626     3554      -72     
==========================================
- Hits         3404     3352      -52     
+ Misses        222      202      -20     

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

@Jacob-Stevens-Haas
Copy link
Member Author

Preempted by #459 , converting back to draft.

@Jacob-Stevens-Haas Jacob-Stevens-Haas marked this pull request as draft January 16, 2024 14:48
@Jacob-Stevens-Haas Jacob-Stevens-Haas marked this pull request as ready for review April 5, 2024 17:03
@Jacob-Stevens-Haas Jacob-Stevens-Haas merged commit 80171b7 into master Apr 14, 2024
6 checks passed
@Jacob-Stevens-Haas Jacob-Stevens-Haas deleted the trapping-helper branch April 14, 2024 02:22
jpcurbelo pushed a commit to jpcurbelo/pysindy_fork that referenced this pull request Apr 30, 2024
Make TrappingSR3 a subclass of ConstrainedSR3
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