Loss Mincut#
mincut
#
| CLASS | DESCRIPTION |
|---|---|
MinCutLoss |
Differentiable MinCut loss for spectral clustering via transition probabilities. |
Classes#
MinCutLoss(reduce='mean', sign=1.0, eps: float = torch.finfo(torch.float32).eps, ortho_weight: float = 1.0, context_prefix: str | None = None)
#
Bases: Loss
Differentiable MinCut loss for spectral clustering via transition probabilities.
Implements the normalized cut objective using a transition matrix formulation, where states are identified by maximizing within-state random walk probabilities.
The loss combines two objectives:
-
Transition probability maximization: Maximizes expected probability that random walks stay within assigned states \(-\frac{\text{Tr}(S^T T S)}{\text{Tr}(S^T S)}\)
-
Orthogonality constraint: Encourages distinct, balanced clusters using a squared penalty: \(\|\frac{S^T S}{n} - I\|_F^2\), where \(n\) is the number of samples
where \(T\) is a transition matrix (e.g., from diffusion maps), \(S\) is the soft state assignment matrix, and \(I\) is the identity matrix.
Interpretation:
The term \(\text{Tr}(S^T T S)=\sum_k\sum_{i,j} S_{ik}\cdot T_{ij} \cdot S_{jk}\) computes transition probabilities weighted by state co-assignment:
-
Symmetric case (
markov_symmetricnormalization): Maximizes expected probability that random walks stay within assigned states. Points in the same state have high mutual transition probabilities (short diffusion distances). -
Nonsymmetric case (
markov_nonsymmetric): Maximizes expected probability flow circulation within states. States form around regions where directed random walks tend to circulate, accounting for anisotropic or directional structure in the data (e.g., drift, directed graphs).
Both formulations minimize the normalized cut, but with different geometric interpretations.
The normalization type is not checked internally.
| PARAMETER | DESCRIPTION |
|---|---|
reduce
|
Reduction method (unused for this loss).
TYPE:
|
sign
|
Loss sign multiplier.
TYPE:
|
ortho_weight
|
Weight for orthogonality constraint. Controls the trade-off between minimizing cut and enforcing balanced cluster separation.
TYPE:
|
eps
|
Small constant for numerical stability in divisions.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Compute MinCut loss with orthogonality regularization. |
Source code in spectre/loss/mincut.py
Functions#
forward(context: dict, **kwargs) -> torch.Tensor
#
Compute MinCut loss with orthogonality regularization.
| PARAMETER | DESCRIPTION |
|---|---|
context
|
Dictionary containing required tensors:
TYPE:
|
**kwargs
|
Additional keyword arguments (unused).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Scalar loss combining MinCut and orthogonality objectives. |