-
Notifications
You must be signed in to change notification settings - Fork 34
ABC Routine #1413
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
ABC Routine #1413
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1413 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 92 94 +2
Lines 8968 9148 +180
==========================================
+ Hits 8968 9148 +180
Continue to review full report at Codecov.
|
MichaelClerx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't checked the tests or notebook, but this is looking quite good!
Some comments attached
pints/tests/test_abc_rejection.py
Outdated
| """ | ||
| Tests the basic methods of the ABC Rejection routine. | ||
| """ | ||
| # Set up toy model, parameter values, problem, error measure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent!
|
@phumtutum @ben18785 Just while you are still working on it, have you come across this pyabc package before? They tried applying ABC to ODE problems (and SDE too of course). Thought might be good to have a look, in particular their choice of summary statistics, if you haven't done so already. P.S.: If you think that's relevant enough, might be good to open a separate issue for it! Not saying you have to finish/include it in this PR. For some reason I couldn't find any relevant issue, so I thought I'd put a note here first. |
pints/_abc/_abc_rejection.py
Outdated
| def threshold(self): | ||
| """ | ||
| Returns threshold error distance that determines if a sample is | ||
| accepted (is ``error < threshold``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| accepted (is ``error < threshold``). | |
| accepted (if ``error < threshold``). |
|
Thanks for the changes @phumtutum , looks good to me now! @ben18785 @fcooper8472 @martinjrobins are we happy to merge this, or should we have a https://github.com/pints-team/method-merge-tests first? |
|
Discussion in meeting on 2021-12-30 Victor & Ben say: decent pre-merge tests require more stochastic problems. this is work in progress (#1417), so can't do this just yet Conclusion: Let's merge this before adding pre-merge tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some final suggestions:
- This needs a changelog.md update
- The notebook could do with a bit more text, i.e. start by showing output from the model, explain how a threshold is set, show a final posterior prediction (i.e. the range of model predictions deemed acceptable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks @phumtutum , I'm very excited to see pints branching into these topics
Suggestions on the notebook:
- Add a plot of the data
- Add a random seed. On the current problem, the performance can vary significantly across realizations of the data generation
- The rejection ABC seems a highly simplistic inference method. I ran some simulations and when the prior has a significantly higher variance than the posterior, the method is hopelessly inefficient. This rather worries me as in Bayesian inference it is not uncommon to choose a diffuse prior with a large variance. While I admit that this is a deeper topic than ought to be comprehensively addressed in an example notebook, somewhere in the notebook I think we need to give users some warning that this method does not always work, and tell them to monitor the acceptance rate to see if it is working for their problem.
|
I have addressed the comments and also fixed a small bug that was making the sampler less efficient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking really good, but the notebook can still use more text. Imagine this is someone's first attempt at running an ABC algorithm.
I'd want a bit more explanation, e.g.
This example shows you how to perform Rejection ABC on a time series from the stochastic degradation model. This model describes the .... over time. It differs from most other models in PINTS, in that it ... Then explain why ABC can deal with these kind of models.
Since it's stochastic, I'd also plot a few runs with the same parameters, and then show how that contrasts with a few runs with a 2nd set of parameters. Not because we are describing the model (that's for the model's notebook), but to show the problem faced by the sampling routine.
Now the Rejection ABC algorithm can be applied to sample parameter values. To do this, we... explain about using an error measure instead of a likelihood. Explain how you choose it (ok if this is a bit hand wavy!).
Plotting the approximate posterior compared to the actual parameter value.
-->
Finally, to see why are we plotting this?, we plot the approximate...
Then show the graph. Then explain (A) what we see in the graph (it's never as obvious to the audience, so always explain what they're looking at. also add x & y labels); (B) explain what that tells us about the problem, method, and choices we made (e.g. error)
|
You could also consider keeping this notebook short, but adding a "first-example" notebook for ABC with more background and then refer to that in the abc rejection notebook. This would be in line with the notebooks for optimisation and mcmc sampling |
|
I have decided to go with extending the current jupyter notebook instead of creating a new one. Please let me know what you think about this version of the ipynb. |
|
This PR is ready for a review, I have added the ipynb changes so that now pints.toy.stochastic.Degradation model is used. However, some set up for the unit test seems not to work. I am not sure why or if that problem is related to this PR. |
ben18785
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a few cosmetic changes to the notebook, but otherwise I'm happy for this to go in.
|
@MichaelClerx @rcw5890 are you happy for this to go in now? I've had a run through and think all's good from my end. |
|
@ben18785 Yeah I'd gotten to the point where I was happy if you were. Have not re-checked but safe to assume I still am :D |
|
Great, thanks @MichaelClerx. @rcw5890 are you happy with this one to go in? |
4082204 to
e992673
Compare
|
Fixed the merge conflicts (got a bit messy 😓 ). @rcw5890 what do you think? |
Uh oh!
There was an error while loading. Please reload this page.