Add simulator function to SBC#44
Conversation
aloctavodia
left a comment
There was a problem hiding this comment.
Thanks for this contribution, and sorry for taking so much time to answer. I added a few comments that help simplify the code (assuming they work as intended).
Co-authored-by: Osvaldo A Martin <aloctavodia@gmail.com>
|
I will check who is using numba. We are using it in a couple of places in arviz, but it should be optional there. We should have a simple example on how to use a simulator. But that can be done in a separated PR. We could also have examples here https://arviz-devs.github.io/EABM/Chapters/Simulation_based_calibration.html |
simulator function to SBCsimulator function to SBC
Bambi dependency issueThe test for Current error at 0.13.0 says: This happens because with bambi==0.13.0 the PyMC model has variables named as With bambi==0.15.0 the PyMC model has variables named as I think I definitely misunderstood the Bambi model when writing the text. I guess Do you have any input on this? I've never used Bambi (and I see you're a maintainer). Is there a way we can provide a better interface? I can imagine this being very confusing to use (at least, more confusing than the vanilla |
|
yes, |
|
CI now fails with ERROR: Ignored the following versions that require a different python version: 0.14.0 Requires-Python >=3.10,<3.13; 0.15.0 Requires-Python >=3.10,<3.13Perhaps most pragmatic decision would be to simply skip the test? |
|
Sounds good to me. It will work with the upcoming release of bambi. |
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
Description
This PR adds an optional argument
simulatorto provide a more flexible user interface by allowing SBC to be used with (1) models with no observed variables and (2) custom simulators that do not match the probabilistic model. We discussed this possibility at #4 . It’s my first time usingnumpyroand contributing to some PyMC ecosystem library, so I’m happy to learn.I haven't updated the documentation, but test cases include new functionality, and I've written the following toy example.
Toy example for
simulatorLet's say we are interested in modeling the annual dispersal of a species across a (1-dimensional) landscape. For example, we might want to estimate the average dispersal (
sigma) from a dataset ofstartandendcoordinates.The custom
simulatorfunction is useful when (a) having a model that does not have a built-in simulator (because it was a customPotentialcall, for example) or (b) when we want to simulate data from a model that is not a probabilistic model.Let's say we have a mechanistic model that describes the dispersal process. Starting and ending points were taken with a 1-year interval. Every day, an individual moves a distance drawn from an unknown distribution with finite variance. According to the central limit theorem, the total sum of the displacements (if independent) should follow a normal distribution with mean 0 and standard deviation sqrt(time) * sigma as time increases. We might wonder if 1 year is enough time for this approximation to be accurate, and we can test this using SMC for different dispersal distributions with a custom
simulatorfunction.