Loss Functions
Similar to activation functions, two general types of loss functions have similar forms to Type-A and Type-B activations, operating on the real and imaginary or magnitude and phase, respectively.
- class complextorch.nn.modules.loss.CVCauchyError(c: float = 1)
Complex-Valued Cauchy Error Function CVCauchyError.
\[\mathcal{L}(\mathbf{x}, \mathbf{y}) = \frac{1}{2}\text{sum}( c^2 / 2 \ln(1 + |\mathbf{x} - \mathbf{y}|^2/c^2) )\]where \(c\) is typically set to unity.
Based on work from the following paper:
Ronny Hänsch. Complex-valued multi-layer perceptrons - an application to polarimetric SAR data
- class complextorch.nn.modules.loss.CVFourthPowError
Complex Fourth Power Error Function
\[\mathcal{L}(\mathbf{x}, \mathbf{y}) = \frac{1}{2}\text{sum}(|\mathbf{x} - \mathbf{y}|^4)\]Based on work from the following paper:
Ronny Hänsch. Complex-valued multi-layer perceptrons - an application to polarimetric SAR data
- class complextorch.nn.modules.loss.CVLogCoshError
Complex-Valued Log-Cosh Error Function CVLogCoshError.
\[\mathcal{L}(\mathbf{x}, \mathbf{y}) = \text{sum}(\ln(\cosh(|\mathbf{x} - \mathbf{y}|^2))\]Based on work from the following paper:
Ronny Hänsch. Complex-valued multi-layer perceptrons - an application to polarimetric SAR data
- class complextorch.nn.modules.loss.CVLogError
Complex-Valued Log Error Function CVLogError.
\[\mathcal{L}(\mathbf{x}, \mathbf{y}) = \text{sum}(|\ln(\mathbf{x}) - \ln(\mathbf{y})|^2)\]Based on work from the following paper:
J Bassey, L Qian, X Li. A Survey of Complex-Valued Neural Networks
Eq. (10)
- class complextorch.nn.modules.loss.CVQuadError
Complex-Valued Quadratic Error Function
\[\mathcal{L}(\mathbf{x}, \mathbf{y}) = \frac{1}{2}\text{sum}(|\mathbf{x} - \mathbf{y}|^2)\]Based on work from the following paper:
Ronny Hänsch. Complex-valued multi-layer perceptrons - an application to polarimetric SAR data
- class complextorch.nn.modules.loss.GeneralizedSplitLoss(loss_r: Module, loss_i: Module)
Generalized Split Loss Function
Operates on the real and imaginary parts separately and sums the losses using the operation:
\[\mathcal{L}(\mathbf{x}, \mathbf{y}) = \mathcal{L}_\mathbb{R}(\mathbf{x}_\mathbb{R}, \mathbf{y}_\mathbb{R}) + \mathcal{L}_\mathbb{I}(\mathbf{x}_\mathbb{I}, \mathbf{y}_\mathbb{I})\]
- class complextorch.nn.modules.loss.PerpLossSSIM
Perpendicular SSIM Loss Function
Based on work from the following paper:
M. L. Terpstra, M. Maspero, A. Sbrizzi, C. van den Berg. ⊥-loss: A symmetric loss function for magnetic resonance imaging reconstruction and image registration with deep learning.
See Fig. 1 for perpendicular explanation
Eq. (5)
https://www.sciencedirect.com/science/article/pii/S1361841522001566
Code: https://gitlab.com/computational-imaging-lab/perp_loss
- class complextorch.nn.modules.loss.SSIM(win_size: int = 7, k1: float = 0.01, k2: float = 0.03)
Traditional Real-Valued SSIM Loss Function
Code modified from: https://gitlab.com/computational-imaging-lab/perp_loss
- forward(x: Tensor, y: Tensor, data_range: Tensor | None = None, full: bool = False) Tensor
Computes the SSIM metric on the real-valued tensors.
- Parameters:
x (torch.Tensor) – estimated labels
y (torch.Tensor) – target/ground truth labels
data_range (Optional[torch.Tensor], optional) – Optional data range (max value of data, e.g., 255). Defaults to None.
full (bool, optional) – Compute full SSIM. Defaults to False.
- Returns:
\(\texttt{SSIM}(\mathbf{x}, \mathbf{y})\)
- Return type:
torch.Tensor
- class complextorch.nn.modules.loss.SplitL1
Split L1 Loss Function
\[L1(\mathbf{x}, \mathbf{y}) = \texttt{L1}(\mathbf{x}_\mathbb{R}, \mathbf{y}_\mathbb{R}) + \texttt{L1}(\mathbf{x}_\mathbb{I}, \mathbf{y}_\mathbb{I})\]
- class complextorch.nn.modules.loss.SplitMSE
Split MSE Loss Function
\[MSE(\mathbf{x}, \mathbf{y}) = \texttt{MSE}(\mathbf{x}_\mathbb{R}, \mathbf{y}_\mathbb{R}) + \texttt{MSE}(\mathbf{x}_\mathbb{I}, \mathbf{y}_\mathbb{I})\]
- class complextorch.nn.modules.loss.SplitSSIM(win_size: int = 7, k1: float = 0.01, k2: float = 0.03)
Split SSIM Loss Function
Returns sum of SSIM over real and imaginary parts separately.