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

Feature spline regularization #1222

Merged
merged 24 commits into from
Dec 7, 2023
Merged

Conversation

Doresic
Copy link
Contributor

@Doresic Doresic commented Nov 29, 2023

The main focus of the PR: add spline regularization into the spline approximation method.
Other changed stuff:

  • Due to a theoretical result that the spline parameters do not contribute to the outer gradient calculation, now I can delete all of that unnecessary code 😅
  • Small ensemble change: for some reason the parameter_ids_ensemble list was not a list, so was failing at the .index call.
  • Improvement of the calculate_quantitative_result function of the inner_calculator_collector. It was giving all nan values, because the summation in the gradient calculation was not a np.nansum. That's fixed now.
  • Fixed extraction of sensitivities of optimization parameters in the gradient calculation in the inner_calculator_collector and spline_approximation.solver gradient calculation. Previously, it was using par_sim_idx as the index for rdata. However, it can happen that for some conditions not all parameters are used (i.e. observable parameters). In that case, edatas has a plist of indices of parameters used for that condition, which has to be used as indices for the rdata object.
  • In the importer's create_objective function, if there are non-quantitative data types, the max_sensi_order should be set to 1, as higher-order derivatives are not implemented.
  • Small style change in parameters.py related to hierarchical parameter plotting.
  • Added spline regularization to the spline plotting function.

Note: Still have TODO tests of the regularization.

Initial commit with spline regularization.
The implementation of the gradient wrt theta is not completed (swapping to develop for some debugging of censored).

Additionally, small fixes of censored gradient (sigma related, not important usually).
Implemented the complete gradient, including the regularization term for the ds_dtheta
FIxed the parameter plot issue (will be in a separate PR).
Added the linear regularization to the spline visualization.
Changes that I might have to revert for the Pull request. The ensemble one might've already been pushed by Polina. The solver one completely circumvents dsdtheta gradient calculation due to some "array cannot be inf or NaN" error which pops sometimes, but it's mostly always 0 so removing it makes it easier to deal with for now. This is a big TODO, do not forget.
Fixed the par_sim_idx in the spline solver calculate gradient function. For all conditions, the rdata form is not managed by par_sim_idx, but with par_edata_indices. This is done such that if some parameters are not used in the condition (observable or noise parameters for instance) then the sensitivities wrt. them don't have to be calculated
Added the passing of the edata indices from the calculator to the solver gradient calculation.
Additionally, fixed the inner calculator collector quantitative calculation with nansum instead of a regular one (sometimes it gave only nan values because of this...)
Since I've proven that the ds_dtheta gradient contribution is always 0, we can remove all of the code that was calculating it
@codecov-commenter
Copy link

codecov-commenter commented Nov 29, 2023

Codecov Report

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

Comparison is base (160c2a8) 88.16% compared to head (03e6ef0) 83.81%.
Report is 469 commits behind head on develop.

Files Patch % Lines
pypesto/ensemble/ensemble.py 69.77% 68 Missing ⚠️
...ypesto/hierarchical/spline_approximation/solver.py 82.62% 53 Missing ⚠️
pypesto/ensemble/util.py 65.13% 38 Missing ⚠️
pypesto/hierarchical/optimal_scaling/solver.py 93.53% 26 Missing ⚠️
pypesto/history/base.py 88.57% 24 Missing ⚠️
pypesto/hierarchical/petab.py 84.56% 23 Missing ⚠️
pypesto/engine/mpi_pool.py 0.00% 22 Missing ⚠️
pypesto/hierarchical/inner_calculator_collector.py 88.51% 17 Missing ⚠️
...pesto/hierarchical/spline_approximation/problem.py 89.18% 16 Missing ⚠️
pypesto/hierarchical/problem.py 89.23% 14 Missing ⚠️
... and 16 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1222      +/-   ##
===========================================
- Coverage    88.16%   83.81%   -4.36%     
===========================================
  Files           79      148      +69     
  Lines         5257    11948    +6691     
===========================================
+ Hits          4635    10014    +5379     
- Misses         622     1934    +1312     

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

- Updated the notebook for non-linear semi-quantitative data
- fixed the max_sensi_order problem
- changed default min_diff_factor
- fix quality
@Doresic
Copy link
Contributor Author

Doresic commented Nov 30, 2023

Tests done 👍

@Doresic Doresic marked this pull request as ready for review November 30, 2023 14:02
Copy link
Member

@dweindl dweindl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sufficiently familiar with the method, therefore just some general comments.

pypesto/ensemble/ensemble.py Outdated Show resolved Hide resolved
pypesto/hierarchical/inner_calculator_collector.py Outdated Show resolved Hide resolved
pypesto/hierarchical/spline_approximation/solver.py Outdated Show resolved Hide resolved
pypesto/hierarchical/spline_approximation/solver.py Outdated Show resolved Hide resolved
pypesto/hierarchical/spline_approximation/solver.py Outdated Show resolved Hide resolved
pypesto/hierarchical/spline_approximation/solver.py Outdated Show resolved Hide resolved
pypesto/visualize/parameters.py Show resolved Hide resolved
pypesto/visualize/spline_approximation.py Show resolved Hide resolved
pypesto/visualize/spline_approximation.py Outdated Show resolved Hide resolved
test/hierarchical/test_spline.py Outdated Show resolved Hide resolved
pypesto/visualize/parameters.py Show resolved Hide resolved
pypesto/visualize/spline_approximation.py Show resolved Hide resolved
pypesto/visualize/spline_approximation.py Show resolved Hide resolved
pypesto/visualize/spline_approximation.py Show resolved Hide resolved
@stephanmg
Copy link
Contributor

General suggestion: There seems to be some files (in the hierarchical folder) which have below 80% test coverage, perhaps you can improve this with meaningful tests. If not also fine.

Copy link
Contributor

@FFroehlich FFroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add CODEOWNERS entry for doc/example/example_nonlinear_monotone.ipynb

only looked at pypesto/petab/importer.py

pypesto/petab/importer.py Show resolved Hide resolved
Added tests for untested lines in calculators
Copy link
Collaborator

@PaulJonasJost PaulJonasJost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are merge conflicts that need to be resolved. Otherwise approving since there are already extensive reviews. Thanks 👍🏼

Copy link
Contributor

@m-philipps m-philipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider adding a test for the pypesto/visualize/spline_approximation.py? Can be in a later PR to merge this soon.

@Doresic
Copy link
Contributor Author

Doresic commented Dec 7, 2023

Would you consider adding a test for the pypesto/visualize/spline_approximation.py? Can be in a later PR to merge this soon.

Yes, that would be good to have. I'll add tests in another PR.

@Doresic Doresic merged commit 530a044 into develop Dec 7, 2023
18 checks passed
@Doresic Doresic deleted the feature_spline_regularization branch December 7, 2023 10:32
This was referenced Jan 30, 2024
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.

8 participants