GaussianLinearUniform#
- class bayesflow.simulators.GaussianLinearUniform(D: int = 10, lower_bound: float = -1.0, upper_bound: float = 1.0, n_obs: int = None, obs_scale: float = 0.1, rng: Generator = None)[source]#
Bases:
BenchmarkSimulator
Gaussian Linear Uniform simulated benchmark See: https://arxiv.org/pdf/2101.04653.pdf, Task T.2
NOTE: The paper description uses a variance of 0.1 for likelihood function but the implementation uses scale = 0.1 Our implmenetation uses a default scale of 0.1 for consistency with the implementation.
- Parameters:
- D: int, optional, default: 10
The dimensionality of the Gaussian prior.
- lower_bound: float, optional, default: -1.0
The lower bound of the uniform prior.
- upper_bound: float, optional, default: 1.0
The upper bound of the uniform prior.
- n_obs: int or None, optional, default: None
The number of observations to draw from the likelihood given the location parameter params. If None, a single draw is produced.
- scale: float, optional, default: 0.1
The scale of the Gaussian 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 D-dimensional uniform prior bounded between lower_bound and upper_bound which represents the location vector of a (conjugate) Gaussian likelihood.
- Returns:
- paramsnp.ndarray of shape (D, )
A single draw from the D-dimensional uniform prior.
- observation_model(params: ndarray)[source]#
Generates batched draws from a D-dimenional Gaussian distributions given a batch of location (mean) parameters of D dimensions. Assumes a spherical convariance matrix given by scale * I_D.
- Parameters:
- paramsnp.ndarray of shape (params, D)
The location parameters of the Gaussian likelihood.
- Returns:
- xnp.ndarray of shape (params.shape[0], params.shape[1]) if n_obs is None,
else np.ndarray of shape (params.shape[0], n_obs, params.shape[1]) A single draw or a sample from a batch of Gaussians.
- 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.