Skip to main content

Linear sum assignment problem solver using Jonker-Volgenant algorithm.

Project description

Build Status PyPI

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.

Blog post

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 macOS.

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


Download files

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

Source Distribution

lapjv-1.3.15.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lapjv-1.3.15-cp38-cp38-manylinux_2_24_x86_64.whl (148.0 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.24+ x86-64

File details

Details for the file lapjv-1.3.15.tar.gz.

File metadata

  • Download URL: lapjv-1.3.15.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

File hashes

Hashes for lapjv-1.3.15.tar.gz
Algorithm Hash digest
SHA256 25cb6e315dcb9bff9cbcc66d5f82af87a41fb77e2248b208d5ca0d9f0026d3ef
MD5 6d17e7b9c8174aee3ca132f1c6a9543d
BLAKE2b-256 cd7510e06d9f9b0aa666b66a674235e40772de5a344a9394aae58596d827d717

See more details on using hashes here.

File details

Details for the file lapjv-1.3.15-cp38-cp38-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: lapjv-1.3.15-cp38-cp38-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 148.0 kB
  • Tags: CPython 3.8, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11

File hashes

Hashes for lapjv-1.3.15-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 88cf73e2dbd32bc205f4295cb59f1e1a649767db83ab50c286de844750283827
MD5 c5eb217120036467908d653c1be4c628
BLAKE2b-256 c4c924cd57ebc49cc0be9887466984b16f21e37234e17376ad302ab9480437f3

See more details on using hashes here.

Supported by

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