HammingLoss

class src.loss_func.HammingLoss[source]

Hamming loss between two permutations.

\[L_{hamm} = \sum_{i \in \mathcal{V}_1, j \in \mathcal{V}_2} \left(\mathbf{X}_{i,j} (1-\mathbf{X}^{gt}_{i,j}) + (1-\mathbf{X}_{i,j}) \mathbf{X}^{gt}_{i,j}\right)\]

where \(\mathcal{V}_1, \mathcal{V}_2\) are vertex sets for two graphs.

Firstly adopted by “Rolinek et al. Deep Graph Matching via Blackbox Differentiation of Combinatorial Solvers. ECCV 2020.”

Note

Hamming loss is defined between two discrete matrices, and discretization will in general truncate gradient. A workaround may be using the blackbox differentiation technique.

forward(pred_perm: torch.Tensor, gt_perm: torch.Tensor) torch.Tensor[source]
Parameters
  • pred_perm\((b\times n_1 \times n_2)\) predicted permutation matrix \((\mathbf{X})\)

  • gt_perm\((b\times n_1 \times n_2)\) ground truth permutation matrix \((\mathbf{X}^{gt})\)

Returns

training: bool