Skip to main content

Fast Approximate Quadratic Assignment Problem Solver

This is a Python implementation of an algorithm for approximately solving quadratic assignment problems described in

Joshua T. Vogelstein and John M. Conroy and Vince Lyzinski and Louis J. Podrazik and Steven G. Kratzer and Eric T. Harley and Donniell E. Fishkind and R. Jacob Vogelstein and Carey E. Priebe (2012) Fast Approximate Quadratic Programming for Large (Brain) Graph Matching. arXiv:1112.5507.

It solves

min𝑃∈𝒫<𝐹, 𝑃𝐷𝑃𝖳>

where 𝐷, 𝐹 ∈ ℝ𝑛×𝑛, 𝒫 is the set of 𝑛×𝑛 permutation matrices and <., .> denotes the Frobenius inner product.

The implementation employs the Frank–Wolfe algorithm.

Example

import numpy as np
from faqap import minimize

# Make runs deterministic, descent origins are chosen randomly by default.
np.random.seed(123456789)

D = np.array(
    [
        [0, 0, 0, -4],
        [0, 0, -3, 0],
        [0, -2, 0, 0],
        [-1, 0, 0, 0]
    ],
    dtype=np.float64
)
F = np.array(
    [
        [0, 0, 0, +1],
        [0, 0, +2, 0],
        [0, +3, 0, 0],
        [+4, 0, 0, 0]
    ],
    dtype=np.float64
)

solution_permutation = minimize(D=D, F=F, descents_count=1).x

# Expected is the permutation reversing elements.
print("solution permutation =", solution_permutation)

Output

solution permutation = [3 2 1 0]

GPU Support

GPU support is enabled through Torch. It is an optional dependency. In order to use the GPU you must pass Torch tensors that are on the CUDA device. If you pass CPU tensors the GPU will not be used.

Note that linear sum assignment, which is a part of the algorithm, is done on the CPU though SciPy. On a system with GPU GeForce RTX 2080 SUPER and CPU AMD Ryzen Threadripper 2920X (single thread at 3.5 - 4.3 GHz) for a float32, 128 sized problem linear sum assignment takes ~60% of the execution time. It may be possible to move that part on the GPU as well, but currently there are no good off-the-shelf GPU implementations for that. It is also unclear if there will be any significant speedup.

Installation

pip install faqap

Dependencies

  • Python (>=3.5)
  • NumPy (>=1.10)
  • SciPy (>=1.4)
  • Torch (optional)

Metadata

Release files for faqap 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for faqap 0.3.0
File Interpreter ABI Platform Actions
faqap-0.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for faqap-0.3.0-py2.py3-none-any.whl

Release files / faqap-0.3.0-py2.py3-none-any.whl

Download URL faqap-0.3.0-py2.py3-none-any.whl
Size 9.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
639c0d39f3b61e6cd630db86f79ce0400ea9e38ef32b5cf1a82f0b89c55c9406
BLAKE2b-256 checksum
How to use checksums
18eba74baad500777395fbf13bf51f9dc987196ff96a126fd4cc4da582dd1f6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.0

Security for faqap 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page