HierarchicalSimulator#

class bayesflow.simulators.HierarchicalSimulator(hierarchy: Sequence[Simulator])[source]#

Bases: Simulator

Initialize the hierarchical simulator with a sequence of simulators.

Parameters:
hierarchySequence[Simulator]

A sequence of simulator instances representing each level of the hierarchy. Each level’s output is used as input for the next, with increasing batch dimensions.

sample(batch_shape: tuple[int, ...], **kwargs) dict[str, ndarray][source]#

Sample from a hierarchy of simulators.

Parameters:
batch_shapeShape

A tuple where each element specifies the number of samples at the corresponding level of the hierarchy. The total batch size increases multiplicatively through the levels.

**kwargs

Additional keyword arguments passed to each simulator. These are combined with outputs from previous levels and repeated appropriately.

Returns:
output_datadict of str to np.ndarray

A dictionary containing the outputs from the entire hierarchy. Outputs are reshaped to match the hierarchical batch shape, i.e., with shape equal to batch_shape + original_shape.

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