Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rflamary committed Sep 28, 2018
1 parent 5e7bfbc commit ee8ed4f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 17 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This open source Python library provide several solvers for optimization problem
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] and stabilized version [9][10] with optional GPU implementation (requires cudamat).
* Entropic regularization OT solver with Sinkhorn Knopp Algorithm [2] and stabilized version [9][10] with optional GPU implementation (requires cupy).
* 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] and unmixing [4].
Expand Down Expand Up @@ -83,12 +83,8 @@ Some sub-modules require additional dependences which are discussed below
```
pip install pymanopt autograd
```
* **ot.gpu** (GPU accelerated OT) depends on cudamat that have to be installed with:
```
git clone https://github.com/cudamat/cudamat.git
cd cudamat
python setup.py install --user # for user install (no root)
```
* **ot.gpu** (GPU accelerated OT) depends on cupy that have to be installed following instructions on [this page](https://docs-cupy.chainer.org/en/stable/install.html).


obviously you need CUDA installed and a compatible GPU.

Expand Down
6 changes: 6 additions & 0 deletions docs/source/all.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ ot.da

.. automodule:: ot.da
:members:

ot.gpu
--------

.. automodule:: ot.gpu
:members:

ot.dr
--------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Mock(MagicMock):
@classmethod
def __getattr__(cls, name):
return MagicMock()
MOCK_MODULES = ['ot.lp.emd_wrap','autograd','pymanopt','cudamat','autograd.numpy','pymanopt.manifolds','pymanopt.solvers']
MOCK_MODULES = ['ot.lp.emd_wrap','autograd','pymanopt','cupy','autograd.numpy','pymanopt.manifolds','pymanopt.solvers']
# 'autograd.numpy','pymanopt.manifolds','pymanopt.solvers',
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
# !!!!
Expand Down
22 changes: 21 additions & 1 deletion ot/gpu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
# -*- coding: utf-8 -*-
"""
This module implement GPU ilmplementation for several OT solvers and utility
functions. The GPU backend in handled by `cupy
<https://cupy.chainer.org/>`_.
By default, the functions in this module accept and return numpy arrays
in order to proide drop-in replacement for the other POT function but
the transfer between CPU en GPU comes with a significant overhead.
In order to get the best erformances, we recommend to given only cupy
arrays to the functions and desactivate the conversion to numpy of the
result of the function with parameter ``to_numpy=False``.
"""

from . import bregman
from . import da
from .bregman import sinkhorn
from .da

from . import utils
from .utils import dist, to_gpu, to_np
Expand All @@ -13,4 +33,4 @@
#
# License: MIT License

__all__ = ["utils", "dist", "sinkhorn"]
__all__ = ["utils", "dist", "sinkhorn", 'bregman', 'da', 'to_gpu', 'to_np']
7 changes: 6 additions & 1 deletion ot/gpu/bregman.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
def sinkhorn_knopp(a, b, M, reg, numItermax=1000, stopThr=1e-9,
verbose=False, log=False, to_numpy=True, **kwargs):
"""
Solve the entropic regularization optimal transport problem and return the OT matrix
Solve the entropic regularization optimal transport on GPU
If the input matrix are in numpy format, they will be uploaded to the
GPU first which can incur significant time overhead.
The function solves the following optimization problem:
Expand Down Expand Up @@ -56,6 +59,8 @@ def sinkhorn_knopp(a, b, M, reg, numItermax=1000, stopThr=1e-9,
Print information along iterations
log : bool, optional
record log if True
to_numpy : boolean, optional (default True)
If true convert back the GPU array result to numpy format.
Returns
Expand Down
8 changes: 7 additions & 1 deletion ot/gpu/da.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def sinkhorn_lpl1_mm(a, labels_a, b, M, reg, eta=0.1, numItermax=10,
log=False, to_numpy=True):
"""
Solve the entropic regularization optimal transport problem with nonconvex
group lasso regularization
group lasso regularization on GPU
If the input matrix are in numpy format, they will be uploaded to the
GPU first which can incur significant time overhead.
The function solves the following optimization problem:
Expand Down Expand Up @@ -74,6 +78,8 @@ def sinkhorn_lpl1_mm(a, labels_a, b, M, reg, eta=0.1, numItermax=10,
Print information along iterations
log : bool, optional
record log if True
to_numpy : boolean, optional (default True)
If true convert back the GPU array result to numpy format.
Returns
Expand Down
15 changes: 9 additions & 6 deletions ot/gpu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@
def euclidean_distances(a, b, squared=False, to_numpy=True):
"""
Compute the pairwise euclidean distance between matrices a and b.
Parameters
If the input matrix are in numpy format, they will be uploaded to the
GPU first which can incur significant time overhead.
Parameters
----------
a : np.ndarray (n, f)
first matrix
b : np.ndarray (m, f)
second matrix
gpu : boolean, optional (default False)
if True and the module cupy is available, the computation is done
on the GPU and the type of the matrix returned is cupy.ndarray.
Otherwise, compute on the CPU and returns np.ndarray.
to_numpy : boolean, optional (default True)
If true convert back the GPU array result to numpy format.
squared : boolean, optional (default False)
if True, return squared euclidean distance matrix
Returns
Returns
-------
c : (n x m) np.ndarray or cupy.ndarray
pairwise euclidean distance distance matrix
Expand Down

0 comments on commit ee8ed4f

Please sign in to comment.