Skip to content

Conversation

@phumtutum
Copy link
Contributor

@phumtutum phumtutum commented Nov 8, 2021

  • Added an ABC base class + controller
  • Added an implementation of the ABC rejection algorithm
  • Added tests for those classes
  • Added a jupyter notebook to highlight the rejection algorithm, here is the resulting plot:
    output

@codecov
Copy link

codecov bot commented Nov 8, 2021

Codecov Report

Merging #1413 (95c910e) into master (ba6d5ce) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            master     #1413    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           92        94     +2     
  Lines         8968      9148   +180     
==========================================
+ Hits          8968      9148   +180     
Impacted Files Coverage Δ
pints/__init__.py 100.00% <100.00%> (ø)
pints/_abc/__init__.py 100.00% <100.00%> (ø)
pints/_abc/_abc_rejection.py 100.00% <100.00%> (ø)

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 ba6d5ce...95c910e. Read the comment docs.

@phumtutum phumtutum requested a review from ben18785 November 8, 2021 13:29
Copy link
Member

@MichaelClerx MichaelClerx left a 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

"""
Tests the basic methods of the ABC Rejection routine.
"""
# Set up toy model, parameter values, problem, error measure
Copy link
Member

Choose a reason for hiding this comment

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

Indent!

@chonlei
Copy link
Member

chonlei commented Nov 26, 2021

@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.

def threshold(self):
"""
Returns threshold error distance that determines if a sample is
accepted (is ``error < threshold``).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
accepted (is ``error < threshold``).
accepted (if ``error < threshold``).

@MichaelClerx
Copy link
Member

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?

@MichaelClerx
Copy link
Member

MichaelClerx commented Nov 30, 2021

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

@MichaelClerx MichaelClerx requested review from MichaelClerx and rccreswell and removed request for ben18785 November 30, 2021 12:50
Copy link
Member

@MichaelClerx MichaelClerx left a 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)

Copy link
Contributor

@rccreswell rccreswell left a 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.

@phumtutum
Copy link
Contributor Author

I have addressed the comments and also fixed a small bug that was making the sampler less efficient.

Copy link
Member

@MichaelClerx MichaelClerx left a 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)

@MichaelClerx
Copy link
Member

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

@phumtutum
Copy link
Contributor Author

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.

@phumtutum
Copy link
Contributor Author

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 ben18785 self-requested a review March 15, 2022 18:52
Copy link
Collaborator

@ben18785 ben18785 left a 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.

@ben18785
Copy link
Collaborator

@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.

@MichaelClerx
Copy link
Member

@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

@ben18785
Copy link
Collaborator

Great, thanks @MichaelClerx. @rcw5890 are you happy with this one to go in?

@MichaelClerx
Copy link
Member

Fixed the merge conflicts (got a bit messy 😓 ). @rcw5890 what do you think?

@rccreswell rccreswell merged commit 7380440 into master Mar 22, 2022
@MichaelClerx MichaelClerx deleted the i-96-abc-routine branch March 22, 2022 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants