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 fixedpars #37

Merged
merged 53 commits into from
Sep 5, 2018
Merged

Feature fixedpars #37

merged 53 commits into from
Sep 5, 2018

Conversation

yannikschaelte
Copy link
Member

Enable fixing of parameters:

  • In pypesto.Problem, fixed parameters can be specified via x_fixed_indices and x_fixed_vals. This information is then propagated via the callback method objective.handle_x_fixed() to the pypesto.Objective (which is copied) which can then take reduced vectors and internally map them back to the full input vector including fixed dimensions.
  • In this way, the Optimizer only sees the reduced vectors, which is desirable.
  • After the optimization, in the results object all vectors are mapped back to include fixed dimensions, using comfort function in pypesto.Problem.
  • The AmiciObjective one might (later) want to change to use amici's ability to fix parameters, this has not been done yet because the AmiciObjective will undergo diverse changes anyway.
  • Question: E.g. problem.lb, ub are maintained in the reduced dimension. One might want to do this differently. Atm, if one want the full vectors, one would need to call problem.get_full_vector(problem.lb, problem.x_fixed_vals)

@ICB-DCM ICB-DCM deleted a comment Aug 31, 2018
@ICB-DCM ICB-DCM deleted a comment Aug 31, 2018
@dweindl
Copy link
Member

dweindl commented Aug 31, 2018

I'd prefer if somebody who was using this feature in matlab before could review this. Who?

@codecov-io
Copy link

codecov-io commented Aug 31, 2018

Codecov Report

Merging #37 into master will decrease coverage by 0.59%.
The diff coverage is 79.31%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #37     +/-   ##
=========================================
- Coverage   82.94%   82.35%   -0.6%     
=========================================
  Files          13       15      +2     
  Lines         604      918    +314     
=========================================
+ Hits          501      756    +255     
- Misses        103      162     +59
Impacted Files Coverage Δ
pypesto/__init__.py 100% <100%> (ø) ⬆️
pypesto/objective/__init__.py 100% <100%> (ø)
pypesto/optimize/__init__.py 100% <100%> (ø) ⬆️
pypesto/visualize/parameters.py 96.77% <100%> (+0.1%) ⬆️
pypesto/result.py 77.41% <100%> (ø) ⬆️
pypesto/optimize/startpoint.py 46.87% <38.46%> (-40.63%) ⬇️
pypesto/objective/amici_objective.py 61.73% <61.73%> (ø)
pypesto/problem.py 67.9% <66.66%> (-32.1%) ⬇️
pypesto/objective/objective.py 85.55% <85.55%> (ø)
pypesto/optimize/optimize.py 90.9% <88.88%> (+21.67%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e121072...af57153. Read the comment docs.

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.

Looks good and convenient to use

@@ -21,5 +21,20 @@ Tests can be written with `pytest <https://docs.pytest.org/en/latest/>`_
or the `unittest <https://docs.python.org/3/library/unittest.html>`_ module.


Copy link
Member

Choose a reason for hiding this comment

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

Is contribute.rst recognized by github? Otherwise change to CONTRIBUTING.md to show this information in pull requests?


if x_fixed_vals is None:
x_fixed_vals = np.array([])
self.x_fixed_vals = np.array(x_fixed_vals)
Copy link
Member

Choose a reason for hiding this comment

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

Check that len(x_fixed_vals) == len(x_fixed_indices) ?

@ICB-DCM ICB-DCM deleted a comment Sep 4, 2018
@ICB-DCM ICB-DCM deleted a comment Sep 4, 2018
@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
@yannikschaelte
Copy link
Member Author

SORRY FOR THE BIG MERGE!!!

Merging with another pull request where, among other things, the objective was enabled to record a history, a couple of more changes became necessary:

  • An ObjectiveHistory object was introduced which separated the history functionality from the objective class. It would be of interest to further this separation. There are different update/reset methods (one might see these as external configurators) in the objective which enable the problem and the optimization routine to make changes to these values.

  • objective.has_fval etc. properties were introduced which compute the logic to see what the objective function supports regarding gradients, residuals and so on. These properties are now used in the Optimizers to feed their routines with available function values. It would be desirable to be a bit more flexible here with regard to finite differences. Beforehand there must have been a logic error somewhere, see also optimization seems to fail #41.

  • Certain parameters were reshuffled and put into options objects, which enables easier tossing around.

  • The optimize.minimize function was decomposed to make it better readable.

  • One design point: Now everywhere x instead of par (or pars or whatever) is used. Just because it's shorter.

One remark on the underlying idea: Objective should be rather free from dimensions, because in particular different parameter fixings can be used, and the dimensions can be read automatically from the data (bounds etc) passed to a Problem. Therefore, the problem deals with everything dimension-related, and just updates the objective accordingly. It also provides functions to switch between representations, as well as the dimension used in the optimization etc.

Please indicate if you would do sth different, e.g. the options constructs or whatever.

@yannikschaelte
Copy link
Member Author

@dweindl @FFroehlich maybe you can have a short look bc due to the merge many changes were required. I will merge to master tomorrow then hopefully. the problems with the notebooks should be resolved.

]

# check whether to append to trace
if not self.options.trace_all and fval >= self.fval_min:
Copy link
Contributor

Choose a reason for hiding this comment

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

we could check for that a bit earlier, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

At this point one remark: I found that pd.DataFrame.toc appending is really slow compared to list.append() (like 10s to <1s), but of course has better readability. Usually won't matter for our ODE problems.

print(('start ' + str(j_start) + ' failed: {0}').format(err))
optimizer_result = recover_result(objective, startpoint, err)
return optimizer_result
raise err
Copy link
Contributor

Choose a reason for hiding this comment

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

does this properly rethrow the error with full traceback? If not, I would prefer the inline version.

Copy link
Member Author

Choose a reason for hiding this comment

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

true, the stacktrace is wrong, starting in the new method. will change that.

@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
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.

Looks good. Had only a superficial look because of time-constraints though.

from .objective import Objective

try:
import amici
Copy link
Member

Choose a reason for hiding this comment

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

Here I would add a version check as mentioned in #40 . The AMICI python interface is likely to undergo some more changes, and I think it's quite annoying for the user to find out which version works

Copy link
Member Author

Choose a reason for hiding this comment

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

requires AMICI-dev/AMICI#426, then we should test that here using amici.__version__ and see here: https://stackoverflow.com/questions/11887762/how-do-i-compare-version-numbers-in-python

return self.get_error_output(sensi_orders, mode)

self.preequilibration_edata[fixedParameters]['x0'] = \
rdata['x0']
Copy link
Member

Choose a reason for hiding this comment

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

Why are we using x0 here? Why are we not using preequilibration inside amici?

Copy link
Member Author

Choose a reason for hiding this comment

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

Flag indicating whether to save the trace.
Default: False.

trace_file: str, optional
Copy link
Member

Choose a reason for hiding this comment

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

Do we need trace_save? Is this not implied by trace_file?


def _save_trace(self, finalize=False):
"""
Save to file via pickle if options.trace_save is True and other
Copy link
Member

Choose a reason for hiding this comment

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

pickle? pandas?

@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
@ICB-DCM ICB-DCM deleted a comment Sep 5, 2018
@yannikschaelte yannikschaelte merged commit c4eac3c into master Sep 5, 2018
@yannikschaelte yannikschaelte deleted the feature_fixedpars branch September 5, 2018 11:13
m-philipps pushed a commit that referenced this pull request Jun 14, 2022
Fix rule scanning for observables and sigma
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.

4 participants