SMC
Sequential Monte Carlo ABC implementation with adaptive tolerance schedules.
Main Function
smc
Main SMC-ABC algorithm implementation.
approxbayescomp.smc.smc(numIters, popSize, obs, models, priors, distance=wasserstein, sumstats=None, modelPrior=None, numProcs=1, epsMin=0, seed=None, verbose=False, matchZeros=False, recycling=True, systematic=False, strictPopulationSize=False, simulatorUsesOldNumpyRNG=True, showProgressBar=False, plotProgress=False, plotProgressRefLines=None)
Run Sequential Monte Carlo Approximate Bayesian Computation (SMC-ABC).
This function implements the SMC-ABC algorithm for parameter inference and model selection. It iteratively samples from the posterior distribution by adaptively decreasing the tolerance threshold epsilon over multiple iterations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numIters
|
int
|
Number of SMC iterations to perform. More iterations allow for tighter tolerances and better approximations of the posterior. |
required |
popSize
|
int
|
Size of the particle population at each iteration. |
required |
obs
|
array_like or tuple
|
Observed data. Can be a single array or a tuple of arrays for bivariate observations. |
required |
models
|
list or callable
|
List of simulator functions (for model selection) or a single simulator function. Each simulator should take parameters and return simulated data. |
required |
priors
|
list or Prior
|
List of prior distributions (one per model) or a single prior distribution. Should be instances of IndependentPrior or IndependentUniformPrior. |
required |
distance
|
callable
|
Distance function to compare observed and simulated data. Default is wasserstein. Should take two arguments (obs, sim) and return a scalar distance. |
wasserstein
|
sumstats
|
callable
|
Summary statistics function to reduce data dimensionality. If None, raw data is used. Should take data and return summary statistics array. |
None
|
modelPrior
|
array_like
|
Prior probabilities for each model (for model selection). If None, uniform prior is used. |
None
|
numProcs
|
int
|
Number of parallel processes to use. Default is 1 (sequential). |
1
|
epsMin
|
float
|
Minimum tolerance threshold. Algorithm stops when epsilon reaches this value. Default is 0. |
0
|
seed
|
int
|
Random seed for reproducibility. If None, random seed is used. |
None
|
verbose
|
bool
|
If True, print detailed progress information. Default is False. |
False
|
matchZeros
|
bool
|
If True, reject simulations that don't match zero counts in observed data. Default is False. |
False
|
recycling
|
bool
|
If True, use particle recycling to improve efficiency. Keeps particles from the previous iteration that still pass the current tolerance, combined with newly sampled particles. Default is True. |
True
|
systematic
|
bool
|
If True, use systematic sampling for particle proposals. Default is False. |
False
|
strictPopulationSize
|
bool
|
If True, ensure exact population size (automatically True when numProcs=1). Default is False. |
False
|
simulatorUsesOldNumpyRNG
|
bool
|
If True, simulator uses legacy numpy.random functions. If False, uses new Generator API. Default is True. |
True
|
showProgressBar
|
bool
|
If True, display a progress bar during execution. Default is False. |
False
|
plotProgress
|
bool
|
If True, plot posterior distributions after each iteration. Default is False. |
False
|
plotProgressRefLines
|
dict
|
Reference lines to add to progress plots. Only used if plotProgress is True. |
None
|
Returns:
Type | Description |
---|---|
Population
|
Final population object containing particles, weights, and other information about the approximated posterior distribution. |
Examples:
Core Classes
Model
ABC model specification containing simulator, distance function, and other settings.
approxbayescomp.smc.Model = collections.namedtuple('Model', ['freq', 'sev', 'psi', 'obsFreqs'], defaults=['ones', None, None, None])
module-attribute
Population
Container for ABC population with particles, weights, and distances.
approxbayescomp.smc.Population
A Population object stores a collection of particles in the SMC procedure. Each particle is a potential theta parameter which could explain the observed data. Each theta has a corresponding weight, belongs to a specific model (as we may be fitting multiple competing models simultaneously), and has an observed distance of its fake data to the observed data.
Functions
clone()
Create a deep copy of this population object.
combine(other)
Combine this population with another to create one larger population.
drop_small_models()
Throw away the particles which correspond to models which have an extremely small population size.
drop_worst_particle()
Throw away the particle in this population which has the largest distance to the observed data.
ess()
Calculate the effective sample size (ESS) for each model in this population.
fit_kdes()
Fit a kernel density estimator (KDE) to each model's subpopulation in this population. Return all the KDEs in tuple. If there isn't enough data for some model to fit a KDE, that entry will be None.
subpopulation(keep)
Create a subpopulation of particles from this population where we keep only the particles at the locations of True in the supplied boolean vector.
total_ess()
Calculate the total effective sample size (ESS) of this population. That is, add together the ESS for each model under consideration.
Psi
Tolerance schedule class for adaptive ABC.
approxbayescomp.smc.Psi = collections.namedtuple('Psi', ['name', 'param'], defaults=['sum', 0.0])
module-attribute
Utilities
compute_psi
Compute tolerance schedule from distances.