bayesflow.benchmarks.sir module#

bayesflow.benchmarks.sir.prior(rng=None)[source]#

Generates a random draw from a 2-dimensional (independent) lognormal prior which represents the contact and recovery rate parameters of a basic SIR model.

Parameters:
rngnp.random.Generator or None, default: None

An optional random number generator to use.

Returns:
thetanp.ndarray of shape (2,)

A single draw from the 2-dimensional prior.

bayesflow.benchmarks.sir.simulator(theta, N=1000000.0, T=160, I0=1.0, R0=0.0, subsample=10, total_count=1000, scale_by_total=True, rng=None)[source]#

Runs a basic SIR model simulation for T time steps and returns subsample evenly spaced points from the simulated trajectory, given disease parameters (contact and recovery rate) theta.

See https://arxiv.org/pdf/2101.04653.pdf, Benchmark Task T.9.

Note, that the simulator will scale the outputs between 0 and 1.

Parameters:
thetanp.ndarray of shape (2,)

The 2-dimensional vector of disease parameters.

Nfloat, optional, default: 1e6 = 1 000 000

The size of the simulated population.

TT, optional, default: 160

The duration (time horizon) of the simulation.

I0float, optional, default: 1.

The number of initially infected individuals.

R0float, optional, default: 0.

The number of initially recovered individuals.

subsampleint or None, optional, default: 10

The number of evenly spaced time points to return. If None, no subsampling will be performed and all T timepoints will be returned.

total_countint, optional, default: 1000

The N parameter of the binomial noise distribution. Used just for scaling the data and magnifying the effect of noise, such that max infected == total_count.

scale_by_totalbool, optional, default: True

Scales the outputs by total_count if set to True.

rngnp.random.Generator or None, default: None

An optional random number generator to use.

Returns:
xnp.ndarray of shape (subsample,) or (T,) if subsample=None

The time series of simulated infected individuals. A trailing dimension of 1 should be added by a BayesFlow configurator if the data is (properly) to be treated as time series.

bayesflow.benchmarks.sir.configurator(forward_dict, mode='posterior', as_summary_condition=False)[source]#

Configures simulator outputs for use in BayesFlow training.