hinge_loss
- pmrf.math.losses.hinge_loss(y_true: Array, y_pred: Array, operator: Literal['<', '<=', '>', '>=', '==', '='], weight: float | Array = 1.0, mask: Array | None = None, base_loss: str | Callable = 'rmse', multioutput: str | Array | Callable = 'uniform_average', **kwargs) Array
Applies a differentiable one-sided constraint (hinge) before evaluating a base metric.
Utilizes a differentiable clamping technique to ensure the optimizer only experiences a penalty gradient when the constraint is violated.
- Parameters:
y_true (jnp.ndarray) – The target threshold or ground truth values.
y_pred (jnp.ndarray) – The estimated circuit feature values.
operator (Literal['<', '<=', '>', '>=', '==', '=']) – The logical constraint operator defining the goal boundary.
weight (float | jnp.ndarray, default=1.0) – A scalar or array multiplier to scale the importance of the penalty.
mask (jnp.ndarray | None, default=None) – A boolean array filtering which data points apply to this loss.
base_loss (str | Callable, default='rmse') – The underlying mathematical metric applied to the constraint residual. Can be a string alias (resolved via LOSS_LOOKUP) or a custom callable.
**kwargs – Key-word arguments to forward to the underlying loss function.
- Returns:
The calculated scalar or array penalty.
- Return type:
jnp.ndarray
- Raises:
ValueError – If an unknown constraint operator is provided.