Linear sum assignment problem solver using Jonker-Volgenant algorithm.
Project description
Linear Assignment Problem solver using Jonker-Volgenant algorithm
This project is the rewrite of pyLAPJV which supports Python 3 and updates the core code. The performance is twice as high as the original thanks to the optimization of the augmenting row reduction phase using Intel AVX2 intrinsics. It is a native Python 3 module and does not work with Python 2.x, stick to pyLAPJV otherwise.
Linear assignment problem is the bijection between two sets with equal cardinality which optimizes the sum of the individual mapping costs taken from the fixed cost matrix. It naturally arises e.g. when we want to fit t-SNE results into a rectangular regular grid. See this awesome notebook for the details about why LAP matters: CloudToGrid.
Jonker-Volgenant algorithm is described in the paper:
R. Jonker and A. Volgenant, "A Shortest Augmenting Path Algorithm for Dense and Sparse Linear Assignment Problems," Computing, vol. 38, pp. 325-340, 1987.
This paper is not publicly available though a brief description exists on sciencedirect.com. JV is faster in than the Hungarian algorithm in practice, though the complexity is the same - O(n3).
The C++ source of the algorithm comes from http://www.magiclogic.com/assignment.html It has been reworked and partially optimized with OpenMP 4.0 SIMD.
Installing
pip3 install lapjv
Tested on Linux and Windows. macOS is not supported, please do not report macOS build errors in the issues. Feel free to PR macOS support, but I warn that it will be a rough ride.
Usage
Refer to test.py for the complete code.
from lapjv import lapjv
row_ind, col_ind, _ = lapjv(cost_matrix)
The assignment matrix by row is row_ind
: the value at n-th place is the assigned column index to the n-th row.
col_ind
is the reverse of row_ind
: mapping from columns to row indexes.
Note: a bijection is only possible for sets with equal cardinality. If you need to map A vectors to B vectors, derive the square symmetric (A+B) x (A+B) matrix: take the first A rows and columns from A and the remaining [A..A+B] rows and columns from B. Set the A->A and B->B costs to some maximum distance value, big enough so that you don't see assignment errors.
Illegal instruction
This error appears if your CPU does not support the AVX2 instruction set. We do not ship builds for different CPUs so you need to build the package yourself:
pip3 install git+https://github.com/src-d/lapjv
NAN-s
NAN-s in the cost matrix lead to completely undefined result. It is the caller's responsibility to check them.
License
MIT Licensed,see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file lapjv-1.3.27.tar.gz
.
File metadata
- Download URL: lapjv-1.3.27.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5e8de9ef12480e98cd790fa79cdf9fdc913ec43cb921d146a34fcb1bc403aff |
|
MD5 | daa6ea5dea2672a0710d1db4069d5cd9 |
|
BLAKE2b-256 | 9bdebc15ca377306ad005dbdeb4018d7d04aff21329462dd381e6a5a46b18d48 |
File details
Details for the file lapjv-1.3.27-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 27.8 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f0b28f6e4c998498255437b634e07cddb91856e555fa1a511046b48e0d88a65 |
|
MD5 | 414f261a21edc19e4b91f628bb57ea96 |
|
BLAKE2b-256 | 743ad18cad445cfb65a1b9082a05966abeb4e4c13899c911bcb6b73182500b9d |
File details
Details for the file lapjv-1.3.27-cp311-cp311-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp311-cp311-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 727.4 kB
- Tags: CPython 3.11, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3caa34736fb141da2cdcb1d57a718255d7de9d70af1eab5f4d650dc87d344111 |
|
MD5 | 5f8110438f7d6ec9ecf3481e8bc6482d |
|
BLAKE2b-256 | bd382a969511866287d2b2fb85bb72c241fa7bd654e18d5c234772351d74cdc8 |
File details
Details for the file lapjv-1.3.27-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 162.7 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eae7899ab3f869b17c7dfe75705d45c7d9e6b94c298dbd7852ed0816455ad95 |
|
MD5 | c81a1f4bd9d0e45ed91f36c8a4d88791 |
|
BLAKE2b-256 | 54fb16de6af8185bf638588dc62a219732275bc17d8d20c8389b2cc5bc6fdb3f |
File details
Details for the file lapjv-1.3.27-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 27.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2779d8cc7b50e83a281c79158bf7febf545086daefc1404d1fc915a6c39fb56f |
|
MD5 | 6b511f5918433b27500b5a133d8a95f4 |
|
BLAKE2b-256 | 64ae0480648e302e8eb94205b9e3962bc7bb32ef4e5f5ba647a0b88b62d21da0 |
File details
Details for the file lapjv-1.3.27-cp310-cp310-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 726.6 kB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e87df2d8fe95864bf204af8b949ca4b14a6241c00c84c1540e88a6bea474ec8 |
|
MD5 | 97e31defefea2fd6dfa81312c4003ab4 |
|
BLAKE2b-256 | a64c40c48b461a4e2a77e7dbe87264155191ea386f8a0903ab01c59e9a7e338c |
File details
Details for the file lapjv-1.3.27-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 161.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd114248dab8f63d4446bd37f5aa3b131b59565fa1f005609cb8a41fdad3568a |
|
MD5 | 21fe3fb103400887c7c120cada100b5d |
|
BLAKE2b-256 | 834363348a22ec42ef719d18d086763d67461fca2b49df16afd54ca36a83d553 |
File details
Details for the file lapjv-1.3.27-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 27.8 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86b8ef915a10dee348f22b4f4b0dc8c72f47f41baa535e0b2f37e3d7b87e24af |
|
MD5 | 5dd9f7c79b2a79bff3b5431f3ca1cecd |
|
BLAKE2b-256 | 12bc7756c0a841e25ce759e3b1e64ffd4a7b0cddcfd35b680b730483f47dab08 |
File details
Details for the file lapjv-1.3.27-cp39-cp39-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp39-cp39-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 726.4 kB
- Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4548ab79d37809bbd2f41ec1f1d2fe9d40289286d6bd1c7adf3282247a9e7b5d |
|
MD5 | 4e7d7876812945f66fc2e5ed73a42ced |
|
BLAKE2b-256 | 23826a82b932f3da0c3b9877e266b1385b0b31d318710456482503a582109ca2 |
File details
Details for the file lapjv-1.3.27-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: lapjv-1.3.27-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 161.6 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9dd0e6a409aedceb655c4c37ec3a9f5d0c0cf47e92d508163e94ee5e19ab67f |
|
MD5 | 2df9f2562641a97066503c60972de5ab |
|
BLAKE2b-256 | f00d701ff843ac820fbba885105e81a9b25e9fea38abf17ff6f789db8a66787b |