8000 GitHub - PhilipNZ/POT: Python Optimal Transport library
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ POT Public
forked from PythonOT/POT

Python Optimal Transport library

License

Notifications You must be signed in to change notification settings

PhilipNZ/POT

8000
 
 

Repository files navigation

POT: Python Optimal Transport

PyPI version Anaconda Cloud Build Status Documentation Status Downloads Anaconda downloads License

This open source Python library provide several solvers for optimization problems related to Optimal Transport for signal, image processing and machine learning.

It provides the following solvers:

  • OT Network Flow solver for the linear program/ Earth Movers Distance [1].
  • Entropic regularization OT solver with Sinkhorn Knopp Algorithm [2], stabilized version [9][10] and greedy Sinkhorn [22] with optional GPU implementation (requires cupy).
  • Sinkhorn divergence [23] and entropic regularization OT from empirical data.
  • Smooth optimal transport solvers (dual and semi-dual) for KL and squared L2 regularizations [17].
  • Non regularized Wasserstein barycenters [16] with LP solver (only small scale).
  • Bregman projections for Wasserstein barycenter [3], convolutional barycenter [21] and unmixing [4].
  • Optimal transport for domain adaptation with group lasso regularization [5]
  • Conditional gradient [6] and Generalized conditional gradient for regularized OT [7].
  • Linear OT [14] and Joint OT matrix and mapping estimation [8].
  • Wasserstein Discriminant Analysis [11] (requires autograd + pymanopt).
  • Gromov-Wasserstein distances and barycenters ([13] and regularized [12])
  • Stochastic Optimization for Large-scale Optimal Transport (semi-dual problem [18] and dual problem [19])
  • Non regularized free support Wasserstein barycenters [20].
  • Unbalanced OT with KL relaxation distance and barycenter [10, 25].

Some demonstrations (both in Python and Jupyter Notebook format) are available in the examples folder.

Using and citing the toolbox

If you use this toolbox in your research and find it useful, please cite POT using the following bibtex reference:

@misc{flamary2017pot,
title={POT Python Optimal Transport library},
author={Flamary, R{'e}mi and Courty, Nicolas},
url={https://github.com/rflamary/POT},
year={2017}
}

Installation

The library has been tested on Linux, MacOSX and Windows. It requires a C++ compiler for building/installing the EMD solver and relies on the following Python modules:

  • Numpy (>=1.11)
  • Scipy (>=1.0)
  • Cython (>=0.23)
  • Matplotlib (>=1.5)

Pip installation

Note that due to a limitation of pip, cython and numpy need to be installed prior to installing POT. This can be done easily with

pip install numpy cython

You can install the toolbox through PyPI with:

pip install POT

or get the very latest version by downloading it and then running:

python setup.py install --user # for user install (no root)

Anaconda installation with conda-forge

If you use the Anaconda python distribution, POT is available in conda-forge. To install it and the required dependencies:

conda install -c conda-forge pot

Post installation check

After a correct installation, you should be able to import the module without errors:

import ot

Note that for easier access the module is name ot instead of pot.

Dependencies

Some sub-modules require additional dependences which are discussed below

  • ot.dr (Wasserstein dimensionality reduction) depends on autograd and pymanopt that can be installed with:
pip install pymanopt autograd
  • ot.gpu (GPU accelerated OT) depends on cupy that have to be installed following instructions on this page.

obviously you need CUDA installed and a compatible GPU.

Examples

Short examples

  • Import the toolbox
import ot
  • Compute Wasserstein distances
# a,b are 1D histograms (sum to 1 and positive)
# M is the ground cost matrix
Wd=ot.emd2(a,b,M) # exact linear program
Wd_reg=ot.sinkhorn2(a,b,M,reg) # entropic regularized OT
# if b is a matrix compute all distances to a and return a vector
  • Compute OT matrix
# a,b are 1D histograms (sum to 1 and positive)
# M is the ground cost matrix
T=ot.emd(a,b,M) # exact linear program
T_reg=ot.sinkhorn(a,b,M,reg) # entropic regularized OT
  • Compute Wasserstein barycenter
# A is a n*d matrix containing d  1D histograms
# M is the ground cost matrix
ba=ot.barycenter(A,M,reg) # reg is regularization parameter

Examples and Notebooks

The examples folder contain several examples and use case for the library. The full documentation is available on Readthedocs.

Here is a list of the Python notebooks available here if you want a quick look:

You can also see the notebooks with Jupyter nbviewer.

Acknowledgements

This toolbox has been created and is maintained by

The contributors to this library are

This toolbox benefit a lot from open source research and we would like to thank the following persons for providing some code (in various languages):

Contributions and code of conduct

Every contribution is welcome and should respect the contribution guidelines. Each member of the project is expected to follow the code of conduct.

Support