Monotonic Differentiable Sorting Networks

Felix Petersen, Christian Borgelt, Hilde Kuehne, Oliver Deussen

In many machine learning tasks, models must be trained using "ordering supervision" rather than absolute ground-truth values. For instance, we might know that Image A represents a larger number than Image B, but we lack the exact scalar values for either. To train a model in this setting, the network must pass predicted values through a sorting algorithm and backpropagate the resulting error.

Because standard sorting is a discrete operation (a step function) with no useful gradients, researchers have developed differentiable sorting networks. These networks replace hard "swap" operations with continuous relaxations, typically using functions like the logistic sigmoid. However, this paper identifies a critical flaw in existing differentiable sorting networks: they are non-monotonic. This flaw leads to gradients with the wrong sign during training, severely hindering optimization.

Architecture of a differentiable sorting network processing image features.

The "Wrong-Way" Gradient Problem

Differentiable sorting networks are built on fixed structures of "wires" and "conditional swaps" (such as bitonic or odd-even sorts). To make these networks differentiable, the conditional swaps are relaxed into continuous operations.

The authors point out that when using the standard logistic relaxation, the network becomes non-monotonic. In a relaxed sorting network, increasing an input value can paradoxically decrease its corresponding output value. This creates "wrong-way" gradients that actively confuse the optimization process, telling the model to move in the wrong direction to reduce loss. This problem compounds as networks get deeper and the number of items to sort increases.

Proposed Solution: Monotonic Relaxations

To fix this, the authors focus on the sigmoid function used to relax the conditional swap. They provide a theoretical proof establishing that for a relaxed swap to remain monotonic, the derivative of the sigmoid function must decay no faster than $1/x^2$.

Based on this requirement, they introduce three specific alternatives to the standard logistic sigmoid ($\sigma$):

  1. Reciprocal Sigmoid ($f_R$): A simple function explicitly designed to meet the $1/x^2$ decay requirement.
  2. Cauchy CDF ($f_C$): Based on the Cauchy distribution, which features "heavy tails" that naturally satisfy the monotonicity condition.
  3. Optimal Monotonic Sigmoid ($f_O$): A piecewise function mathematically derived to be the "best" possible sigmoid. It minimizes the approximation error (the gap between the relaxed swap and a true hard swap) while remaining monotonic and Lipschitz-continuous.
Comparison of standard and proposed sigmoid functions for monotonic sorting.

By ensuring the sorting function is monotonic, the optimization landscape becomes quasiconvex. Quasiconvex functions are significantly easier to optimize because they have better convergence properties in gradient-based training, ensuring the gradient always points in the correct direction.

Experimental Results

The authors evaluated their monotonic relaxations on two primary benchmarks: 4-digit MNIST (predicting scalar values of 4-digit numbers using only relative order) and SVHN (Street View House Numbers, a more challenging real-world equivalent).

The monotonic sorting networks significantly outperformed previous state-of-the-art methods, including NeuralSort, Sinkhorn sorting, and the original (non-monotonic) Diffsort:

  • MNIST (n=15): The proposed monotonic methods achieved ~30-31% full ranking accuracy. In stark contrast, the previous logistic Diffsort managed only 4.7%, and NeuralSort achieved just 9.7%.
  • Scaling to Larger Sets: As the number of items to sort ($n$) increases, the gap between monotonic and non-monotonic methods grows dramatically. On MNIST with $n=32$, non-monotonic methods completely collapsed (0% accuracy), while the monotonic networks maintained robust performance.
  • SVHN: Results on the SVHN dataset mirrored MNIST, with the monotonic functions (especially the Reciprocal and Cauchy versions) providing the highest accuracy.

The experiments also revealed a trade-off between smoothness and error. For shallow networks, smooth functions like the Cauchy CDF performed best. For deeper networks (larger $n$), the low approximation error of the Optimal Sigmoid ($f_O$) became the deciding factor for success.

Limitations and Future Work

While monotonic differentiable sorting networks represent a major leap forward, some limitations remain. First, while bitonic sorting networks are efficient ($O(n \log^2 n)$), the odd-even networks used in some of the paper's experiments scale at $O(n^3)$ in terms of the permutation matrix, which could bottleneck very large-scale sorting tasks.

Additionally, the performance of these networks is sensitive to the inverse temperature parameter, $\beta$. The optimal $\beta$ depends heavily on the number of layers in the network. While the authors experimented with training $\beta$ jointly as a parameter, they found the networks performed better when it was fixed. Developing a reliable schedule or an adaptive method for learning $\beta$ during training remains an open and promising area for future research.

Summary updated

BibTeX
@inproceedings{petersen2022monotonic,
  author = {Felix Petersen and Christian Borgelt and Hilde Kuehne and Oliver Deussen},
  title = {{Monotonic Differentiable Sorting Networks}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=adRevjlyfNs},
}
Figure