artist.core.loss_functions

Classes

Loss

Initialize the the base loss.

VectorLoss

Initialize the vector loss.

FocalSpotLoss

Initialize the focal spot loss.

PixelLoss

Initialize the pixel loss.

KLDivergenceLoss

Initialize the Kullback-Leibler divergence loss.

AngleLoss

Initialize the angle loss.

Module Contents

class artist.core.loss_functions.Loss(loss_function: torch.nn.Module)

Initialize the the base loss.

Parameters

loss_functiontorch.nn.Module

A torch module implementing a loss.

loss_function
abstractmethod __call__(prediction: torch.Tensor, ground_truth: torch.Tensor, **kwargs: Any) torch.Tensor

Compute the loss.

Parameters

predictiontorch.Tensor

The predicted values. Tensor of variable shape.

ground_truthtorch.Tensor

The ground truth. Tensor of variable shape.

**kwargsAny

Keyword arguments.

Raises

NotImplementedError

This abstract method must be overridden.

class artist.core.loss_functions.VectorLoss

Bases: Loss

Initialize the vector loss.

__call__(prediction: torch.Tensor, ground_truth: torch.Tensor, **kwargs: Any) torch.Tensor

Compute the vector loss.

Parameters

predictiontorch.Tensor

The predicted values. Tensor of shape [number_of_samples, …].

ground_truthtorch.Tensor

The ground truth. Tensor of shape [number_of_samples, …].

**kwargsAny

Keyword arguments. The reduction_dimensions is an expected keyword argument for the vector loss.

Raises

ValueError

If expected keyword arguments are not passed.

Returns

torch.Tensor

The summed MSE vector loss reduced along the specified dimensions. Tensor of shape [number_of_samples].

class artist.core.loss_functions.FocalSpotLoss(scenario: artist.scenario.scenario.Scenario)

Bases: Loss

Initialize the focal spot loss.

Parameters

scenarioScenario

The scenario.

scenario
__call__(prediction: torch.Tensor, ground_truth: torch.Tensor, **kwargs: Any) torch.Tensor

Compute the focal spot loss.

First the focal spots of the prediction are computed, then the loss is computed and reduced along the specified dimensions.

Parameters

predictiontorch.Tensor

The predicted values. Tensor of shape [number_of_samples, bitmap_resolution_e, bitmap_resolution_u].

ground_truthtorch.Tensor

The ground truth. Tensor of shape [number_of_samples, 4].

**kwargsAny

Keyword arguments. The reduction_dimensions, target_area_mask and optionally device are expected keyword arguments for the focal spot loss.

Raises

ValueError

If expected keyword arguments are not passed.

Returns

torch.Tensor

The summed MSE focal spot loss reduced along the specified dimensions. Tensor of shape [number_of_samples].

class artist.core.loss_functions.PixelLoss(scenario: artist.scenario.scenario.Scenario)

Bases: Loss

Initialize the pixel loss.

Parameters

scenarioScenario

The scenario.

scenario
__call__(prediction: torch.Tensor, ground_truth: torch.Tensor, **kwargs: Any) torch.Tensor

Compute the pixel loss.

First the predicted bitmaps and the ground truth are normalized, then the loss is computed and reduced along the specified dimensions.

Parameters

predictiontorch.Tensor

The predicted values. Tensor of shape [number_of_samples, bitmap_resolution_e, bitmap_resolution_u].

ground_truthtorch.Tensor

The ground truth. Tensor of shape [number_of_samples, bitmap_resolution_e, bitmap_resolution_u].

**kwargsAny

Keyword arguments. The reduction_dimensions, target_area_mask and optionally device are expected keyword arguments for the pixel loss.

Raises

ValueError

If expected keyword arguments are not passed.

Returns

torch.Tensor

The summed MSE pixel loss reduced along the specified dimensions. Tensor of shape [number_of_samples].

class artist.core.loss_functions.KLDivergenceLoss

Bases: Loss

Initialize the Kullback-Leibler divergence loss.

__call__(prediction: torch.Tensor, ground_truth: torch.Tensor, **kwargs: Any) torch.Tensor

Compute the Kullback-Leibler divergence loss \(D_{\mathrm{KL}}(P \parallel Q)\).

The elements in the prediction and ground truth are normalized and shifted, to be greater or equal to zero. The kl-divergence is defined by:

\[D_{\mathrm{KL}}(P \parallel Q) = \sum_{x} P(x) \log \frac{P(x)}{Q(x)},\]

where \(P\) is the ground truth distribution and \(Q\) is the approximation or prediction of \(Q\). The kl-divergence is an asymmetric function. Switching \(P\) and \(Q\) has the following effect: \(P \parallel Q\) Penalizes extra mass in the prediction where the ground truth has none. \(Q \parallel P\) Penalizes missing mass in the prediction where the ground truth has mass.

Parameters

predictiontorch.Tensor

The predicted values. Tensor of shape [number_of_samples, bitmap_resolution_e, bitmap_resolution_u].

ground_truthtorch.Tensor

The ground truth. Tensor of shape [number_of_samples, bitmap_resolution_e, bitmap_resolution_u].

**kwargsAny

Keyword arguments. The reduction_dimensions is an expected keyword argument for the kl-divergence loss.

Raises

ValueError

If expected keyword arguments are not passed.

Returns

torch.Tensor

The summed kl-divergence loss reduced along the specified dimensions. Tensor of shape [number_of_samples].

class artist.core.loss_functions.AngleLoss

Bases: Loss

Initialize the angle loss.

__call__(prediction: torch.Tensor, ground_truth: torch.Tensor, **kwargs: Any) torch.Tensor

Compute the cosine similarity between the prediction and ground truth.

Parameters

predictiontorch.Tensor

The predicted values. Tensor of shape [number_of_samples, 4].

ground_truthtorch.Tensor

The ground truth. Tensor of shape [number_of_samples, 4].

**kwargsAny

Keyword arguments.

Returns

torch.Tensor

The summed loss reduced along the specified dimensions. Tensor of shape [number_of_samples].