autoemulate.simulations.base#
- class Simulator(parameters_range, output_names, log_level='progress_bar')[source]#
Bases:
ABC
,ValidationMixin
Base class for simulations. All simulators should inherit from this class.
This class provides the interface and common functionality for different simulation implementations.
- property parameters_range#
Dictionary mapping input parameter names to their (min, max) ranges.
- property param_names#
List of parameter names.
- property param_bounds#
List of parameter bounds.
- property output_names#
List of output parameter names.
- property in_dim#
Input dimensionality.
- property out_dim#
Output dimensionality.
- sample_inputs(n_samples, random_seed=None, method='lhs')[source]#
Generate random samples using Quasi-Monte Carlo methods.
Available methods are Sobol or Latin Hypercube Sampling. For overview, see the scipy documentation: https://docs.scipy.org/doc/scipy/reference/stats.qmc.html
- Parameters:
- Returns:
Parameter samples (column order is given by self.param_names)
- Return type:
TensorLike
- forward(x, allow_failures=True)[source]#
Generate samples from input data using the simulator.
Combines the abstract method _forward with some validation checks. If there is a failure during the forward pass of the simulation, the error is logged and None is returned.
- Parameters:
x (TensorLike) – Input tensor of shape (n_samples, self.in_dim).
allow_failures (bool) – Whether to allow failures during simulation. Default is True. When true, failed simulations will return None instead of raising an error. When False, error is raised.
- Returns:
Simulated output tensor. None if the simulation failed.
- Return type:
TensorLike
- forward_batch(x, allow_failures=True)[source]#
Run multiple simulations.
If allow_failures is False, failed simulations will raise an error. Otherwise, failed simulations are skipped, and only successful results are returned along with their corresponding input parameters.
- Parameters:
x (TensorLike) – Tensor of input parameters to make predictions for.
allow_failures (bool) – Whether to allow failures during simulation. Default is True. When true, failed simulations will return None instead of raising an error. When False, error is raised.
- Returns:
Tuple of (simulation_results, valid_input_parameters). Only successful simulations are included.
- Return type:
tuple[TensorLike, TensorLike]