SIR#

class bayesflow.simulators.SIR(N: float = 1000000.0, T: int = 160, I0: float = 1.0, R0: float = 0.0, subsample: int = None, total_count: int = 1000, scale_by_total: bool = True, rng: Generator = None)[source]#

Bases: BenchmarkSimulator

SIR simulated benchmark See: https://arxiv.org/pdf/2101.04653.pdf, Task T.9

NOTE: the simulator scales outputs between 0 and 1.

Parameters:
N: float, optional, default: 1e6

The size of the simulated population.

T: int, optional, default: 160

The duration (time horizon) of the simulation.

I0: float, optional, default: 1.0

The number of initially infected individuals.

R0: float, optional, default: 0.0

The number of initially recovered individuals.

subsample: int 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_count: int, 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_total: bool, optional, default: True

Scales the outputs by total_count if set to True.

rng: np.random.Generator or None, optional, default: None

An optional random number generator to use.

prior()[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.

Returns:
paramsnp.ndarray of shape (2, )

A single draw from the 2-dimensional prior.

__call__(**kwargs) dict[str, ndarray]#

Call self as a function.

observation_model(params: ndarray)[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) params.

Parameters:
paramsnp.ndarray of shape (2,)

The 2-dimensional vector of disease parameters.

Returns:
xnp.ndarray of shape (subsample, ) or (T, 1) 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.

rejection_sample(batch_shape: tuple[int, ...], predicate: Callable[[dict[str, ndarray]], ndarray], *, axis: int = 0, sample_size: int = None, **kwargs) dict[str, ndarray]#
sample(batch_shape: tuple[int, ...], **kwargs) dict[str, ndarray]#

Runs simulated benchmark and returns batch_size parameter and observation batches

Parameters:
batch_shape: tuple

Number of parameter-observation batches to simulate.

Returns:
dict[str, np.ndarray]: simulated parameters and observables

with shapes (batch_size, …)