Losses

weavenet.loss.loss_one2one_correlation(mab, mba_t=None)[source]

Evaluates loss to maintain \(m\) to be a doubly-stochastic matrix, which is a contiously-relaxed one-to-one matching.

\[\mathcal{L}_{\rm one2one}(m) = 1 - \frac{N+M}{2NM} \sum_{(i,j)\in N\times M} (\frac{m_{i,j}}{||m_{*,j}||_2} * \frac{m_{i,j}}{||m_{i,*}||_2})\]
Shape:
  • mab: \((\ldots, N, M)\)

  • mba: \((\ldots, N, M)\)

  • output: \((\ldots, )\)

Parameters
  • mab (Tensor) – a matching from side a to b.

  • mba – a matching from side b to a transposed to have the same shape to mab.

  • mba_t (Optional[Tensor]) –

Returns

loss

Return type

Tensor

.. note::

The coefficient \(\frac{N+M}{2NM}\) can be \(\frac{1}{\max(N,M)}\) for \(N\neq M\) cases?

weavenet.loss.loss_one2one_correlation_exp(mab, mba_t=None)[source]

Evaluates loss based on loss_one2one_correlation() but with exp(mab) and exp(mba).

Shapes are same with loss_one2one_correlation()

Parameters
  • mab (Tensor) – a matching from side a to b.

  • mba – a matching from side b to a transposed to have the same shape to mab.

  • mba_t (Optional[Tensor]) –

Returns

loss

Return type

Tensor

weavenet.loss.loss_one2many_penalty(mab, mba_t=None)[source]

Evaluates loss based on the value more than 1.0 for each row and column.

Shapes are same with loss_one2one_correlation()

Args:

mab: a matching from side a to b. mba: a matching from side b to a transposed to have the same shape to mab.

Returns:

loss

Parameters
  • mab (Tensor) –

  • mba_t (Optional[Tensor]) –

Return type

Tensor

weavenet.loss.loss_stability(m, sab, sba_t)[source]

Evaluates loss to minimize violation of stability constraints of stable marriage problem, originally proposed in Shira Li, “Deep Learning for Two-Sided Matching Markets” as expected ex post stability violation.

\[\begin{split}\text{envy}^{ab}_j(m, s^{ab}) &=& \sum_{n\in N\backslash\{i\}}m_{i,j}\max(s^{ab}_{i,j}-s^{ab}_{n,j},0) \\ \text{envy}^{ba}_i(m,, s^{ba}) &=& \sum_{m\in M\backslash\{j\}}m^\top_{j,i}\max(s^{ba}_{j,i}-s^{ba}_{m,i},0) \\ \mathcal{L}_{\rm stability}(m, s^{ab}, s^{ba}) &=& \sum_{(i,j)\in N\times M} \text{envy}^{ab}_j(m, s^{ab}) * \text{envy}^{ba}_j(m, s^{ba})\end{split}\]
Shape:
  • m: \((\ldots, N, M)\)

  • sab: \((\ldots, N, M)\)

  • sba_t: \((\ldots, N, M)\)

  • output: \((\ldots,)\)

Parameters
  • m (Tensor) – a continously-relaxed assignment between sides \(a\) and \(b\), where |a|=N, |b|=M.

  • sab (Tensor) – a satisfaction at matching of agents in side \(a\) to side \(b\).

  • sba_t (Tensor) – a satisfaction at matching of agents in side \(b\) to side \(a\) (transposed to be the same shape with sab).

Returns

The calculated expected ex post stability violation of \(\mathcal{L}_{\rm stability}(m, s^{ab}, s^{ba})\).

Return type

Tensor

weavenet.loss.loss_sexequality(m, sab, sba_t)[source]

Evaluates loss to minimize sex-equality cost.

\[\begin{split}S^{ab}(m) &=& \sum_{(i,j)\in N\times M} m_{i,j}s^{ab}_{i,j} \\ S^{ba}(m) &=& \sum_{(i,j)\in N\times M} m^\top_{j,i}s^{ba}_{j,i} \\ \mathcal{L}_{\rm sexequality}(m, s^{ab}, s^{ba}) &=& | S^{ab}(m) - S^{ba}(m)|\end{split}\]

Shape: see loss_stability()

Parameters
Returns

Batch-wise mean of \(\mathcal{L}_{\rm sexequality}(m, s^{ab}, s^{ba})\).

Return type

Tensor

weavenet.loss.loss_egalitarian(m, sab, sba_t)[source]

Calculates a loss to minimize egalitarian cost.

\[\mathcal{L}_{\rm egalitarian}(m, s^{ab}, s^{ba}) = S^{ab}(m) + S^{ba}(m),\]

where see loss_sexequality for definitions of \(S^{ab}(m)\) and \(S^{ba}(m)\).

Shape: see loss_stability()

Parameters
Returns

loss \(\mathcal{L}_{\rm egalitarian}(m, s^{ab}, s^{ba})\).

Return type

Tensor

weavenet.loss.loss_balance(m, sab, sba_t)[source]

Calculates a loss to minimize balance cost.

\[\mathcal{L}_{\rm balance}(m, s^{ab}, s^{ba}) = min(S^{ab}(m), S^{ba}(m)),\]

where see loss_sexequality for definitions of \(S^{ab}(m)\) and \(S^{ba}(m)\).

Note

It is also known that

\(\mathcal{L}_{\rm balance}(m, s^{ab}, s^{ba}) = \frac{\mathcal{L}_{\rm sexequality}(m, s^{ab}, s^{ba})+\mathcal{L}_{\rm egalitarian}(m, s^{ab}, s^{ba})}{2}\).

Shape: see loss_stability()

Parameters
Returns

loss \(\mathcal{L}_{\rm balance}(m, s^{ab}, s^{ba})\).

Return type

Tensor