swiftemulator.emulators.base module

Base for all emulators. This BaseEmulator class is a specification for how all emulators should be implemented, but does not implement a specific model itself (all methods raise NotImplementedError by default). Controls on the behaviour of the emulator are passed as initialiser arguments, and the data is passed as arguments to fit_model.

class swiftemulator.emulators.base.BaseEmulator[source]

Bases: object

Base emulator for training models. Initialisation parameters are used in fit_model to specify additional parameters to the model.

ordering: Optional[List[Hashable]] = None
parameter_order: Optional[List[str]] = None
model_specification: Optional[ModelSpecification] = None
model_parameters: Optional[ModelParameters] = None
model_values: Optional[ModelValues] = None
independent_variables: Optional[array] = None
dependent_variables: Optional[array] = None
dependent_variable_errors: Optional[array] = None
emulator = None
fit_model(model_specification: ModelSpecification, model_parameters: ModelParameters, model_values: ModelValues)[source]

Fits a model to the independent and dependent variables given by the model spec, parameters, and values.

predict_values(independent: array, model_parameters: Dict[str, float]) array[source]

Predict values from the trained emulator contained within this object.

Parameters:
  • independent – Independent continuous variables to evaluate the emulator at. If the emulator is discrete, these are only allowed to be the discrete independent variables that the emulator was trained at (disregarding the additional ‘independent’ model parameters, below.)

  • np.array – Independent continuous variables to evaluate the emulator at. If the emulator is discrete, these are only allowed to be the discrete independent variables that the emulator was trained at (disregarding the additional ‘independent’ model parameters, below.)

  • model_parameters (Dict[str, float]) – The point in model parameter space to create predicted values at.

Returns:

  • dependent_predictions, np.array – Array of predictions, if the emulator is a function f, these are the predicted values of f(independent) evaluted at the position of the input model_parameters.

  • dependent_prediction_errors, np.array – Errors on the model predictions. For models where the errors are unconstrained, this is an array of zeroes.

Raises:

AttributeError – When the model has not been trained before trying to make a prediction, or when attempting to evaluate the model at disallowed independent variables.