MCPcopy Index your code
hub / github.com/PythonOT/POT

github.com/PythonOT/POT @0.9.6.post1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.9.6.post1 ↗ · + Follow
1,806 symbols 10,264 edges 194 files 613 documented · 34%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

POT: Python Optimal Transport

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

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

Website and documentation: https://PythonOT.github.io/

Source Code (MIT): https://github.com/PythonOT/POT

POT has the following main features: * A large set of differentiable solvers for optimal transport problems, including: * Exact linear OT, entropic and quadratic regularized OT, * Gromov-Wasserstein (GW) distances, Fused GW distances and variants of quadratic OT, * Unbalanced and partial OT for different divergences, * OT barycenters (Wasserstein and GW) for fixed and free support, * Fast OT solvers in 1D, on the circle and between Gaussian Mixture Models (GMMs), * Many ML related solvers, such as domain adaptation, optimal transport mapping estimation, subspace learning, Graph Neural Networks (GNNs) layers. * Several backends for easy use with Pytorch, Jax, Tensorflow, Numpy and Cupy arrays.

Implemented Features

POT provides the following generic OT solvers:

POT provides the following Machine Learning related solvers:

Some other examples are available in the documentation.

Using and citing the toolbox

If you use this toolbox in your research and find it useful, please cite POT using the following references from the current version and from our JMLR paper:

Flamary R., Vincent-Cuaz C., Courty N., Gramfort A., Kachaiev O., Quang Tran H., David L., Bonet C., Cassereau N., Gnassounou T., Tanguy E., Delon J., Collas A., Mazelet S., Chapel L., Kerdoncuff T., Yu X., Feickert M., Krzakala P., Liu T., Fernandes Montesuma E. POT Python Optimal Transport (version 0.9.5). URL: https://github.com/PythonOT/POT

Rémi Flamary, Nicolas Courty, Alexandre Gramfort, Mokhtar Z. Alaya, Aurélie Boisbunon, Stanislas Chambon, Laetitia Chapel, Adrien Corenflos, Kilian Fatras, Nemo Fournier, Léo Gautheron, Nathalie T.H. Gayraud, Hicham Janati, Alain Rakotomamonjy, Ievgen Redko, Antoine Rolet, Antony Schutz, Vivien Seguy, Danica J. Sutherland, Romain Tavenard, Alexander Tong, Titouan Vayer, POT Python Optimal Transport library, Journal of Machine Learning Research, 22(78):1−8, 2021. URL: https://pythonot.github.io/

In Bibtex format:

@misc{flamary2024pot,
  author = {Flamary, R{\'e}mi and Vincent-Cuaz, C{\'e}dric and Courty, Nicolas and Gramfort, Alexandre and Kachaiev, Oleksii and Quang Tran, Huy and David, Laurène and Bonet, Cl{\'e}ment and Cassereau, Nathan and Gnassounou, Th{\'e}o and Tanguy, Eloi and Delon, Julie and Collas, Antoine and Mazelet, Sonia and Chapel, Laetitia and Kerdoncuff, Tanguy and Yu, Xizheng and Feickert, Matthew and Krzakala, Paul and Liu, Tianlin and Fernandes Montesuma, Eduardo},
  title = {POT Python Optimal Transport (version 0.9.5)},
  url = {https://github.com/PythonOT/POT},
  year = {2024}
}

@article{flamary2021pot,
  author  = {R{\'e}mi Flamary and Nicolas Courty and Alexandre Gramfort and Mokhtar Z. Alaya and Aur{\'e}lie Boisbunon and Stanislas Chambon and Laetitia Chapel and Adrien Corenflos and Kilian Fatras and Nemo Fournier and L{\'e}o Gautheron and Nathalie T.H. Gayraud and Hicham Janati and Alain Rakotomamonjy and Ievgen Redko and Antoine Rolet and Antony Schutz and Vivien Seguy and Danica J. Sutherland and Romain Tavenard and Alexander Tong and Titouan Vayer},
  title   = {POT: Python Optimal Transport},
  journal = {Journal of Machine Learning Research},
  year    = {2021},
  volume  = {22},
  number  = {78},
  pages   = {1-8},
  url     = {http://jmlr.org/papers/v22/20-451.html}
}

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.16)
  • Scipy (>=1.0)
  • Cython (>=0.23) (build only, not necessary when installing from pip or conda)

Pip installation

You can install the toolbox through PyPI with:

pip install POT

or get the very latest version by running:

pip install -U https://github.com/PythonOT/POT/archive/master.zip # with --user for user install (no root)

Optional dependencies may be installed with

pip install POT[all]

Note that this installs cvxopt, which is licensed under GPL 3.0. Alternatively, if you cannot use GPL-licensed software, the specific optional dependencies may be installed individually, or per-submodule. The available optional installations are backend-jax, backend-tf, backend-torch, cvxopt, dr, gnn, all.

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 named ot instead of pot.

Dependencies

Some sub-modules require additional dependencies which are discussed below

  • ot.dr (Wasserstein dimensionality reduction) depends on autograd and pymanopt that can be installed with:
pip install pymanopt autograd

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

# With the unified  API :
Wd = ot.solve(M, a, b).value # exact linear program
Wd_reg = ot.solve(M, a, b, reg=reg).value # entropic regularized OT

# With the old API :
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

```python

a,b are 1D histograms (sum to 1 and positive)

M is the ground cost matrix

Core symbols most depended-on inside this repo

sum
called by 1240
ot/backend.py
to_numpy
called by 749
ot/backend.py
from_numpy
called by 513
ot/backend.py
dot
called by 503
ot/backend.py
randn
called by 407
ot/backend.py
ones
called by 382
ot/backend.py
max
called by 286
ot/backend.py
reshape
called by 268
ot/backend.py

Shape

Function 987
Method 757
Class 52
Enum 7
Route 3

Languages

Python93%
C++7%

Modules by API surface

ot/backend.py562 symbols
ot/utils.py69 symbols
ot/da.py55 symbols
test/test_bregman.py45 symbols
test/test_utils.py41 symbols
test/test_sliced.py37 symbols
ot/lp/network_simplex_simple.h34 symbols
ot/lp/network_simplex_simple_omp.h33 symbols
test/test_ot.py29 symbols
ot/smooth.py28 symbols
ot/lp/full_bipartitegraph_omp.h28 symbols
ot/lp/full_bipartitegraph.h28 symbols

For agents

$ claude mcp add POT \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact