HybridLossΒΆ

Defined in fynance.models.loss

class HybridLoss(loss_a, loss_b, alpha=0.5, learnable=False, **kwargs)[source]

Bases: BaseLoss

Convex combination of two losses: \(\alpha L_a + (1-\alpha) L_b\).

Combines two differentiable objectives (e.g. SharpeLoss and DirectionalAccuracyLoss) with a weight alpha. The weight can be fixed or made learnable (an nn.Parameter passed through a sigmoid so it stays in (0, 1) and is optimized jointly with the model).

Parameters:
loss_a, loss_bBaseLoss

The two component losses (any callables (y_pred, y_true) -> scalar).

alphafloat, optional

Weight of loss_a in [0, 1]. Default 0.5.

learnablebool, optional

If True, alpha becomes a learnable parameter. Default False.

**kwargs

Forwarded to BaseLoss.

forward(y_pred, y_true=None)[source]

Compute the weighted sum of the two losses (scalar).