yamle.utils.operation_utils module#

yamle.utils.operation_utils.average_predictions(predictions, task, weights=None)[source]#

This function is used to average the predictions.

Note that it is assumed that no gradients are passed through the predictions when this function is called.

Parameters:
  • predictions (torch.Tensor) – The predictions to average.

  • task (str) – The task to perform the averaging for.

  • weights (Optional[torch.Tensor]) – The weights to use for the averaging. If the weights are not provided, the mean is used.

Return type:

Tensor

yamle.utils.operation_utils.weighted_regression_variance(predictions, weights=None)[source]#

This function is used to calculate the regression variance.

Parameters:
  • predictions (torch.Tensor) – The predictions to calculate the variance for. The shape should be (batch_size, num_members, *prediction_dims).

  • weights (Optional[torch.Tensor]) – The weights to use for the variance calculation. If the weights are not provided, the mean is used.

Return type:

Tensor

yamle.utils.operation_utils.repeat_inputs(inputs, num)[source]#

This method is used to concatenate the num inputs into the first dimension.

Return type:

Tensor

yamle.utils.operation_utils.repeat_inputs_in_batch(batch, num)[source]#

This method is used to concatenate the num dimension into the batch dimension.

Return type:

List[Tensor]

yamle.utils.operation_utils.entropy(probabilities, dim=1)[source]#

Compute the entropy of a probability distribution. :type _sphinx_paramlinks_yamle.utils.operation_utils.entropy.probabilities: Tensor :param _sphinx_paramlinks_yamle.utils.operation_utils.entropy.probabilities: The probability distribution. :type _sphinx_paramlinks_yamle.utils.operation_utils.entropy.probabilities: torch.Tensor :type _sphinx_paramlinks_yamle.utils.operation_utils.entropy.dim: int :param _sphinx_paramlinks_yamle.utils.operation_utils.entropy.dim: The dimension to compute the entropy. Defaults to 1. :type _sphinx_paramlinks_yamle.utils.operation_utils.entropy.dim: int, optional

Return type:

Tensor

Returns:

torch.Tensor – The entropy of the distribution.

yamle.utils.operation_utils.classification_uncertainty_decomposition(samples, probabilities=False, weights=None)[source]#

Decompose the output with repsect to predictive, aleatoric and epistemic uncertainties.

Parameters:
  • samples (torch.Tensor) – The samples to decompose. The shape should be (batch_size, num_members, num_classes).

  • probabilities (bool, optional) – Whether the samples are probabilities. Defaults to False.

  • weights (Optional[torch.Tensor], optional) – The weights to use for the decomposition. Defaults to None.

Return type:

Tuple[Tensor, Tensor, Tensor]

yamle.utils.operation_utils.regression_uncertainty_decomposition(samples, weights=None)[source]#

Decompose the output with repsect to mean, predictive, aleatoric and epistemic uncertainties.

Parameters:
  • samples (torch.Tensor) – The samples to decompose. The shape should be (batch_size, num_members, 2, output_dim).

  • weights (Optional[torch.Tensor], optional) – The weights to use for the decomposition. Defaults to None.

Return type:

Tuple[Tensor, Tensor, Tensor, Tensor]