Utilities

Contains utility functions for calibration

This module defines various utility functions for the calibration of simulations.

class calisim.utils.utilities.EarlyStopper(patience: int = 1, min_delta: float = 0)[source]

Early stopping for training.

early_stop(validation_loss: float) bool[source]

Perform early stopping.

Parameters:

validation_loss (float) – The training validation loss.

Returns:

Whether to perform early stopping.

Return type:

bool

class calisim.utils.utilities.PriorCollection(priors: list[Distribution])[source]

A wrapper around a collection of priors.

sample(batch_shape: tuple = ()) Tensor[source]

Sample from the priors.

Parameters:

batch_shape (tuple, optional) – The batch shape of the sampled priors. Defaults to ().

Returns:

The sampled priors.

Return type:

torch.Tensor

calisim.utils.utilities.calibration_func_wrapper(X: ndarray, workflow: CalibrationWorkflowBase, observed_data: DataFrame | ndarray, parameter_names: list[str], data_types: list[ParameterDataType], calibration_kwargs: dict, wrap_values: bool = False) ndarray[source]

Wrapper function for the calibration function.

Parameters:
  • X (np.ndarray) – The parameter set matrix.

  • workflow (CalibrationWorkflowBase) – The calibration workflow.

  • observed_data (pd.DataFrame | np.ndarray) – The observed data.

  • parameter_names (list[str]) – The list of simulation parameter names.

  • data_types (list[ParameterDataType]) – The data types for each parameter.

  • calibration_kwargs (dict) – Arguments to supply to the calibration function.

  • wrap_values (bool) – Whether to wrap scalar values with a list. Defaults to False.

Returns:

The simulation output data.

Return type:

np.ndarray

calisim.utils.utilities.create_file_path(file_path: str) str[source]

Create file path if it does not exist.

Parameters:

file_path (str) – The file path to create.

Returns:

The created file path.

Return type:

str

calisim.utils.utilities.extend_X(X: ndarray, Y_rows: int) ndarray[source]

Extend the number of rows for X with a dummy index column.

Parameters:
  • X (np.ndarray) – The input matrix.

  • Y_rows (int)

Returns:

The extended input matrix with a dummy column.

Return type:

np.ndarray

calisim.utils.utilities.get_datetime_now() str[source]

Get the current datetime for now.

Returns:

The current datetime.

Return type:

str

calisim.utils.utilities.get_examples_outdir() str[source]

Get the output directory for calibration examples.

Returns:

The output directory.

Return type:

str

calisim.utils.utilities.get_simulation_uuid() str[source]

Get a new simulation uuid.

Returns:

The simulation uuid.

Return type:

str