LambdaSimulator#
- class bayesflow.simulators.LambdaSimulator(sample_fn: Callable[[Sequence[int]], dict[str, any]], *, is_batched: bool = False)[source]#
Bases:
Simulator
Implements a simulator based on a sampling function.
Initialize a simulator based on a simple callable function
- Parameters:
- sample_fnCallable[[Sequence[int]], dict[str, any]]
A function that generates samples. It should accept batch_shape as its first argument (if is_batched=True), followed by keyword arguments.
- is_batchedbool, optional
Whether the sample_fn is implemented to handle batched sampling directly. If False, sample_fn will be called once per sample and results will be stacked. Default is False.
- sample(batch_shape: tuple[int, ...], **kwargs) dict[str, ndarray] [source]#
Sample using the wrapped sampling function.
- Parameters:
- batch_shapeShape
The shape of the batch to sample. Typically, a tuple indicating the number of samples, but an int can also be passed.
- **kwargs
Additional keyword arguments passed to the sampling function. Only valid arguments (as determined by the function’s signature) are used.
- Returns:
- datadict of str to np.ndarray
A dictionary of sampled outputs. Keys are output names and values are numpy arrays. If is_batched is False, individual outputs are stacked along the first axis.