Giter Club home page Giter Club logo

spatial-kwd's Introduction

Spatial-KWD

Computing Kantorovich-Wasserstein distances for large spatial maps

This software library contains efficient implementations of Discrete Optimal Transport algorithms for the computation of Kantorovich-Wassestein distances [1] customized for large spatial maps.

The core library is written in standard ANSI-C++11, but it has two wrappers:

  1. A Python wrapper
  2. An R wrapper

If you need a wrapper in another language, please let us know by posting a request on GitHub.

Currently, the Spatial-KWD library is tested on

  • Google Colabs notebooks
  • Windows 10 (R v4.0.3, Python >= 3.6)
  • Mac OS X Bug Sur 11.0.1 (R v4.0.3, Python 3.8.3)
  • Linux 20.04.1 LTS (R v4.0.0, Python 3.8.5)

Basic Usage: Colab Notebooks

The simplest way to test this library is to run one of the following notebooks on Colab:

Data Notebook Link
[2021/02/20] Tutorial 1: Using Spatial-KWD with Python Open In Colab
[2020/11/22] Tutorial 2: Using Spatial-KWD with R Open In Colab

Python Wrapper

To compile the Python wrapper you need the following library:

To install Cython you can look at the official documentation Installing Cython.

Then, you have to download this repository, move to the subdirectory .\wrapper\python\, and then run from command line the following command:

python setup.py build_ext

This will compile the C++ code and build the python wrapper. If you prefer to compile the wrapper in a local directory, you can run the command:

python setup.py build_ext --inplace

In this case, however, you can only use the library in the local directory where you compile it.

Once you have done with the installation of the python wrapper, you can test it using one of the following script:

  • test_kwd.py: A basic example with three histograms.
  • test_pandas.py: An example based on Pandas Series, which uses also an exact solver.

R Wrapper

The wrapper for R is contained in the SpatialKWD_0.3.0.tar.gz package, and all the source code are freely available on this site under the directory wrappers/R.

For compiling the wrapper, you need a recent version of R and the Rcpp package (we test it with Rcpp v.1.0.5, but it should work also with older versions).

Windows users can download a pre-compiled binary package at the following link:

Once you have installed the Spatial-KWD package, you can test it running one of the following scripts:

  • test_SKWD.R: to compute the distances among three dummies histograms
  • test_SKWD_dataframe.R: to compute the distance between two histograms stored in a data.frame or in a data.table.

If you need an interface for a different R data structure, again, please let us know.

About

Contributors
Status since 2020
License EUPL v1.2

Main References

Note

Windows package of the R wrapper is built with Win-Builder.

spatial-kwd's People

Contributors

stegua avatar gjacopo avatar mmatyi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.