Skip to content

A generic implementation of Approximate Bayesian Computation methods

Notifications You must be signed in to change notification settings

pbourguignon/python-abc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-abc

A generic implementation of Approximate Bayesian Computation methods, including a parallel version based on the multiprocessing module.

Basic usage

A frontend to the sampler is provided. All you need to provide is a python module exposing functions:

  • prior_r(hparams) return a sample @params@ from the prior

  • statistics_r(params) return a sample of the statistics (should be a dictionary, like @{'avg': 1.02, 'std': 0.201}@

  • load_params(filename) return the hyperparameters read from filename. Will be passed to prior_r untouched.

  • load_data(filename) return the data summary read from filename. Will be used to compute distances

  • format(param) return the string representation of the parameter for output

Library usage (OUTDATED)

The sampler comes in two flavor: a non-parallel version (in module ABC.py), mostly meant for educational purposes, and a parallel version (in module ABCmp.py). Both interfaces are mostly identical.

The main class is ABC.ABCSampler (ABCmp.ABCmp respectively). Its constructor takes references to the functions @prior@ and @statistisc@ above. Optionally, a custom distance function can also be used.

If these functions are available from a single module user_module, then a simple code like would do the job:

from user_module import some_function as f_prior
from user_module import some_other_function as f_model
from user_module import yet_another_function as f_summarize
import ABC

# Load your data
data = ...

abc = ABC.ABCSampler( data, 
                      user_module.f_prior, 
                      user_module.f_model,
                      user_module.f_summarize)

res = abc.sample(nsamples, acc_ratio)

About

A generic implementation of Approximate Bayesian Computation methods

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages