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

New function to plot trajectory of a model with custom timepoints. #739

Merged
merged 12 commits into from
Oct 14, 2021

Conversation

PaulJonasJost
Copy link
Collaborator

Thankful for any ideas on how to get the condition id's nicely. Otherwise, anything I forgot?

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2021

Codecov Report

Merging #739 (e165754) into develop (265ba6c) will increase coverage by 43.21%.
The diff coverage is 76.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##           develop     #739       +/-   ##
============================================
+ Coverage    46.43%   89.65%   +43.21%     
============================================
  Files           99       99               
  Lines         6671     6720       +49     
============================================
+ Hits          3098     6025     +2927     
+ Misses        3573      695     -2878     
Impacted Files Coverage Δ
pypesto/visualize/model_fit.py 80.95% <76.47%> (+80.95%) ⬆️
pypesto/objective/base.py 82.08% <0.00%> (+1.49%) ⬆️
pypesto/optimize/optimizer.py 90.16% <0.00%> (+3.43%) ⬆️
pypesto/startpoint/uniform.py 100.00% <0.00%> (+5.88%) ⬆️
pypesto/optimize/optimize.py 94.11% <0.00%> (+5.88%) ⬆️
pypesto/ensemble/constants.py 92.00% <0.00%> (+6.00%) ⬆️
pypesto/optimize/options.py 100.00% <0.00%> (+10.52%) ⬆️
pypesto/objective/function.py 95.28% <0.00%> (+12.26%) ⬆️
pypesto/petab/pysb_importer.py 93.33% <0.00%> (+13.33%) ⬆️
pypesto/objective/util.py 96.55% <0.00%> (+13.79%) ⬆️
... and 56 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 265ba6c...e165754. Read the comment docs.

Copy link
Member

@dilpath dilpath left a comment

Choose a reason for hiding this comment

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

Looks great 👍

I can make the suggested changes to set_custom_timepoints within the next week, if you prefer.

Since this is especially useful for users, an example in a notebook would be appropriate.

test/visualize/test_visualize.py Outdated Show resolved Hide resolved
test/visualize/test_visualize.py Outdated Show resolved Hide resolved
test/visualize/test_visualize.py Outdated Show resolved Hide resolved
Comment on lines +112 to +114
timepoints = np.linspace(start=0,
stop=end_time,
num=n_timepoints)
Copy link
Member

Choose a reason for hiding this comment

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

Might be nice to have this handled by AmiciObjective.set_custom_timepoints so it can be used in other contexts

pypesto/visualize/model_fit.py Outdated Show resolved Hide resolved
pypesto/visualize/model_fit.py Outdated Show resolved Hide resolved
pypesto/visualize/model_fit.py Outdated Show resolved Hide resolved
stop=end_time,
num=n_timepoints)
obj = problem.objective.set_custom_timepoints(
timepoints_global=timepoints)
Copy link
Member

Choose a reason for hiding this comment

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

Typehint says timepoints can be a Sequence[np.ndarray], which would currently be specified with the timepoints argument of set_custom_timepoints instead. AmiciObjective.set_custom_timepoints could be changed to have only one argument timepoints that changes behaviour with isinstance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

pypesto/visualize/model_fit.py Outdated Show resolved Hide resolved
Copy link
Member

@yannikschaelte yannikschaelte left a comment

Choose a reason for hiding this comment

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

thanks, useful to have

# add timepoints as needed
if timepoints is None:
end_time = max(problem.objective.edatas[0].getTimepoints())
timepoints = np.linspace(start=0,
Copy link
Member

Choose a reason for hiding this comment

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

also use min(getTimepoints)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no that would be a problem again, as in that scenario having only one measured timepoints at the end would give you no trajectory again 🤔 I would say in case you do not want to start at 0, just supply the timepoints.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, how are steady-state measurements handled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

would you want a trajectory of a steady state? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

No but if there is an inf timepoint then this might ruin the np.linspace timepoints

pypesto/visualize/model_fit.py Outdated Show resolved Hide resolved
test/visualize/test_visualize.py Outdated Show resolved Hide resolved
return axes


def _time_trajectory_model_with_states(
Copy link
Member

Choose a reason for hiding this comment

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

Could move this back and put plotStateTrajectories inside an if state_indices: block. The extra computation related to states should be insignificant

pypesto/visualize/model_fit.py Outdated Show resolved Hide resolved
pypesto/visualize/model_fit.py Show resolved Hide resolved
pypesto/visualize/model_fit.py Outdated Show resolved Hide resolved
test/visualize/test_visualize.py Outdated Show resolved Hide resolved
test/visualize/test_visualize.py Outdated Show resolved Hide resolved
@dilpath
Copy link
Member

dilpath commented Oct 13, 2021

Thankful for any ideas on how to get the condition id's nicely. Otherwise, anything I forgot?

AMICI uses

petab_problem.get_simulation_conditions_from_measurement_df()

in simulate_petab and create_edatas: https://github.com/AMICI-dev/AMICI/blob/27b91dfd04966230e7af63eea977d7ebd11c6271/python/amici/petab_objective.py

@PaulJonasJost
Copy link
Collaborator Author

Thankful for any ideas on how to get the condition id's nicely. Otherwise, anything I forgot?

AMICI uses

petab_problem.get_simulation_conditions_from_measurement_df()

in simulate_petab and create_edatas: https://github.com/AMICI-dev/AMICI/blob/27b91dfd04966230e7af63eea977d7ebd11c6271/python/amici/petab_objective.py

ahh but in that case I would need to supply the petab_problem as well... will think about it a bit more and probably make an issue out of it and an extra PR. Better imo.

@PaulJonasJost PaulJonasJost marked this pull request as ready for review October 14, 2021 10:59
@PaulJonasJost PaulJonasJost merged commit 9d84d3e into develop Oct 14, 2021
@PaulJonasJost PaulJonasJost deleted the added_more_options_to_model_fit branch October 14, 2021 11:51
@yannikschaelte yannikschaelte mentioned this pull request Oct 28, 2021
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