loss_functions
This file contains the loss functions for the normalizing flow training.
Since we are combining different loss functions we have different options.
- class tensiometer.synthetic_probability.loss_functions.SharpStep(step_epoch=50, value_1=1.0, value_2=0.1, beta=0.0, **kwargs)[source]
Implement sharp stepping between two values
Initialize loss function
- class tensiometer.synthetic_probability.loss_functions.SoftAdapt_weight_loss(tau=1.0, beta=0.0, smoothing=True, smoothing_tau=20, quantity_1='val_rho_loss', quantity_2='val_ee_loss', **kwargs)[source]
Implement SoftAdapt as in arXiv:1912.12355, with optional smoothing
Initialize loss function
- class tensiometer.synthetic_probability.loss_functions.annealed_weight_loss(anneal_epoch=125, lambda_1=1.0, beta=0.0, roll_off_nepoch=10, **kwargs)[source]
Slowly go from density to evidence-error loss.
Initialize loss function
- class tensiometer.synthetic_probability.loss_functions.constant_weight_loss(alpha=1.0, beta=0.0)[source]
Combined density and evidence-error loss with fixed weights.
Initialize the fixed-weight loss.
- Parameters:
alpha – weight for the density component.
beta – additive offset applied to predicted log density.
- compute_loss(y_true, y_pred, sample_weight)[source]
Combine density and evidence-error loss.
- Parameters:
y_true – target log density.
y_pred – predicted log density.
sample_weight – weights for each sample.
- Returns:
weighted sum of loss components.
- class tensiometer.synthetic_probability.loss_functions.random_weight_loss(initial_random_epoch=0, lambda_1=1.0, beta=0.0, **kwargs)[source]
Random weighting of the two loss functions.
Initialize loss function
- class tensiometer.synthetic_probability.loss_functions.standard_loss[source]
KL-based density loss for normalizing flow training.
Standard density loss function for the normalizing flow.
- call(y_true, y_pred)[source]
Standard normalizing flow loss function is KL divergence of two abstract distributions.
- class tensiometer.synthetic_probability.loss_functions.variable_weight_loss(lambda_1=1.0, lambda_2=0.0, beta=0.0)[source]
Combined loss with trainable weights updated during training.
Initialize the variable-weight loss.
- Parameters:
lambda_1 – initial weight for the density term.
lambda_2 – initial weight for the evidence-error term.
beta – additive offset applied to predicted log density.
- compute_loss(y_true, y_pred, sample_weight)[source]
Combine density and evidence-error loss using current weights.
- Parameters:
y_true – target log density.
y_pred – predicted log density.
sample_weight – weights for each sample.
- Returns:
weighted loss value.
- compute_loss_components(y_true, y_pred, sample_weight, lambda_1=None, lambda_2=None)[source]
Compute density and evidence-error components with configurable weights.
- Parameters:
y_true – target log density.
y_pred – predicted log density.
sample_weight – weights for each sample.
lambda_1 – optional override for density weight.
lambda_2 – optional override for evidence-error weight.
- Returns:
tuple of density loss, variance of residuals, and active weights.
- update_lambda_values_on_epoch_begin(epoch, **kwargs)[source]
Update values of lambda at epoch start. Takes in every kwargs to not crowd the interface…
- Parameters:
epoch – current epoch index.
kwargs – unused passthrough arguments for compatibility.
- Raises:
NotImplementedError – expected to be overridden in subclasses.