LotkaVolterra#
- class bayesflow.simulators.LotkaVolterra(X0: int = 30, Y0: int = 1, T: int | None = 20, subsample: int = 10, flatten: bool = True, obs_noise: float = 0.1, dt: float = None, rng: Generator = None)[source]#
Bases:
BenchmarkSimulator
Lotka Volterra simulated benchmark. See: https://arxiv.org/pdf/2101.04653.pdf, Task T.10
- Parameters:
- X0: int, optional, default: 30
Initial number of prey species.
- Y0: int, optional, default: 1
Initial number of predator species.
- T: int, optional, default: 20
The duration (time horizon) of the simulation.
- 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.
- flatten: bool, optional, default: True
A flag to indicate whether a 1D (flatten=True) or 2D (flatten=False) representation of the simulated data is returned.
- obs_noise: float, optional, default: 0.1
The standard deviation of the log-normal likelihood.
- rng: np.random.Generator or None, optional, default: None
An optional random number generator to use.
- prior()[source]#
Generates a random draw from a 4-dimensional (independent) lognormal prior which represents the four contact parameters of the Lotka-Volterra model.
- Returns:
- paramsnp.ndarray of shape (4, )
A single draw from the 4-dimensional prior.
- observation_model(params: ndarray) ndarray [source]#
Runs a Lotka-Volterra simulation for T time steps and returns subsample evenly spaced points from the simulated trajectory, given contact parameters params.
- Parameters:
- paramsnp.ndarray of shape (2,)
The 2-dimensional vector of disease parameters.
- Returns:
- xnp.ndarray of shape (subsample, 2) or (subsample*2,) if subsample is not None,
otherwise shape (T, 2) or (T*2,) if subsample is None. The time series of simulated predator and pray populations
- 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, …)
- sample_batched(batch_shape: tuple[int, ...], *, sample_size: int, **kwargs)#
Sample the desired number of simulations in smaller batches.
Limited resources, especially memory, can make it necessary to run simulations in smaller batches. The number of samples per simulated batch is specified by sample_size.