summaryrefslogtreecommitdiff
path: root/ot/utils.py
diff options
context:
space:
mode:
authorievred <ievgen.redko@univ-st-etienne.fr>2020-04-08 16:34:39 +0200
committerievred <ievgen.redko@univ-st-etienne.fr>2020-04-08 16:34:39 +0200
commit1a4c264cc9b2cb0bb89840ee9175177e86eef3ef (patch)
treeed3835181028050245d555548fcac6714122ae1d /ot/utils.py
parent0b402fd7c7e07043afd3a9df9d75bc424730b06f (diff)
added label normalization to utils
Diffstat (limited to 'ot/utils.py')
-rw-r--r--ot/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/ot/utils.py b/ot/utils.py
index b71458b..c154f99 100644
--- a/ot/utils.py
+++ b/ot/utils.py
@@ -200,6 +200,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: