summaryrefslogtreecommitdiff
path: root/ot/da.py
diff options
context:
space:
mode:
authorSlasnista <stan.chambon@gmail.com>2017-08-04 11:40:44 +0200
committerSlasnista <stan.chambon@gmail.com>2017-08-04 11:40:44 +0200
commit727077ad7db503955aea0751abf9f361f1d82af7 (patch)
treeca6265190ef8c5352dd6aaaee5b84f061e8458e5 /ot/da.py
parent64880e721f45c56de4815dd41cd21b8570c9776f (diff)
added new class SinkhornL1l2Transport() + dedicated test
Diffstat (limited to 'ot/da.py')
-rw-r--r--ot/da.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/ot/da.py b/ot/da.py
index 3031f63..6100d15 100644
--- a/ot/da.py
+++ b/ot/da.py
@@ -1369,6 +1369,10 @@ class SinkhornLpl1Transport(BaseTransport):
Parameters
----------
+ reg_e : float, optional (default=1)
+ Entropic regularization parameter
+ reg_cl : float, optional (default=0.1)
+ Class regularization parameter
mode : string, optional (default="unsupervised")
The DA mode. If "unsupervised" no target labels are taken into account
to modify the cost matrix. If "semisupervised" the target labels
@@ -1384,6 +1388,11 @@ class SinkhornLpl1Transport(BaseTransport):
The ground metric for the Wasserstein problem
distribution : string, optional (default="uniform")
The kind of distribution estimation to employ
+ max_iter : int, float, optional (default=10)
+ The minimum number of iteration before stopping the optimization
+ algorithm if no it has not converged
+ max_inner_iter : int, float, optional (default=200)
+ The number of iteration in the inner loop
verbose : int, optional (default=0)
Controls the verbosity of the optimization algorithm
log : int, optional (default=0)
@@ -1452,3 +1461,103 @@ class SinkhornLpl1Transport(BaseTransport):
verbose=self.verbose, log=self.log)
return self
+
+
+class SinkhornL1l2Transport(BaseTransport):
+ """Domain Adapatation OT method based on sinkhorn algorithm +
+ l1l2 class regularization.
+
+ Parameters
+ ----------
+ reg_e : float, optional (default=1)
+ Entropic regularization parameter
+ reg_cl : float, optional (default=0.1)
+ Class regularization parameter
+ mode : string, optional (default="unsupervised")
+ The DA mode. If "unsupervised" no target labels are taken into account
+ to modify the cost matrix. If "semisupervised" the target labels
+ are taken into account to set coefficients of the pairwise distance
+ matrix to 0 for row and columns indices that correspond to source and
+ target samples which share the same labels.
+ mapping : string, optional (default="barycentric")
+ The kind of mapping to apply to transport samples from a domain into
+ another one.
+ if "barycentric" only the samples used to estimate the coupling can
+ be transported from a domain to another one.
+ metric : string, optional (default="sqeuclidean")
+ The ground metric for the Wasserstein problem
+ distribution : string, optional (default="uniform")
+ The kind of distribution estimation to employ
+ max_iter : int, float, optional (default=10)
+ The minimum number of iteration before stopping the optimization
+ algorithm if no it has not converged
+ max_inner_iter : int, float, optional (default=200)
+ The number of iteration in the inner loop
+ verbose : int, optional (default=0)
+ Controls the verbosity of the optimization algorithm
+ log : int, optional (default=0)
+ Controls the logs of the optimization algorithm
+ Attributes
+ ----------
+ Coupling_ : the optimal coupling
+
+ References
+ ----------
+
+ .. [1] N. Courty; R. Flamary; D. Tuia; A. Rakotomamonjy,
+ "Optimal Transport for Domain Adaptation," in IEEE
+ Transactions on Pattern Analysis and Machine Intelligence ,
+ vol.PP, no.99, pp.1-1
+ .. [2] Rakotomamonjy, A., Flamary, R., & Courty, N. (2015).
+ Generalized conditional gradient: analysis of convergence
+ and applications. arXiv preprint arXiv:1510.06567.
+
+ """
+
+ def __init__(self, reg_e=1., reg_cl=0.1, mode="unsupervised",
+ max_iter=10, max_inner_iter=200,
+ tol=10e-9, verbose=False, log=False,
+ metric="sqeuclidean",
+ distribution_estimation=distribution_estimation_uniform,
+ out_of_sample_map='ferradans'):
+
+ self.reg_e = reg_e
+ self.reg_cl = reg_cl
+ self.mode = mode
+ self.max_iter = max_iter
+ self.max_inner_iter = max_inner_iter
+ self.tol = tol
+ self.verbose = verbose
+ self.log = log
+ self.metric = metric
+ self.distribution_estimation = distribution_estimation
+ self.out_of_sample_map = out_of_sample_map
+
+ def fit(self, Xs, ys=None, Xt=None, yt=None):
+ """Build a coupling matrix from source and target sets of samples
+ (Xs, ys) and (Xt, yt)
+ Parameters
+ ----------
+ Xs : array-like of shape = [n_source_samples, n_features]
+ The training input samples.
+ ys : array-like, shape = [n_source_samples]
+ The class labels
+ Xt : array-like of shape = [n_target_samples, n_features]
+ The training input samples.
+ yt : array-like, shape = [n_labeled_target_samples]
+ The class labels
+ Returns
+ -------
+ self : object
+ Returns self.
+ """
+
+ super(SinkhornL1l2Transport, self).fit(Xs, ys, Xt, yt)
+
+ self.Coupling_ = sinkhorn_l1l2_gl(
+ a=self.mu_s, labels_a=ys, b=self.mu_t, M=self.Cost,
+ reg=self.reg_e, eta=self.reg_cl, numItermax=self.max_iter,
+ numInnerItermax=self.max_inner_iter, stopInnerThr=self.tol,
+ verbose=self.verbose, log=self.log)
+
+ return self