DOROTHY home

Reference / API reference / dorothy / dorothy.inference / dorothy.inference.calibration

dorothy.inference.calibration

Calibration factors that scale the predicted scatter, one per head and parameter.

The trainer fits them after training (training.calibrate_uncertainties) and saves them in the checkpoint as calibration.json, which maps label source -> parameter name -> factor. They describe best_model.pth. Prediction and evaluation apply them with calibrate_scatter().

Functions

calibrate_scatter(scatter, factors, ...)

Scale one head's predicted scatter by its calibration factors.

load_calibration(checkpoint_path)

Read the calibration factors of a checkpoint directory.

save_calibration(checkpoint_path, calibration)

Write calibration factors to calibration.json in a checkpoint directory.

dorothy.inference.calibration.calibrate_scatter(scatter, factors, parameter_names)[source]

Scale one head’s predicted scatter by its calibration factors.

sigma_cal = c * s, with the factor c of each parameter.

Parameters:
  • scatter (ndarray) – Predicted scatter s, shape (n_stars, n_params).

  • factors (dict[str, float]) – Parameter name -> calibration factor c.

  • parameter_names (list[str]) – Parameter name of each column of scatter.

Returns:

The calibrated scatter, a new array with the shape and dtype of scatter.

Raises:

ValueError – If factors does not hold one factor for each name in parameter_names.

Return type:

ndarray

dorothy.inference.calibration.save_calibration(checkpoint_path, calibration)[source]

Write calibration factors to calibration.json in a checkpoint directory.

Parameters:
  • checkpoint_path (str | Path) – Checkpoint directory.

  • calibration (dict[str, dict[str, float]]) – Label source -> parameter name -> factor.

dorothy.inference.calibration.load_calibration(checkpoint_path)[source]

Read the calibration factors of a checkpoint directory.

Parameters:

checkpoint_path (str | Path) – Checkpoint directory.

Returns:

Label source -> parameter name -> factor, or None if the directory has no calibration.json.

Return type:

dict[str, dict[str, float]] | None