Spatial KWD for Large Spatial Maps
Project description
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
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
Hashes for Spatial_KWD-0.4.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f065f8fa4b08c8c970c4b4a62e667978921ae32d17012b42aa5945f25adab6c |
|
MD5 | ec7e538ce1ff0f381c51ac7fba739a34 |
|
BLAKE2b-256 | 90f8ba9d38281fe74dfc140a5fab6172c0995f8c1e694bd7fda6d3cb0e36c5c9 |
Hashes for Spatial_KWD-0.4.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0887e130c46de1903d2fa2ca415f1a4b4eb249243ad377f6a912d99a1997e622 |
|
MD5 | 15bc92527fdc7494967940a6a391f697 |
|
BLAKE2b-256 | d2e609f62a3094b01b2134b04980ebb669b93a4183c27791c2dfb584f17bf971 |
Hashes for Spatial_KWD-0.4.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1010704f31bdc5001118e5f86f16448b468d1f8dbe22b2de17a48616f590c4b6 |
|
MD5 | 2f9ca874fbaffb596bdc46347e74b76a |
|
BLAKE2b-256 | ab370effbab86c1b552f28f1650b574a4eeb261545c3861da417c9c52432b531 |
Hashes for Spatial_KWD-0.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a91a9cbb5d8da6e3fc141326198ff0905c1f6431d4eb5457e12e75afd55c4566 |
|
MD5 | e475a615601a3ad869accc4c4f9b2feb |
|
BLAKE2b-256 | f6fa45f5a6e31f4963364c9c8bd0fca37e07a26b654b3efa87dab428a6875447 |
Hashes for Spatial_KWD-0.4.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0755a4fde0b9d4e14fc6909effecf7735f9dc6a95ecfce7bfcb97001a6338db8 |
|
MD5 | 1504cba9d1f3574faecbb199f33c1d3a |
|
BLAKE2b-256 | 2378059a9f68375115e6fce0e062a8bdc83a16f26d0db116b97d5383972a227d |
Hashes for Spatial_KWD-0.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e301e39a9acdf53e3b74c217ba3a25833e580baa72607732d88740bd740cb321 |
|
MD5 | 3452f93f96c5284faa50d3be0c3afe95 |
|
BLAKE2b-256 | 5ed2256507d692f7751c05ec94647919a72d03c4e048fb7a41dbd1a1a26ad042 |
Hashes for Spatial_KWD-0.4.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e666e28da92816c561a2d6ab24b09fa21556b059caf1f4c8a8756fe358567474 |
|
MD5 | c9a122608eecbc868963c1e71a695229 |
|
BLAKE2b-256 | 4241a6d221c4d0ff90acab1d4b968d77e80f7eeb74042cee2e8b30b314622af3 |
Hashes for Spatial_KWD-0.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35da3de8f4a481c5ae48fd5a8b42d057e8c64b96c4d3348b90392e33b30456ab |
|
MD5 | f0a8eea9512d2978a0bc1d10bde78648 |
|
BLAKE2b-256 | 414c67dc93d67a538009cbce384f59b1918bfcc07de3cf7015c44dd3fc7b5274 |
Hashes for Spatial_KWD-0.4.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3e1b96c3f125e9dde07ec68e9a8bf4dbf8ee61079567fe8affb70974a8e5a4a |
|
MD5 | d1b6c979d71e40ba7cca6c55442d71a8 |
|
BLAKE2b-256 | a6765734c48b63b6245f23b185eb5c085cb2df4c2ba7e8cfb30d4b07f506e7f4 |