artist.optim.loss
Classes
Initialize the base loss. |
|
Initialize the vector loss. |
|
Initialize the focal spot loss. |
|
Initialize the pixel loss. |
|
Initialize the Kullback-Leibler divergence loss. |
|
Initialize the angle loss. |
Functions
|
Calculate the mean loss per heliostat from a loss per sample. |
Module Contents
- class artist.optim.loss.Loss(loss_function: torch.nn.Module)
Initialize 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. Shape is variable.
- ground_truthtorch.Tensor
The ground truth. Shape is variable.
- **kwargsAny
Keyword arguments.
Raises
- NotImplementedError
This abstract method must be overridden.
- class artist.optim.loss.VectorLoss
Bases:
LossInitialize 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. Shape is
[number_of_samples, ...].- ground_truthtorch.Tensor
The ground truth. Shape is
[number_of_samples, ...].- **kwargsAny
Keyword arguments.
reduction_dimensionsis 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. Shape is
[number_of_samples].
- class artist.optim.loss.FocalSpotLoss(scenario: artist.scenario.scenario.Scenario)
Bases:
LossInitialize 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. Shape is
[number_of_samples, bitmap_resolution_e, bitmap_resolution_u].- ground_truthtorch.Tensor
The ground truth. Shape is
[number_of_samples, 4].- **kwargsAny
Keyword arguments.
target_area_indicesanddeviceare expected keyword arguments for the focal spot loss.
Raises
- ValueError
If expected keyword arguments are not passed.
Returns
- torch.Tensor
The focal spot loss. Shape is
[number_of_samples].
- class artist.optim.loss.PixelLoss(scenario: artist.scenario.scenario.Scenario)
Bases:
LossInitialize 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. Shape is
[number_of_samples, bitmap_resolution_e, bitmap_resolution_u].- ground_truthtorch.Tensor
The ground truth. Shape is
[number_of_samples, bitmap_resolution_e, bitmap_resolution_u].- **kwargsAny
Keyword arguments.
reduction_dimensions,target_area_indices, anddeviceare 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. Shape is
[number_of_samples].
- class artist.optim.loss.KLDivergenceLoss
Bases:
LossInitialize 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. Shape is
[number_of_samples, bitmap_resolution_e, bitmap_resolution_u].- ground_truthtorch.Tensor
The ground truth. Shape is
[number_of_samples, bitmap_resolution_e, bitmap_resolution_u].- **kwargsAny
Keyword arguments.
reduction_dimensionsis 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. Shape is
[number_of_samples].
- class artist.optim.loss.AngleLoss
Bases:
LossInitialize 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. Shape is
[number_of_samples, 4].- ground_truthtorch.Tensor
The ground truth. Shape is
[number_of_samples, 4].- **kwargsAny
Keyword arguments.
Returns
- torch.Tensor
The summed loss reduced along the specified dimensions. Shape is
[number_of_samples].
- artist.optim.loss.mean_loss_per_heliostat(loss_per_sample: torch.Tensor, number_of_samples_per_heliostat: int) torch.Tensor
Calculate the mean loss per heliostat from a loss per sample.
Parameters
- loss_per_sampletorch.Tensor
Loss per sample. Shape is
[number_of_samples].- number_of_samples_per_heliostatint
Number of samples per heliostat.
Returns
- torch.Tensor
Loss per heliostat. Shape is
[number_of_heliostats].