PowerLoss#
- class PowerLoss(p=2, reduction='mean', relative=False)[source]#
Bases:
LossInterface
Implementation of the Power Loss. It defines a criterion to measures the pointwise error between values in the input \(x\) and values in the target \(y\).
If
reduction
is set tonone
, the loss can be written as:\[\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad l_n = \frac{1}{D}\left[\sum_{i=1}^{D} \left| x_n^i - y_n^i \right|^p\right],\]If
relative
is set toTrue
, the relative error is computed:\[\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad l_n = \frac{ \sum_{i=1}^{D} | x_n^i - y_n^i|^p } {\sum_{i=1}^{D}|y_n^i|^p},\]where \(N\) is the batch size.
If
reduction
is notnone
, then:\[\begin{split}\ell(x, y) = \begin{cases} \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} \end{cases}\end{split}\]Initialization of the
PowerLoss
class.- Parameters:
p (int) – Degree of the Lp norm. It specifies the norm to be computed. Default is
2
(euclidean norm).reduction (str) – The reduction method for the loss. Available options:
none
,mean
,sum
. Ifnone
, no reduction is applied. Ifmean
, the sum of the loss values is divided by the number of values. Ifsum
, the loss values are summed. Default ismean
.relative (bool) – If
True
, the relative error is computed. Default isFalse
.
- forward(input, target)[source]#
Forward method of the loss function.
- Parameters:
input (torch.Tensor) – Input tensor from real data.
target (torch.Tensor) – Model tensor output.
- Returns:
Loss evaluation.
- Return type: