ICB-DCM / pyPESTO

python Parameter EStimation TOolbox
https://pypesto.readthedocs.io
BSD 3-Clause "New" or "Revised" License
216 stars 47 forks source link

Customize Ensemble prediction #1257

Closed shoepfl closed 9 months ago

shoepfl commented 9 months ago

Hi there,

I looked into the ensemble predictions I get for my PEtab problems when I use the MCMC sampling pipeline of the docs, i.e. I get as many prediction_results as expected. However, each prediction result contains several entries for each time point. They are, of course, all identical as it´s a deterministic ODE. Question: Is there a way to simulate only once per paramter sample? This would reduce the computational time drastically and it makes no sense to do it repeatedly with an ODE.

The 2nd question is if there is a possibility to get ensemble predictions for time points which are not part of the measurement table. This would be cool as we sample parameters and they allow for continuous simulations and make interpolations possible.

Best,

Sebastian

Doresic commented 9 months ago

Hi Sebastian,

Thanks for the question! :) I assumed you referred to the MCMC sampling diagnostics example notebook, so I'll use variable names from there. The prediction_results attribute of ensemble_prediction returned by ensemble.predict(predictor_y, ...) contains 1 prediction result for each sample the ensemble got from MCMC. I suppose there are as many of those as you expect. Each individual prediction_results[i] for an index i has an attribute .conditions which is a list of PredictionConditionResult for each condition of your model. Each of those has an output, timepoints it has been simulated for, noise parameters etc... But the individual prediction results prediction_results[i] should not contain several simulation results for each timepoint. The several entries should be across conditions of your model, and those can have different simulation outputs, so the model has to be simulated for each. Does your model have several conditions?

Answer to 2nd question: yes, that can be done, but there are a couple of steps to do that. To your ensemble.predict(predictor, ) call you pass some kind of a predictor. That is constructed using AmiciPredictor(amici_objective, ...). If you want different timepoints for your prediction, you can alter the edatas object of the amici_objective. amici_objective.edatas contains experimental data (timepoints, data, etc...) for each of your model conditions. So amici_objective.edatas[0] is the experimental data of the first condition, etc. For each condition, you can set specific simulation timepoints using amici_objective.edatas[0].setTimepoints(timepoints), where timepoints is the array with new timepoints for that condition. That should work

Hope this helps. If you still have issues, send a bit more details of your PEtab problem and of the specific MCMC run with prediction.

Best, Domagoj

dilpath commented 9 months ago

The 2nd question is if there is a possibility to get ensemble predictions for time points which are not part of the measurement table.

Just to add to Domagoj's answer, there's a helper method [1] for what Domagoj described, which is demonstrated at the end of the notebook [2].

[1] https://pypesto.readthedocs.io/en/latest/api/pypesto.objective.html#pypesto.objective.AmiciObjective.set_custom_timepoints [2] https://github.com/ICB-DCM/pyPESTO/blob/main/doc/example/sampling_diagnostics.ipynb

shoepfl commented 9 months ago

Dear Doresic and Dilan,

thank you very much for the detailed explanation. Indeed, I had "dummy" experimental conditions that were only relevant in a model extension. This also explains why I got the exact same prediction several times.

Customizing the amici objective for user-specified time points is also very handy via the helper method. Thanks for pointing that out. The new script is already running :)

Best, Sebastian