diff options
author | Gard Spreemann <gspr@nonempty.org> | 2020-07-09 08:49:39 +0200 |
---|---|---|
committer | Gard Spreemann <gspr@nonempty.org> | 2020-07-09 08:49:39 +0200 |
commit | a16b9471d7114ec08977479b7249efe747702b97 (patch) | |
tree | 692f3061d0329cad954206b2bf903ba3384403f0 /ot/utils.py | |
parent | 0812fcd82cbf11d444619e96c55ba507bc09ef5d (diff) | |
parent | 94d5c8cc9046854f473d8e4526a3bcf214eb5411 (diff) |
Merge tag '0.7.0' into dfsg/latest
Diffstat (limited to 'ot/utils.py')
-rw-r--r-- | ot/utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ot/utils.py b/ot/utils.py index b71458b..f9911a1 100644 --- a/ot/utils.py +++ b/ot/utils.py @@ -49,6 +49,12 @@ def kernel(x1, x2, method='gaussian', sigma=1, **kwargs): return K +def laplacian(x): + """Compute Laplacian matrix""" + L = np.diag(np.sum(x, axis=0)) - x + return L + + def unif(n): """ return a uniform histogram of length n (simplex) @@ -200,6 +206,28 @@ def dots(*args): return reduce(np.dot, args) +def label_normalization(y, start=0): + """ Transform labels to start at a given value + + Parameters + ---------- + y : array-like, shape (n, ) + The vector of labels to be normalized. + start : int + Desired value for the smallest label in y (default=0) + + Returns + ------- + y : array-like, shape (n1, ) + The input vector of labels normalized according to given start value. + """ + + diff = np.min(np.unique(y)) - start + if diff != 0: + y -= diff + return y + + def fun(f, q_in, q_out): """ Utility function for parmap with no serializing problems """ while True: |