swiftemulator.sensitivity.cross_check module

Basic test for any emulator. Leave one simulation out and test how well the emulator fits those values.

class swiftemulator.sensitivity.cross_check.CrossCheck(kernel: Optional[Kernel] = None, mean_model: Optional[MeanModel] = None, hide_progress: bool = True)[source]

Bases: object

Generator for emulators for leave one out checks.

Parameters:
  • kernel – The george kernel to use. The GPE here uses a copy of this instance. By default, this is the ExpSquaredKernel in George

  • george.kernels – The george kernel to use. The GPE here uses a copy of this instance. By default, this is the ExpSquaredKernel in George

  • mean_model – A mean model conforming to the swiftemulator mean model protocol (several pre-made models are available in the swiftemulator.mean_models module).

  • MeanModel – A mean model conforming to the swiftemulator mean model protocol (several pre-made models are available in the swiftemulator.mean_models module).

  • optional – A mean model conforming to the swiftemulator mean model protocol (several pre-made models are available in the swiftemulator.mean_models module).

  • hide_progress (bool) – Option to display a tqdm bar when creating the emulators, Default is to hide progress bar.

kernel: Optional[Kernel]
mean_model: Optional[MeanModel]
hide_progress: bool
model_specification: ModelSpecification
model_parameters: ModelParameters
model_values: ModelValues
leave_out_order: Optional[List[int]] = None
cross_emulators: Optional[Dict[Hashable, GP]] = None
build_emulators(model_specification: ModelSpecification, model_parameters: ModelParameters, model_values: ModelValues)[source]

Build a dictonary with an emulator for each simulation where the data of that simulation is left out

Note: this can take a long time

Parameters:
  • model_specification (ModelSpecification) – Full instance of the model specification.

  • model_parameters (ModelParameters) – Full instance of the model parameters.

  • model_values (ModelValues) – Full instance of the model values describing this individual scaling relation.

build_mocked_model_values_original_independent() ModelValues[source]

” Builds a mocked ModelValues container, using the cross emulators. The emulators are evaluated at the same independent variables that were ‘left out’.

Returns:

model_values – The model values container with each leave-one-out scaling relation predicted. This is also set as cross_model_values.

Return type:

ModelValues

build_mocked_model_values(emulate_at: array) ModelValues[source]

Builds a mocked ModelValues container, using the cross emulators. Similar to build_mocked_model_value_original_independent but evaluates all emulators at a consistent set of independent variables.

Parameters:

emulate_at (np.array) – independent array where the emulator is evaluated.

Returns:

model_values – The model values container with each leave-one-out scaling relation predicted. This is also set as cross_model_values.

Return type:

ModelValues

plot_results(emulate_at: array, output_path: Optional[Union[str, Path]] = None, xlabel: Optional[str] = None, ylabel: Optional[str] = None)[source]

Make a plot of each of the leave_out emulators vs the original data.

Parameters:
  • emulate_at (np.array) – independent array where the emulator is evaluated.

  • output_path (Union[str, Path], optional) – Optional, name of the folder where you want to save the figures.

  • xlabel (str, optional) – Label for horizontal axis on the resultant figure.

  • ylabel (str, optional) – Label for vertical axis on the resultant figure.

get_mean_squared(use_dependent_error: bool = False, use_y_as_error: bool = False, use_squared_difference: bool = True)[source]

Calculates the mean squared per simulation and the total mean squared of the entire set of left-out simulations.

Parameters:
  • use_dependent_error (boolean) – Use the simulation errors as weights for the mean squared calulation. Default is false.

  • use_y_as_error (boolean) – Use the model y values as the weights for the calculation.

  • use_squared_difference (boolean) – Use the simulation errors as weights for the mean squared calulation. Default is false.

Returns:

  • total_square_mean (float) – Mean (square) error across the bins.

  • mean_squared_dict (Dict[Hashable, float]) – Error per unique identifier.