GaussianLinear#
- class bayesflow.simulators.GaussianLinear(D: int = 10, prior_scale: float = 0.1, n_obs: int = None, obs_scale: float = 0.1, rng: Generator = None)[source]#
Bases:
BenchmarkSimulator
Gaussian Linear simulated benchmark See: https://arxiv.org/pdf/2101.04653.pdf, Task T.1
NOTE: The paper description uses a variance of 0.1 for the prior and likelihood 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 distribution.
- prior_scale: float, optional, default: 0.1
The scale of the Gaussian prior.
- n_obs: int or None, optional, default: None
The number of observations to draw from the likelihood given the location parameter params. If n obs is None, a single draw is produced.
- obs_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 Gaussian prior distribution with a spherical scale matrix given by sigma * I_D. Represents the location vector of a (conjugate) Gaussian likelihood.
- Returns:
- paramsnp.ndarray of shape (D, )
A single draw from the D-dimensional Gaussian 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.