summaryrefslogtreecommitdiff
path: root/src/python/gudhi
diff options
context:
space:
mode:
authortlacombe <lacombe1993@gmail.com>2019-10-17 11:56:20 +0200
committertlacombe <lacombe1993@gmail.com>2019-10-17 11:56:20 +0200
commit91632989f92b89752dd4e59836dff80b43f349f1 (patch)
tree98152a1571a53e53bcfb1c03ed28b2222701b991 /src/python/gudhi
parentf9ec015c1bdd01068771d0d04ff55e0436ffc879 (diff)
updated wasserstein doc to be sphinx-compatible + correction of typo in the .rst
Diffstat (limited to 'src/python/gudhi')
-rw-r--r--src/python/gudhi/wasserstein.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/python/gudhi/wasserstein.py b/src/python/gudhi/wasserstein.py
index ae5f75a5..0b2fe79a 100644
--- a/src/python/gudhi/wasserstein.py
+++ b/src/python/gudhi/wasserstein.py
@@ -17,8 +17,8 @@ except ImportError:
def _proj_on_diag(X):
'''
- param X: (n x 2) array encoding the points of a persistent diagram.
- return: (n x 2) arary encoding the (respective orthogonal) projections of the points onto the diagonal
+ :param X: (n x 2) array encoding the points of a persistent diagram.
+ :returns: (n x 2) arary encoding the (respective orthogonal) projections of the points onto the diagonal
'''
Z = (X[:,0] + X[:,1]) / 2.
return np.array([Z , Z]).T
@@ -26,11 +26,11 @@ def _proj_on_diag(X):
def _build_dist_matrix(X, Y, p=2., q=2.):
'''
- param X: (n x 2) np.array encoding the (points of the) first diagram.
- param Y: (m x 2) np.array encoding the second diagram.
- param q: Ground metric (i.e. norm l_q).
- param p: exponent for the Wasserstein metric.
- return: (n+1) x (m+1) np.array encoding the cost matrix C.
+ :param X: (n x 2) np.array encoding the (points of the) first diagram.
+ :param Y: (m x 2) np.array encoding the second diagram.
+ :param q: Ground metric (i.e. norm l_q).
+ :param p: exponent for the Wasserstein metric.
+ :returns: (n+1) x (m+1) np.array encoding the cost matrix C.
For 1 <= i <= n, 1 <= j <= m, C[i,j] encodes the distance between X[i] and Y[j], while C[i, m+1] (resp. C[n+1, j]) encodes the distance (to the p) between X[i] (resp Y[j]) and its orthogonal proj onto the diagonal.
note also that C[n+1, m+1] = 0 (it costs nothing to move from the diagonal to the diagonal).
'''
@@ -54,10 +54,10 @@ def _build_dist_matrix(X, Y, p=2., q=2.):
def _perstot(X, p, q):
'''
- param X: (n x 2) numpy array (points of a given diagram)
- param q: Ground metric on the (upper-half) plane (i.e. norm l_q in R^2); Default value is 2 (euclidean norm).
- param p: exponent for Wasserstein; Default value is 2.
- return: float, the total persistence of the diagram (that is, its distance to the empty diagram).
+ :param X: (n x 2) numpy array (points of a given diagram)
+ :param q: Ground metric on the (upper-half) plane (i.e. norm l_q in R^2); Default value is 2 (euclidean norm).
+ :param p: exponent for Wasserstein; Default value is 2.
+ :returns: float, the total persistence of the diagram (that is, its distance to the empty diagram).
'''
Xdiag = _proj_on_diag(X)
return (np.sum(np.linalg.norm(X - Xdiag, ord=q, axis=1)**p))**(1/p)
@@ -65,10 +65,12 @@ def _perstot(X, p, q):
def wasserstein_distance(X, Y, p=2., q=2.):
'''
- param X, Y: (n x 2) and (m x 2) numpy array (points of persistence diagrams)
- param q: Ground metric on the (upper-half) plane (i.e. norm l_q in R^2); Default value is 2 (euclidean norm).
- param p: exponent for Wasserstein; Default value is 2.
- return: float, the p-Wasserstein distance (1 <= p < infty) with respect to the q-norm as ground metric.
+ :param X: (n x 2) np.array encoding the (points of the) first diagram.
+ :param Y: (m x 2) np.array encoding the second diagram.
+ :param q: Ground metric on the (upper-half) plane (i.e. norm l_q in R^2); Default value is 2 (euclidean norm).
+ :param p: exponent for Wasserstein; Default value is 2.
+ :returns: the p-Wasserstein distance (1 <= p < infty) with respect to the q-norm as ground metric.
+ :rtype: float
'''
n = len(X)
m = len(Y)