|
| 1 | +# API |
| 2 | + |
| 3 | +## Samplers |
| 4 | + |
| 5 | +AdvancedPS introduces a few samplers extending [AbstractMCMC](https://github.com/TuringLang/AbstractMCMC.jl). |
| 6 | +The `sample` method expects a custom type that subtypes `AbstractMCMC.AbstractModel`. |
| 7 | +The available samplers are listed below: |
| 8 | + |
| 9 | +### SMC |
| 10 | + |
| 11 | +```@docs |
| 12 | +AdvancedPS.SMC |
| 13 | +``` |
| 14 | +The SMC sampler populates a set of particles in a [`AdvancedPS.ParticleContainer`](@ref) and performs a [`AdvancedPS.sweep!`](@ref) which |
| 15 | +propagates the particles and provides an estimation of the log-evidence |
| 16 | + |
| 17 | +```julia |
| 18 | +sampler = SMC(nparticles) |
| 19 | +chains = sample(model, sampler) |
| 20 | +``` |
| 21 | + |
| 22 | +### Particle Gibbs |
| 23 | +```@docs |
| 24 | +AdvancedPS.PG |
| 25 | +``` |
| 26 | +The Particle Gibbs introduced in [^2] runs a sequence of conditional SMC steps where a pre-selected particle, the reference particle, is replayed and propagated through |
| 27 | +the SMC step. |
| 28 | + |
| 29 | +```julia |
| 30 | +sampler = PG(nparticles) |
| 31 | +chains = sample(model, sampler, nchains) |
| 32 | +``` |
| 33 | + |
| 34 | +For more detailed examples please refer to the [Examples](@ref) page. |
| 35 | + |
| 36 | +## Resampling |
| 37 | + |
| 38 | +AdvancedPS implements adaptive resampling for both [`AdvancedPS.PG`](@ref) and [`AdvancedPS.SMC`](@ref). |
| 39 | +The following resampling schemes are implemented: |
| 40 | +```@docs |
| 41 | +AdvancedPS.resample_multinomial |
| 42 | +AdvancedPS.resample_residual |
| 43 | +AdvancedPS.resample_stratified |
| 44 | +AdvancedPS.resample_systematic |
| 45 | +``` |
| 46 | + |
| 47 | +Each of these schemes is wrapped in a [`AdvancedPS.ResampleWithESSThreshold`](@ref) struct to trigger a resampling step whenever the ESS is below a certain threshold. |
| 48 | +```@docs |
| 49 | +AdvancedPS.ResampleWithESSThreshold |
| 50 | +``` |
| 51 | + |
| 52 | +## RNG |
| 53 | + |
| 54 | +AdvancedPS replays the individual trajectories instead of storing the intermediate values. This way we can build efficient samplers. |
| 55 | +However in order to replay the trajectories we need to reproduce most of the random numbers generated |
| 56 | +during the execution of the program while also generating diverging traces after each resampling step. |
| 57 | +To solve these two issues AdvancedPS uses counter-based RNG introduced in [^1] and widely used in large parallel systems see |
| 58 | +[StochasticDifferentialEquations](https://github.com/SciML/StochasticDiffEq.jl) or [JAX](https://jax.readthedocs.io/en/latest/jax-101/05-random-numbers.html?highlight=random) |
| 59 | +for other implementations. |
| 60 | + |
| 61 | +Under the hood AdvancedPS is using [Random123](https://github.com/JuliaRandom/Random123.jl) for the generators. |
| 62 | +Using counter-based RNG allows us to split generators thus creating new independent random streams. These generators are also wrapped in a [`AdvancedPS.TracedRNG`](@ref) type. |
| 63 | +The `TracedRNG` keeps track of the keys generated at every `split` and can be reset to replay random streams. |
| 64 | + |
| 65 | + |
| 66 | +```@docs |
| 67 | +AdvancedPS.TracedRNG |
| 68 | +AdvancedPS.split |
| 69 | +AdvancedPS.load_state! |
| 70 | +AdvancedPS.save_state! |
| 71 | +``` |
| 72 | + |
| 73 | +## Internals |
| 74 | +### Particle Sweep |
| 75 | + |
| 76 | +```@docs |
| 77 | +AdvancedPS.ParticleContainer |
| 78 | +AdvancedPS.sweep! |
| 79 | +``` |
| 80 | + |
| 81 | +[^1]: John K. Salmon, Mark A. Moraes, Ron O. Dror, and David E. Shaw. 2011. Parallel random numbers: as easy as 1, 2, 3. In Proceedings of 2011 International Conference for High Performance Computing, Networking, Storage and Analysis (SC '11). Association for Computing Machinery, New York, NY, USA, Article 16, 1–12. DOI:https://doi.org/10.1145/2063384.2063405 |
| 82 | +[^2]: Andrieu, Christophe, Arnaud Doucet, and Roman Holenstein. "Particle Markov chain Monte Carlo methods." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 72, no. 3 (2010): 269-342. |
0 commit comments