approximate_bayesian_computation#

class pygom.approximate_bayesian_computation.ABC(loss_object, parameters, constraint=None)[source]#
Parameters
  • loss_object (class BaseLoss e.g. SquareLoss) –

  • parameters (list) – a list of objects of class Parameter

  • constraint (tuple) – specifies the total population size and which state’s initial condition should be changed to conserve the population size.

continue_posterior_sample(N, tol, G=1, q=None, M=None, progress=False)[source]#

Parameters (same as get_posterior_sample)#

N: integer

the number of samples in each generation

tol: float or array like

the initial tolerance or sequence of decreasing tolerances

G: integer

the number of generations used in ABC SMC/ ABC SMC MNN

q: float (0 < q < 1)

the quantile used to specify the tolerance for future generations in ABC SMC/ ABC SMC MNN

M: integer

the number of nearest neighbours used in ABC SMC MNN (M < N)

progress: bool

if True, reports the generation number, acceptance rate and threshold after each generation

get_posterior_sample(N, tol, G=1, q=None, M=None, progress=False, rerun=False)[source]#
Parameters
  • N (integer) – the number of samples in each generation

  • tol (float or array like) – the initial tolerance or sequence of decreasing tolerances

  • G (integer) – the number of generations used in ABC SMC/ ABC SMC MNN

  • q (float (0 < q < 1)) – the quantile used to specify the tolerance for future generations in ABC SMC/ ABC SMC MNN

  • M (integer) – the number of nearest neighbours used in ABC SMC MNN (M < N)

  • progress (bool) – if True, reports the generation number, acceptance rate and threshold after each generation

  • rerun (bool) – if False, this is the first attempt to obtain the posterior sample

get_posterior_sample_original(N, tol, G=1, q=None, M=None, progress=False, rerun=False)[source]#
Parameters
  • N (integer) – the number of samples in each generation

  • tol (float or array like) – the initial tolerance or sequence of decreasing tolerances

  • G (integer) – the number of generations used in ABC SMC/ ABC SMC MNN

  • q (float (0 < q < 1)) – the quantile used to specify the tolerance for future generations in ABC SMC/ ABC SMC MNN

  • M (integer) – the number of nearest neighbours used in ABC SMC MNN (M < N)

  • progress (bool) – if True, reports the generation number, acceptance rate and threshold after each generation

  • rerun (bool) – if False, this is the first attempt to obtain the posterior sample

get_tolerance(g)[source]#
Parameters

g (integer) – generation number of the ABC-SMC/MNN algorithm

plot_pointwise_predictions(plot_states=None, new_time=None, max_ncol=3)[source]#
Parameters
  • plot_states (list) – specifies which states the solution is plotted for

  • new_time (array like) – an array of new times to plot the model solution for. This temporarily overwrites the array of times used for the inference, but this change is reverted once the plotting is completed in case the user wants to run ‘continue_posterior_sample’.

  • max_ncol (integer) – specifies the maximum number of columns in the figure, purely to avoid squashed plots.

plot_posterior_histograms(plot_params=None, max_ncol=4)[source]#
Parameters
  • plot_param (list) – specifies which parameters the posterior distributions are plotted for

  • max_ncol (integer) – specifies the maximum number of columns in the figure, purely to avoid squashed plots.

plot_scatter(plot_params=None, logscale=True)[source]#
Parameters
  • plot_params (list) – specifies which parameters should be included in the pairs plot, the list should ideally contain the names of two or more parameters.

  • logscale (bool) – indicates whether parameters sampled on a log-scale should remain on a log-scale

sigma_nearest_neighbours(xx, index)[source]#
Parameters
  • xx (array like) – array of parameters

  • index (integer) – index of the parameter set the nearest neighbours will be found for

class pygom.approximate_bayesian_computation.Parameter(name, distname, *distpars, logscale)[source]#
Parameters
  • name (string specifying the name of the parameter) –

  • distname (string specifying the prior distribution) –

  • distpars (parameters of the chosen prior distribution) –

  • logscale (bool specifying whether parameter should be sampled on a log scale) –

pygom.approximate_bayesian_computation.create_loss(loss_type, parameters, ode, x0, t0, t, y, state_name, state_weight=None, sigma=None)[source]#

Parameters (see also class BaseLoss)#

loss_type: class BaseLoss parameters: list

a list of objects of class Parameter

ode: class DeterministicOde

the ode class in this package

x0: numeric

initial time

t0: numeric

initial value

t: array like

time points where observations were made

y: array like

observations

state_name: str or list

the state(s) which the observations came from

state_weight: array like

weight for the observations

sigma: numeric

sigma for NormalLoss function

pygom.approximate_bayesian_computation.get_function(str)[source]#
Parameters

str (name of the chosen prior distribution) –