Skip to main content

Spatial-KWD: Kantorovich-Wasserstein Distances for Large Spatial Maps

The Spatial-KWD package contains efficient implementations of Discrete Optimal Transport algorithms for the computation of Kantorovich-Wasserstein distances [1], which are customized for large spatial maps. All the algorithms are based on an ad-hoc implementation of the Network Simplex algorithm [1,2]. Each implemented algorithm builds a different network, exploiting the special structure of spatial maps.

Details

This library contains three helper functions and two main classes.

The three helper functions are compareOneToOne, compareOneToMany, and compareAll. All the functions take in input the data and an options list. Using the options is possible to configure the Kantorivich-Wasserstein solver, so that it uses different algorithms with different parameters.

The helper functions are built on top of two main classes: Histogram2D and Solver.

Note that in case of non-convex maps, the algorithm builds the convex-hull of the input bins and pads the weights with zeros.

Prerequisities

You only need the following two standard python libraries:

  • cython
  • numpy

In the case you want to compile the source files, you need the python-dev, which on linux can be installed by>

apt install python3-dev  # Ubuntu

Installation

To install Spatial-KWD you can run the following command:

pip3 install Spatial-KWD

This will compile the C++ code and build the python wrapper.

Testing

For testing the library you can run the following command:

python3 test_matrix.py

The test program is the following

import numpy as np

from KWD import compareOneToOne, compareOneToMany, compareAll


np.random.seed(13)

N = 32*32
M = 3

# Random data
Coordinates = np.random.randint(0, 32, size=(N, 2), dtype=np.int32)
Weights = np.random.uniform(0, 100, size=(N, 2))

# Testing the first helper function
print('-----------------------------\nTest one2one approx:')
Options = {'Verbosity': 'debug'}
sol = compareOneToOne(Coordinates, Weights, Options)
for k in sol:
    print(k, sol[k])

References

[1] Bassetti, F., Gualandi, S. and Veneroni, M., 2020. On the Computation of Kantorovich--Wasserstein Distances Between Two-Dimensional Histograms by Uncapacitated Minimum Cost Flows. SIAM Journal on Optimization, 30(3), pp.2441-2469.

[2] Cunningham, W.H., 1976. A Network Simplex method. Mathematical Programming, 11(1), pp.105-116.

[3] https://github.com/eurostat/Spatial-KWD

Authors and maintainers

Stefano Gualandi, stefano.gualandi@gmail.com.

Maintainer: Stefano Gualandi stefano.gualandi@gmail.com

Metadata

Release files for Spatial-KWD 0.4.0

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

Source distribution (sdist)

Source distribution for Spatial-KWD 0.4.0
File Size Uploaded Provenance
Spatial-KWD-0.4.0.tar.gz 158.2 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for Spatial-KWD 0.4.0
File
Spatial_KWD-0.4.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
Spatial_KWD-0.4.0-cp39-cp39-manylinux2010_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.12+ x86-64 Details
Spatial_KWD-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.15+ x86-64 Details
Spatial_KWD-0.4.0-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
Spatial_KWD-0.4.0-cp38-cp38-manylinux2010_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-64 Details
Spatial_KWD-0.4.0-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
Spatial_KWD-0.4.0-cp37-cp37m-manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Details
Spatial_KWD-0.4.0-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
Spatial_KWD-0.4.0-cp36-cp36m-manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Details

Total release size: 7.7 MB

Release files / Spatial-KWD-0.4.0.tar.gz

Download URL Spatial-KWD-0.4.0.tar.gz
Size 158.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c4ebba69535e493ab7d882249058a4997f43a0083e3236a27c9f73ae9b38098e
BLAKE2b-256 checksum
How to use checksums
e16b2af211f49deaeefd48cbfcde536dbff0cf1f25c5602bf3d5c83a8c38b589
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/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0

Release files / Spatial_KWD-0.4.0-cp39-cp39-win_amd64.whl

Download URL Spatial_KWD-0.4.0-cp39-cp39-win_amd64.whl
Size 193.5 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
7f065f8fa4b08c8c970c4b4a62e667978921ae32d17012b42aa5945f25adab6c
BLAKE2b-256 checksum
How to use checksums
90f8ba9d38281fe74dfc140a5fab6172c0995f8c1e694bd7fda6d3cb0e36c5c9
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/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0

Release files / Spatial_KWD-0.4.0-cp39-cp39-manylinux2010_x86_64.whl

Download URL Spatial_KWD-0.4.0-cp39-cp39-manylinux2010_x86_64.whl
Size 1.6 MB
Tags CPython 3.9 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
0887e130c46de1903d2fa2ca415f1a4b4eb249243ad377f6a912d99a1997e622
BLAKE2b-256 checksum
How to use checksums
d2e609f62a3094b01b2134b04980ebb669b93a4183c27791c2dfb584f17bf971
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/38.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release files / Spatial_KWD-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl

Download URL Spatial_KWD-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
Size 230.8 kB
Tags CPython 3.9 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
1010704f31bdc5001118e5f86f16448b468d1f8dbe22b2de17a48616f590c4b6
BLAKE2b-256 checksum
How to use checksums
ab370effbab86c1b552f28f1650b574a4eeb261545c3861da417c9c52432b531
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/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.5

Release files / Spatial_KWD-0.4.0-cp38-cp38-win_amd64.whl

Download URL Spatial_KWD-0.4.0-cp38-cp38-win_amd64.whl
Size 194.0 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
a91a9cbb5d8da6e3fc141326198ff0905c1f6431d4eb5457e12e75afd55c4566
BLAKE2b-256 checksum
How to use checksums
f6fa45f5a6e31f4963364c9c8bd0fca37e07a26b654b3efa87dab428a6875447
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/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0

Release files / Spatial_KWD-0.4.0-cp38-cp38-manylinux2010_x86_64.whl

Download URL Spatial_KWD-0.4.0-cp38-cp38-manylinux2010_x86_64.whl
Size 1.7 MB
Tags CPython 3.8 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
0755a4fde0b9d4e14fc6909effecf7735f9dc6a95ecfce7bfcb97001a6338db8
BLAKE2b-256 checksum
How to use checksums
2378059a9f68375115e6fce0e062a8bdc83a16f26d0db116b97d5383972a227d
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/38.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release files / Spatial_KWD-0.4.0-cp37-cp37m-win_amd64.whl

Download URL Spatial_KWD-0.4.0-cp37-cp37m-win_amd64.whl
Size 190.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
e301e39a9acdf53e3b74c217ba3a25833e580baa72607732d88740bd740cb321
BLAKE2b-256 checksum
How to use checksums
5ed2256507d692f7751c05ec94647919a72d03c4e048fb7a41dbd1a1a26ad042
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/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0

Release files / Spatial_KWD-0.4.0-cp37-cp37m-manylinux2010_x86_64.whl

Download URL Spatial_KWD-0.4.0-cp37-cp37m-manylinux2010_x86_64.whl
Size 1.6 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
e666e28da92816c561a2d6ab24b09fa21556b059caf1f4c8a8756fe358567474
BLAKE2b-256 checksum
How to use checksums
4241a6d221c4d0ff90acab1d4b968d77e80f7eeb74042cee2e8b30b314622af3
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/38.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release files / Spatial_KWD-0.4.0-cp36-cp36m-win_amd64.whl

Download URL Spatial_KWD-0.4.0-cp36-cp36m-win_amd64.whl
Size 190.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
35da3de8f4a481c5ae48fd5a8b42d057e8c64b96c4d3348b90392e33b30456ab
BLAKE2b-256 checksum
How to use checksums
414c67dc93d67a538009cbce384f59b1918bfcc07de3cf7015c44dd3fc7b5274
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/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0

Release files / Spatial_KWD-0.4.0-cp36-cp36m-manylinux2010_x86_64.whl

Download URL Spatial_KWD-0.4.0-cp36-cp36m-manylinux2010_x86_64.whl
Size 1.6 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
e3e1b96c3f125e9dde07ec68e9a8bf4dbf8ee61079567fe8affb70974a8e5a4a
BLAKE2b-256 checksum
How to use checksums
a6765734c48b63b6245f23b185eb5c085cb2df4c2ba7e8cfb30d4b07f506e7f4
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/38.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Security for Spatial-KWD 0.4.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.

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