Loss Orthogonal#
orthogonal
#
| CLASS | DESCRIPTION |
|---|---|
OrthogonalLoss |
Orthogonality regularization loss. Encourages orthogonality by penalizing |
| FUNCTION | DESCRIPTION |
|---|---|
orthogonal_loss |
Compute orthogonality regularization loss with optional sample weighting. |
Classes#
OrthogonalLoss(reduce: Literal['sum', 'mean'] = 'mean', sign: float = 1.0, context_prefix: str | None = None, **kwargs)
#
Bases: Loss
Orthogonality regularization loss. Encourages orthogonality by penalizing deviation from identity matrix.
Optionally supports sample weighting when computing the orthogonality penalty.
The loss computes \(\|(Z Z^\top - I)\|^2\) where \(I\) is the identity matrix. When weights are provided, the loss becomes \(\|(W^{1/2} Z Z^\top W^{1/2} - I)\|^2\) where \(W\) is a diagonal matrix of weights.
| PARAMETER | DESCRIPTION |
|---|---|
reduce
|
Reduction method.
TYPE:
|
sign
|
Loss sign multiplier.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Compute orthogonality loss. |
Source code in spectre/loss/orthogonal.py
Functions#
forward(context: dict, **kwargs) -> torch.Tensor
#
Compute orthogonality loss.
| PARAMETER | DESCRIPTION |
|---|---|
context
|
Context dictionary.
TYPE:
|
**kwargs
|
Additional keyword arguments to pass to the loss function.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Orthogonality loss. |
Source code in spectre/loss/orthogonal.py
Functions#
orthogonal_loss(Z: torch.Tensor, weights: torch.Tensor | None = None, reduce: str = 'mean', sign: float = 1.0) -> torch.Tensor
#
Compute orthogonality regularization loss with optional sample weighting.
The loss computes \(\|(Z Z^\top - I)\|^2\) where \(I\) is the identity matrix. When weights are provided, the loss becomes \(\|(W^{1/2} Z Z^\top W^{1/2} - I)\|^2\) where \(W\) is a diagonal matrix of weights.
| PARAMETER | DESCRIPTION |
|---|---|
Z
|
Input matrix to regularize for orthogonality, shape
TYPE:
|
weights
|
Sample weights of shape
TYPE:
|
reduce
|
Reduction method.
TYPE:
|
sign
|
Loss sign multiplier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Orthogonality loss value. |