class HistoryMatching(simulator, observations, threshold=3.0, model_discrepancy=0.0, rank=1, random_seed=None)[source]#

Bases: object

History matching is a model calibration method, which uses observed data to rule out parameter values which are implausible. The implausability metric is:

\[I_i(ar{x_0}) =\]
rac{|z_i - \mathbb{E}(f_i(ar{x_0}))|}

{sqrt{ ext{Var}[z_i - mathbb{E}(f_i(ar{x_0}))]}}

Query points above a given implausibility threshold are ruled out (RO) whereas all other points are marked as not ruled out yet (NROY).

calculate_implausibility(pred_means, pred_vars=None, default_var=0.01)[source]#

Calculate implausibility scores and identify RO and NROY points.

Parameters:
  • pred_means (np.ndarray) – Array of prediction means [n_samples, n_outputs]

  • pred_vars (optional np.ndarray) – Array of prediction variances [n_samples, n_outputs]. If not provided (e.g., when predictions are made by a deterministic simulator), all variances are set to default_var.

  • default_var (int) – Prediction variance to set if not provided.

Returns:

Contains the following key, value pairs:
  • ’I’: array of implausibility scores [n_samples, n_outputs]

  • ’NROY’: list of indices of Not Ruled Out Yet points

  • ’RO’: list of indices of Ruled Out points

Return type:

dict[str, union[np.ndarray, list[int]]]

sample_nroy(nroy_samples, n_samples)[source]#

Generate new parameter samples within NROY space.

Parameters:
  • nroy_samples (np.ndarray) – Array of parameter samples in the NROY space [n_samples, n_parameters].

  • n_samples (int) – Number of new samples to generate within the NROY bounds.

Returns:

Array of parameter samples [n_samples, n_parameters].

Return type:

np.ndarray

predict(x, emulator=None)[source]#

Make predictions for a batch of inputs x. Uses self.simulator unless an emulator trained on self.simulator data is provided.

Parameters:
  • x (np.ndarray) – Array of parameter samples to simulate/emulate [n_samples, n_parameters] returned by self.simulator.sample_inputs or self.sample_nroy methods.

  • TODO (update emulator type and description below)

  • emulator (optional object) – Gaussian process emulator trained on self.simulator data.

Returns:

Arrays of predicted means and variances as well as the input data for which predictions were made succesfully.

Return type:

tuple[np.ndarray, np.ndarray, np.ndarray]

run(n_waves=3, n_samples_per_wave=100, emulator_predict=True, initial_emulator=None)[source]#
Run iterative history matching. In each wave:
  • sample parameter values to test from the NROY space
    • at the start, NROY is the entire parameter space

  • make predictions for the sampled parameters:
    • either, use the provided emulator to make predictions

    • or, use self.simulator to make predictions and update the emulator after each wave (if there are enough succesful samples)

  • compute implausability scores for predictions and further reduce NROY space

Parameters:
  • n_waves (int) – Number of iterations of history matching to run.

  • n_samples_per_wave (int) – Number of parameter samples to make predictions for in each wave.

  • emulator_predict (bool = True) – Whether to use the emulator to make predictions. If False, use self.simulator instead.

  • TODO (update emulator type and description below)

  • initial_emulator (optional object) –

    Gaussian Process emulator pre-trained on self.simulator data. - if emulator_predict=True, the GP is used to make predictions. - if emulator_predict=False, self.simulator is used to make

    predictions and the GP is retrained on the simulated data.

Returns:

  • TODO (can we simplify this?)

  • tuple[np.ndarray, np.ndarray, union[object, None]]

    • Array of all parameter samples for which predictions were made

    • Array of all implausability scores

    • a GP emulator (retrained on new data if emulator_predict=False) or None

update_emulator(existing_emulator, x, y, include_previous_data=True)[source]#

Update an existing GP emulator with new training data.

Parameters:
  • TODO (eventually this should be autoemulate.GaussianProcessExact)

  • existing_emulator (Gaussian Process from sklearn) – Trained GP emulator.

  • x (np.ndarray) – Array of parameter values to train emulator on.

  • y (np.ndarray) – Array of output values.

  • include_previous_data (bool) – Whether to include previous training data (default: True)

Return type:

Updated GP emulator

update_progress_bar(pbar, current_samples, impl_scores, nroy_samples)[source]#

Updates the progress bar.