BernoulliGLMRaw#

class bayesflow.simulators.BernoulliGLMRaw(T: int = 100, rng: Generator = None)[source]#

Bases: BenchmarkSimulator

Bernoulli GLM raw simulated benchmark. See: https://arxiv.org/pdf/2101.04653.pdf, Task T.6

Parameters:
T: int, optional, default: 100

The simulated duration of the task (eq. the number of Bernoulli draws).

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

An optional random number generator to use.

prior()[source]#

Generates a random draw from the custom prior over the 10 Bernoulli GLM parameters (1 intercept and 9 weights). Uses a global covariance matrix Cov for the multivariate Gaussian prior over the model weights, which is pre-computed for efficiency.

Returns:
paramsnp.ndarray of shape (10, )

A single draw from the prior.

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

Call self as a function.

observation_model(params: ndarray)[source]#

Simulates data from the custom Bernoulli GLM likelihood and returns the raw Bernoulli data.

Parameters:
paramsnp.ndarray of shape (10, )

The vector of model parameters (params[0] is intercept, params[i], i > 0 are weights)

Returns:
xnp.ndarray of shape (T, 10)

The full simulated set of Bernoulli draws and design matrix. Should be configured with an additional trailing dimension if the data is (properly) to be treated as a set.

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.

Parameters:
batch_shapeShape

The desired output shape, as in sample(). Will be rounded up to the next complete batch.

sample_sizeint

The number of samples in each simulated batch.

kwargs

Additional keyword arguments passed to sample().