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.22.tar.gz (10.7 kB view details)

Uploaded Source

Built Distributions

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

lapjv-1.3.22-cp310-cp310-win_amd64.whl (22.7 kB view details)

Uploaded CPython 3.10Windows x86-64

lapjv-1.3.22-cp310-cp310-musllinux_1_1_x86_64.whl (692.2 kB view details)

Uploaded CPython 3.10musllinux: musl 1.1+ x86-64

lapjv-1.3.22-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (178.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

lapjv-1.3.22-cp310-cp310-macosx_10_9_x86_64.whl (25.4 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

lapjv-1.3.22-cp39-cp39-win_amd64.whl (22.7 kB view details)

Uploaded CPython 3.9Windows x86-64

lapjv-1.3.22-cp39-cp39-musllinux_1_1_x86_64.whl (692.1 kB view details)

Uploaded CPython 3.9musllinux: musl 1.1+ x86-64

lapjv-1.3.22-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (177.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

lapjv-1.3.22-cp39-cp39-macosx_10_9_x86_64.whl (25.4 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

lapjv-1.3.22-cp38-cp38-win_amd64.whl (22.9 kB view details)

Uploaded CPython 3.8Windows x86-64

lapjv-1.3.22-cp38-cp38-musllinux_1_1_x86_64.whl (692.6 kB view details)

Uploaded CPython 3.8musllinux: musl 1.1+ x86-64

lapjv-1.3.22-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (178.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

lapjv-1.3.22-cp38-cp38-macosx_10_9_x86_64.whl (25.4 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: lapjv-1.3.22.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for lapjv-1.3.22.tar.gz
Algorithm Hash digest
SHA256 d7e49bed13e1d8ee36149215b0b40b70b2fdf0ae742fa7a9e0636c2f3d085067
MD5 661c3b703e4826382fb05be7391d7709
BLAKE2b-256 902365e358d861837e623441bda67dc299347ccc46479207558f1c2066e553a7

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: lapjv-1.3.22-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for lapjv-1.3.22-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 397f0c66cd47c01b7df06182d55faa471c5361d8c08dac996260ce4fd9a72d30
MD5 2bd07e93a6fe1ca2182c90b7a3d4878e
BLAKE2b-256 5764b90265bc06849acefe7dcc854b3d5a5628a8aea8d86abcbfd41e7be0cea7

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c7e9f68a6cdecd77084a95f32059ef8a2cf80da9a2122e0a9d0fe12c9460b6cd
MD5 3a931332e7fdad465ebcc77e738d562a
BLAKE2b-256 1afb4ac04fd00d8bb557713868ee253146fc3b01c1569398e0703370be2fb5d1

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f15d42ede04582f11875c28d5b1b105a180d4ac92b9caf09fb28c2d18e2035e5
MD5 099a4de65edcacbfdeddea47c129fd0a
BLAKE2b-256 e5f62487754d21ea46f0e2524e3511ccc560e7ad53788e0a3f8725d513fffbaa

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1cf99c425151158619c7fb819c3f7d88a6091891247e8d8e58daa31c30aab870
MD5 dc6e55989ca21e87ca1881d71e5231ce
BLAKE2b-256 b4f13254f5b58e9664acbdda4a852bdbd1b70f706320741f812224541ba9f7b9

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: lapjv-1.3.22-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for lapjv-1.3.22-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a62f1ce8922ff86df9ca6a8778f37fc4f8e91e1f622173b1afeb01df6e90d2a0
MD5 4b184fcb61d9f5b78c6109778aca6808
BLAKE2b-256 e1b440dcf11ea253be158ce57b0224fa0ec833c9d7e9771e7ebf87d7a11e117b

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6f40341502c51cfc8dbd3b7e07c01cf9780866f696a334689244d69950c3bf0a
MD5 4f67021b5740056ccb66bc18692fcf60
BLAKE2b-256 40ed030858330380d63290e5341a4972925de26b1d74c1b4e655e2c9f361fda7

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 9b604180ac5ee765481a360f468916c8b2a7fe8550e1272bfce5f4f0427f0a60
MD5 f325eb540dc29e31fa35f6b18f459fd9
BLAKE2b-256 a5b7743585c3482e3f612e75df0a65276811504d0618170ab2b3efed5471335b

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a53ce05677ee8f851d545d93e417e7b0e5c4dd65d44c4787bb82740794f05579
MD5 819aca7af50c9394adb6839ff8ea73b4
BLAKE2b-256 499243bf01a2a102464930ddb327249e2dd11763e1062b5b3fb596156fbb4fda

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: lapjv-1.3.22-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for lapjv-1.3.22-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 85468be93d08f92f7a1582072e3cb3b25b4d2b5c646160271bc593e620226311
MD5 1161e757681fe1294ec3a4c4df17c539
BLAKE2b-256 177ba3187e4b3a7ee373c750fb587fc2f1863a77d72d6313fdbc9f215c6c5198

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3f1a1a08585b11c1dcfc37cc88a548cd67e386ef52d6a49eec054e4432aa055a
MD5 0d1b25dc6c7021b901e8379f0354a318
BLAKE2b-256 31e8ac518bfb2873efb24bbe94eb0aeba6989b7ef02c6a19ae1e25c9d546ebf1

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 45fb9beb1acfbb1e521b1ac3ef10d1af382dad54c5df12006ca43baec264044e
MD5 8a1c3eb82d75286679577d6b2ba26405
BLAKE2b-256 05b802e1c6d04d2bb358e4e54f73c8d8e4d76b92bcb28f25a5db63c85bcc9235

See more details on using hashes here.

File details

Details for the file lapjv-1.3.22-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lapjv-1.3.22-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8cf974143f01a7715ec389a86f19e10846cfc2a3dac6095ff1ad138509bbced3
MD5 a4c269024bba27e2ed42ee33b64e979e
BLAKE2b-256 5e4c929fa274bd49535664e9ac6baad550291f9ae6197ac7c683b0e1e5de8c9b

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