Skip to main content

Differentiable Sorting Networks.

Project description

diffsort - Differentiable Sorting Networks

diffsort_logo

Official implementation for our ICLR 2022 Paper "Monotonic Differentiable Sorting Networks" and our ICML 2021 Paper "Differentiable Sorting Networks for Scalable Sorting and Ranking Supervision". In this work, we leverage classic sorting networks and relax them to propose a new differentiable sorting function: diffsort. This allows propagating gradients through (an approximation of) the sorting / ranking function / operation. Herein, diffsort outperforms existing differentiable sorting functions on the four-digit MNIST and the SVHN sorting tasks. In this repo, we present the PyTorch implementation of differentiable sorting networks.

Video @ Youtube.

video

💻 Installation

diffsort can be installed via pip from PyPI with

pip install diffsort

Or from source, e.g., in a virtual environment like

virtualenv -p python3 .env1
. .env1/bin/activate
pip install .

👩‍💻 Usage

import torch
from diffsort import DiffSortNet

vector_length = 2**4
vectors = torch.randperm(vector_length, dtype=torch.float32, device='cpu', requires_grad=True).view(1, -1)
vectors = vectors - 5.

# sort using a bitonic-sorting-network
sorter = DiffSortNet('bitonic', vector_length, steepness=5)
sorted_vectors, permutation_matrices = sorter(vectors)
print(sorted_vectors)

🧪 Experiments

You can find the main experiment in this Colab notebook.

You can run the four-digit MNIST experiment as

python experiments/main.py -n 5 -m odd_even -s 10 -d mnist

or for the bitonic network

python experiments/main.py -n 16 -m bitonic -s 20 -d mnist

or for SVHN

python experiments/main.py -n 5 -m odd_even -s 10 -d svhn

📖 Citing

@inproceedings{petersen2022monotonic,
  title={Monotonic Differentiable Sorting Networks},
  author={Petersen, Felix and Borgelt, Christian and Kuehne, Hilde and Deussen, Oliver},
  booktitle={International Conference on Learning Representations (ICLR)},
  year={2022}
}

@inproceedings{petersen2021diffsort,
  title={Differentiable Sorting Networks for Scalable Sorting and Ranking Supervision},
  author={Petersen, Felix and Borgelt, Christian and Kuehne, Hilde and Deussen, Oliver},
  booktitle={International Conference on Machine Learning (ICML)},
  year={2021}
}

License

diffsort is released under the MIT license. See LICENSE for additional details about it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffsort-0.2.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

diffsort-0.2.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file diffsort-0.2.0.tar.gz.

File metadata

  • Download URL: diffsort-0.2.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.24.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.48.2 importlib-metadata/4.5.0 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.12

File hashes

Hashes for diffsort-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9af05f475cd7c5bd307d8489d3fefe1c3ec26d639f7fd2c0f0ecb0ed48d91f98
MD5 bb0dbf7a10dbd5f5a29cb5fd5b53be50
BLAKE2b-256 dffdcdd10e3e47069a1bfceb50212cb33935388d5939a731bcbb7e76152ffbd5

See more details on using hashes here.

File details

Details for the file diffsort-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: diffsort-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.24.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.48.2 importlib-metadata/4.5.0 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.12

File hashes

Hashes for diffsort-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95bd5541ade48919cd926366f83165e07645b6e62fe798343b7f0d0332b8a08b
MD5 1709761b76f5273f43d92308063cbd08
BLAKE2b-256 b6f3d2b1d966189805bc1074ad056c1d4397363071c08944807270f53ce73191

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page