Home

Awesome

PyIBS: Inverse Binomial Sampling in Python

What is it?

PyIBS is a a Python implementation of the Inverse Binomial Sampling (IBS) estimator for obtaining unbiased, efficient estimates of the log-likelihood of a model by simulation, originally implemented in MATLAB. [1]

When should I use PyIBS?

The typical scenario is the case in which you have a simulator, that is a model from which you can randomly draw synthetic observations (for a given parameter vector), but cannot evaluate the log-likelihood analytically or numerically. In other words, IBS affords likelihood-based inference for models without explicit likelihood functions (also known as implicit models).

IBS is commonly used as a part of an algorithm for maximum-likelihood estimation or Bayesian inference.

This folder contains Python implementations and examples of IBS.

Installation

PyIBS is available via pip and conda-forge.

  1. Install with:
    python -m pip install pyibs
    
    or:
    conda install --channel=conda-forge pyibs
    
    PyIBS requires Python version 3.9 or newer.

Quick start

The typical workflow of PyIBS follows four steps:

  1. Define the model function (a generative function from which you can draw synthetic observations);
  2. Setup the problem configuration (response matrix, stimulus matrix);
  3. Initialize and then run the estimator OR use the estimator as objective function in an optimization (for example Bayesian Adaptive Direct Search (PyBADS) or Variational Bayesian Monte Carlo (PyVBMC));
  4. Examine and visualize the results.

Initializing and running the estimator in step 3 only involves a couple of lines of code:

from pyibs import IBS
# ...
ibs = IBS(sample_from_model, response_matrix, design_matrix)
neg_logl = ibs(params, num_reps, additional_output, return_positive)

with input arguments for the initialization:

Input arguments for running the estimator:

The outputs are:

Code

References

  1. van Opheusden*, B., Acerbi*, L. & Ma, W.J. (2020). Unbiased and efficient log-likelihood estimation with inverse binomial sampling. PLoS Computational Biology 16(12): e1008483. (* equal contribution) (link)