sage.architecture.custom_losses.loss_functions
Filename = custom_loss_functions.py Description = Repository of custom loss functions
Created on Fri Jan 28 19:08:44 2022
__author__ = nnarenraju __copyright__ = Copyright 2021, Sage __credits__ = nnarenraju __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = nnarenraju __email__ = nnarenraju@gmail.com __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]
Github Repository: NULL
Documentation: NULL
Classes
Binary cross-entropy classification loss with MSE-based parameter |
|
Combined BCE + Heteroscedastic Regression Loss. |
Module Contents
- class BCEWithPEregLoss(regression_weight=1.0)[source]
Bases:
torch.nn.ModuleBinary cross-entropy classification loss with MSE-based parameter estimation regularisation.
The total loss is:
L = BCE(ranking_stat, class_target) + regression_weight * MSE_signal(point_estimates, pe_targets)
where the MSE term is:
computed only on signal samples (
class_target == 1),weighted per-sample by the network’s current predicted signal probability
p = sigmoid(ranking_stat)to focus regression updates on confident detections.
This is the simplest multi-task loss in Sage and does not model prediction uncertainty.
- Parameters:
regression_weight (float) – Relative weight of the regression term vs. BCE.
- Returns:
torch.Tensor, shape
(num_pe + 1,)– Stacked[total_loss, bce_loss, reg_loss, ...](one entry per point-estimate parameter plus the total).Initialize internal Module state, shared by both nn.Module and ScriptModule.
- forward(outputs, targets)[source]
Compute BCE + MSE regression loss.
- Parameters:
outputs (tuple) –
(ranking_stat, point_estimates)ranking_stat: shape(B,)or(B, 1)— raw logits.point_estimates: shape(B, num_pe)— predicted parameters.targets (torch.Tensor, shape
(B, num_pe + 1)) – Last column is the binary class label (0 = noise, 1 = signal). Preceding columns are the regression targets.
- Returns:
[total_loss, bce_loss, reg_loss].- Return type:
torch.Tensor, shape
(num_pe + 1,)
- class BCEWithPEsigmaLoss(regression_weight=1.0, coupling_weight=1.0, beta=0.5, sigma_min=0.001, sigma_max=10.0, eps=1e-06)[source]
Bases:
torch.nn.ModuleCombined BCE + Heteroscedastic Regression Loss.
BCE for classification (ranking statistic).
Regression term uses predicted mean and log-variance.
Only computed for signal entries.
Weighted per-sample by network’s predicted signal probability.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- Parameters:
- forward(outputs, targets)[source]
Compute heteroscedastic BCE + NLL regression + coupling loss.
- Parameters:
outputs (tuple) –
(ranking_stat, point_estimates)ranking_stat: shape(B,)— raw classification logits.point_estimates: shape(B, 2 * num_pe)— concatenation of predicted meansμ(firstnum_pecolumns) and rawσparameters (lastnum_pecolumns), the latter mapped to a strictly-positive std via softplus (_sigma()).targets (torch.Tensor, shape
(B, num_pe + 1)) – Last column is the binary class label; preceding columns are the physical regression targets.
- Returns:
[total_loss, bce_loss, reg_loss, coupling_loss].- Return type:
torch.Tensor, shape
(num_pe + 2,)