Domain adaptation with optimal transport
estimates a uniform distribution from an array of samples \(\mathbf{X}\)
X (array-like, shape (n_samples, n_features)) – The array of samples
mu – The uniform distribution estimated from \(\mathbf{X}\)
array-like, shape (n_samples,)
Solve the optimal transport problem (OT) with Laplacian regularization
where:
\(\mathbf{a}\) and \(\mathbf{b}\) are source and target weights (sum to 1)
\(\mathbf{x_s}\) and \(\mathbf{x_t}\) are source and target samples
\(\mathbf{M}\) is the (ns, nt) metric cost matrix
\(\Omega_\alpha\) is the Laplacian regularization term
with \(\mathbf{S^s}_{i,j}, \mathbf{S^t}_{i,j}\) denoting source and target similarity matrices and \(T(\cdot)\) being a barycentric mapping.
The algorithm used for solving the problem is the conditional gradient algorithm as proposed in [5].
a (array-like (ns,)) – samples weights in the source domain
b (array-like (nt,)) – samples weights in the target domain
xs (array-like (ns,d)) – samples in the source domain
xt (array-like (nt,d)) – samples in the target domain
M (array-like (ns,nt)) – loss matrix
sim (string, optional) – Type of similarity (‘knn’ or ‘gauss’) used to construct the Laplacian.
sim_param (int or float, optional) – Parameter (number of the nearest neighbors for sim=’knn’ or bandwidth for sim=’gauss’) used to compute the Laplacian.
reg (string) – Type of Laplacian regularization
eta (float) – Regularization term for Laplacian regularization
alpha (float) – Regularization term for source domain’s importance in regularization
numItermax (int, optional) – Max number of iterations
stopThr (float, optional) – Stop threshold on error (inner emd solver) (>0)
numInnerItermax (int, optional) – Max number of iterations (inner CG solver)
stopInnerThr (float, optional) – Stop threshold on error (inner CG solver) (>0)
verbose (bool, optional) – Print information along iterations
log (bool, optional) – record log if True
gamma ((ns, nt) array-like) – Optimal transportation matrix for the given parameters
log (dict) – log dictionary return only if log==True in parameters
References
See also
ot.lp.emdUnregularized OT
ot.optim.cgGeneral regularized OT
Solve the entropic regularization optimal transport problem with group lasso regularization
The function solves the following optimization problem:
where :
\(\mathbf{M}\) is the (ns, nt) metric cost matrix
\(\Omega_e\) is the entropic regularization term \(\Omega_e(\gamma)=\sum_{i,j} \gamma_{i,j}\log(\gamma_{i,j})\)
\(\Omega_g\) is the group lasso regularization term \(\Omega_g(\gamma)=\sum_{i,c} \|\gamma_{i,\mathcal{I}_c}\|^2\) where \(\mathcal{I}_c\) are the index of samples from class c in the source domain.
\(\mathbf{a}\) and \(\mathbf{b}\) are source and target weights (sum to 1)
The algorithm used for solving the problem is the generalized conditional gradient as proposed in [5, 7].
a (array-like (ns,)) – samples weights in the source domain
labels_a (array-like (ns,)) – labels of samples in the source domain
b (array-like (nt,)) – samples in the target domain
M (array-like (ns,nt)) – loss matrix
reg (float) – Regularization term for entropic regularization >0
eta (float, optional) – Regularization term for group lasso regularization >0
numItermax (int, optional) – Max number of iterations
numInnerItermax (int, optional) – Max number of iterations (inner sinkhorn solver)
stopInnerThr (float, optional) – Stop threshold on error (inner sinkhorn solver) (>0)
eps (float, optional (default=1e-12)) – Small value to avoid division by zero
verbose (bool, optional) – Print information along iterations
log (bool, optional) – record log if True
gamma ((ns, nt) array-like) – Optimal transportation matrix for the given parameters
log (dict) – log dictionary return only if log==True in parameters
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
See also
ot.optim.gcgGeneralized conditional gradient for OT problems
Solve the entropic regularization optimal transport problem with non-convex group lasso regularization
The function solves the following optimization problem:
where :
\(\mathbf{M}\) is the (ns, nt) metric cost matrix
\(\Omega_e\) is the entropic regularization term \(\Omega_e (\gamma)=\sum_{i,j} \gamma_{i,j}\log(\gamma_{i,j})\)
\(\Omega_g\) is the group lasso regularization term \(\Omega_g(\gamma)=\sum_{i,c} \|\gamma_{i,\mathcal{I}_c}\|^{1/2}_1\) where \(\mathcal{I}_c\) are the index of samples from class c in the source domain.
\(\mathbf{a}\) and \(\mathbf{b}\) are source and target weights (sum to 1)
The algorithm used for solving the problem is the generalized conditional gradient as proposed in [5, 7].
a (array-like (ns,)) – samples weights in the source domain
labels_a (array-like (ns,)) – labels of samples in the source domain
b (array-like (nt,)) – samples weights in the target domain
M (array-like (ns,nt)) – loss matrix
reg (float) – Regularization term for entropic regularization >0
eta (float, optional) – Regularization term for group lasso regularization >0
numItermax (int, optional) – Max number of iterations
numInnerItermax (int, optional) – Max number of iterations (inner sinkhorn solver)
stopInnerThr (float, optional) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional) – Print information along iterations
log (bool, optional) – record log if True
gamma ((ns, nt) array-like) – Optimal transportation matrix for the given parameters
log (dict) – log dictionary return only if log==True in parameters
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
See also
ot.lp.emdUnregularized OT
ot.bregman.sinkhornEntropic regularized OT
ot.optim.cgGeneral regularized OT
Base class for OTDA objects
Note
All estimators should specify all the parameters that can be set
at the class level in their __init__ as explicit keyword
arguments (no *args or **kwargs).
The fit method should:
estimate a cost matrix and store it in a cost_ attribute
estimate a coupling matrix and store it in a coupling_ attribute
estimate distributions from source and target data and store them in mu_s and mu_t attributes
store Xs and Xt in attributes to be used later on in transform and inverse_transform methods
transform method should always get as input a Xs parameter
inverse_transform method should always get as input a Xt parameter
transform_labels method should always get as input a ys parameter
inverse_transform_labels method should always get as input a yt parameter
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The training class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\) and transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for training samples
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
transp_Xs – The source samples samples.
array-like, shape (n_source_samples, n_features)
Transports target samples \(\mathbf{X_t}\) onto source samples \(\mathbf{X_s}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The source class labels
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The target class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xt – The transported target samples.
array-like, shape (n_source_samples, n_features)
Propagate target labels \(\mathbf{y_t}\) to obtain estimated source labels \(\mathbf{y_s}\)
yt (array-like, shape (n_target_samples,))
transp_ys – Estimated soft source labels.
array-like, shape (n_source_samples, nb_classes)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for source samples
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels for target. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
Propagate source labels \(\mathbf{y_s}\) to obtain estimated target labels as in [27].
ys (array-like, shape (n_source_samples,)) – The source class labels
transp_ys – Estimated soft target labels.
array-like, shape (n_target_samples, nb_classes)
References
Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia “Optimal transport for multi-source domain adaptation under target shift”, International Conference on Artificial Intelligence and Statistics (AISTATS), 2019.
ot.da.BaseTransportOT with Laplacian regularization for domain adaptation
OT for image color adaptation with mapping estimation
OT for domain adaptation on empirical distributions
Domain Adaptation OT method based on Earth Mover’s Distance with Laplacian regularization
reg_type (string optional (default='pos')) – Type of the regularization term: ‘pos’ and ‘disp’ for regularization term defined in [2] and [6], respectively.
reg_lap (float, optional (default=1)) – Laplacian regularization parameter
reg_src (float, optional (default=0.5)) – Source relative importance in regularization
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
similarity (string, optional (default="knn")) – The similarity to use either knn or gaussian
similarity_param (int or float, optional (default=None)) – Parameter for the similarity: number of nearest neighbors or bandwidth if similarity=”knn” or “gaussian”, respectively. If None is provided, it is set to 3 or the average pairwise squared Euclidean distance, respectively.
max_iter (int, optional (default=100)) – Max number of BCD iterations
tol (float, optional (default=1e-5)) – Stop threshold on relative loss decrease (>0)
max_inner_iter (int, optional (default=10)) – Max number of iterations (inner CG solver)
inner_tol (float, optional (default=1e-6)) – Stop threshold on error (inner CG solver) (>0)
log (int, optional (default=False)) – Controls the logs of the optimization algorithm
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
References
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
R. Flamary, N. Courty, D. Tuia, A. Rakotomamonjy, “Optimal transport with Laplacian regularization: Applications to domain adaptation and shape matching,” in NIPS Workshop on Optimal Transport and Machine Learning OTML, 2014.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
ot.da.EMDLaplaceTransportOT with Laplacian regularization for domain adaptation
Domain Adaptation OT method based on Earth Mover’s Distance
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
log (int, optional (default=False)) – Controls the logs of the optimization algorithm
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=10)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an infinite cost (10 times the maximum value of the cost matrix)
max_iter (int, optional (default=100000)) – The maximum number of iterations before stopping the optimization algorithm if it has not converged.
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
References
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
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
ot.da.EMDTransportOT with Laplacian regularization for domain adaptation
OT for image color adaptation with mapping estimation
OT for domain adaptation on empirical distributions
Domain Adaptation OT method for multi-source target shift based on Wasserstein barycenter algorithm.
reg_e (float, optional (default=1)) – Entropic regularization parameter
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
A set of optimal couplings between each source domain and the target domain
list of array-like objects, shape K x (n_source_samples, n_target_samples)
Estimated class proportions in the target domain
array-like, shape (n_classes,)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia “Optimal transport for multi-source domain adaptation under target shift”, International Conference on Artificial Intelligence and Statistics (AISTATS), vol. 89, p.849-858, 2019.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Building coupling matrices from a list of source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (list of K array-like objects, shape K x (nk_source_samples, n_features)) – A list of the training input samples.
ys (list of K array-like objects, shape K x (nk_source_samples,)) – A list of the class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Propagate target labels \(\mathbf{y_t}\) to obtain estimated source labels \(\mathbf{y_s}\)
yt (array-like, shape (n_target_samples,)) – The target class labels
transp_ys – A list of estimated soft source labels
list of K array-like objects, shape K x (nk_source_samples, nb_classes)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (list of K array-like objects, shape K x (nk_source_samples, n_features)) – A list of the training input samples.
ys (list of K array-like objects, shape K x (nk_source_samples,)) – A list of the class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
Propagate source labels \(\mathbf{y_s}\) to obtain target labels as in [27]
ys (list of K array-like objects, shape K x (nk_source_samples,)) – A list of the class labels
yt – Estimated soft target labels.
array-like, shape (n_target_samples, nb_classes)
References
Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia “Optimal transport for multi-source domain adaptation under target shift”, International Conference on Artificial Intelligence and Statistics (AISTATS), 2019.
ot.da.JCPOTTransportOT Gaussian Gromov-Wasserstein linear operator between empirical distributions
The function estimates the optimal linear operator that aligns the two empirical distributions optimally wrt the Gromov-Wasserstein distance. This is equivalent to estimating the closed form mapping between two Gaussian distributions \(\mathcal{N}(\mu_s,\Sigma_s)\) and \(\mathcal{N}(\mu_t,\Sigma_t)\) as proposed in [57].
The linear operator from source to target \(M\)
where the matrix \(\mathbf{A}\) and the vector \(\mathbf{b}\) are defined in [57].
sign_eigs (array-like (n_features), str, optional) – sign of the eigenvalues of the mapping matrix, by default all signs will be positive. If ‘skewness’ is provided, the sign of the eigenvalues is selected as the product of the sign of the skewness of the projected data.
log (bool, optional) – record log if True
References
Delon, J., Desolneux, A., & Salmona, A. (2022). Gromov–Wasserstein distances between Gaussian distributions. Journal of Applied Probability, 59(4), 1178-1198.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
ot.da.LinearGWTransportOT linear operator between empirical distributions
The function estimates the optimal linear operator that aligns the two empirical distributions. This is equivalent to estimating the closed form mapping between two Gaussian distributions \(\mathcal{N}(\mu_s,\Sigma_s)\) and \(\mathcal{N}(\mu_t,\Sigma_t)\) as proposed in [14] and discussed in remark 2.29 in [15].
The linear operator from source to target \(M\)
where :
References
Knott, M. and Smith, C. S. “On the optimal mapping of distributions”, Journal of Optimization Theory and Applications Vol 43, 1984
Peyré, G., & Cuturi, M. (2017). “Computational Optimal Transport”, 2018.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Transports target samples \(\mathbf{X_t}\) onto source samples \(\mathbf{X_s}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xt – The transported target samples.
array-like, shape (n_source_samples, n_features)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
ot.da.LinearTransportMappingTransport: DA methods that aims at jointly estimating a optimal transport coupling and the associated mapping
mu (float, optional (default=1)) – Weight for the linear OT loss (>0)
eta (float, optional (default=0.001)) – Regularization term for the linear mapping L (>0)
bias (bool, optional (default=False)) – Estimate linear mapping with constant bias
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
kernel (string, optional (default="linear")) – The kernel to use either linear or gaussian
sigma (float, optional (default=1)) – The gaussian kernel parameter
max_iter (int, optional (default=100)) – Max number of BCD iterations
tol (float, optional (default=1e-5)) – Stop threshold on relative loss decrease (>0)
max_inner_iter (int, optional (default=10)) – Max number of iterations (inner CG solver)
inner_tol (float, optional (default=1e-6)) – Stop threshold on error (inner CG solver) (>0)
log (bool, optional (default=False)) – record log if True
verbose (bool, optional (default=False)) – Print information along iterations
verbose2 (bool, optional (default=False)) – Print information along iterations
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The associated mapping
array-like, shape (n_features (+ 1), n_features), (if bias) for kernel == linear
array-like, shape (n_source_samples (+ 1), n_features), (if bias) for kernel == gaussian
The dictionary of log, empty dict if parameter log is not True
dictionary
References
M. Perrot, N. Courty, R. Flamary, A. Habrard, “Mapping estimation for discrete optimal transport”, Neural Information Processing Systems (NIPS), 2016.
Builds an optimal coupling and estimates the associated mapping from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
ot.da.MappingTransportOT for image color adaptation with mapping estimation
Smooth Strongly Convex Nearest Brenier Potentials (SSNB) is a method from [58] that computes an l-strongly convex potential \(\varphi\) with an L-Lipschitz gradient such that \(\nabla \varphi \# \mu \approx \nu\). This regularity can be enforced only on the components of a partition of the ambient space (encoded by point classes), which is a relaxation compared to imposing global regularity.
SSNBs approach the target measure by solving the optimisation problem:
where \(\mathcal{F}\) is the space functions that are on every set \(E_k\) l-strongly convex with an L-Lipschitz gradient, given \((E_k)_{k \in [K]}\) a partition of the ambient source space.
The problem is solved on “fitting” source and target data via a convex Quadratically Constrained Quadratic Program,
yielding the values phi and the gradients G at at the source points.
The images of “new” source samples are then found by solving a (simpler) Quadratically Constrained Linear Program
at each point, using the fitting “parameters” phi and G. We provide two possible images, which
correspond to “lower” and “upper potentials” ([59], Theorem 3.14). Each of these two images are optimal
solutions of the SSNB problem, and can be used in practice.
Warning
This function requires the CVXPY library
Warning
Accepts any backend but will convert to Numpy then back to the backend.
strongly_convex_constant (float, optional) – constant for the strong convexity of the input potential phi, defaults to 0.6
gradient_lipschitz_constant (float, optional) – constant for the Lipschitz property of the input gradient G, defaults to 1.4
its (int, optional) – number of iterations, defaults to 100
log (bool, optional) – record log if true
seed (int or RandomState or None, optional) – Seed used for random number generator (for the initialisation in fit.
References
François-Pierre Paty, Alexandre d’Aspremont, and Marco Cuturi. Regularity as regularization: Smooth and strongly convex brenier potentials in optimal transport. In International Conference on Artificial Intelligence and Statistics, pages 1222–1232. PMLR, 2020.
Adrien B Taylor. Convex interpolation and performance estimation of first-order methods for convex optimization. PhD thesis, Catholic University of Louvain, Louvain-la-Neuve, Belgium, 2017.
See also
ot.mapping.nearest_brenier_potential_fitFitting the SSNB on source and target data
ot.mapping.nearest_brenier_potential_predict_boundsPredicting SSNB images on new source data
Fits the Smooth Strongly Convex Nearest Brenier Potential [58] to the source data Xs to the target data
Xt, with the partition given by the (optional) labels ys.
Wrapper for ot.mapping.nearest_brenier_potential_fit.
Warning
This function requires the CVXPY library
Warning
Accepts any backend but will convert to Numpy then back to the backend.
Xs (array-like (n, d)) – source points used to compute the optimal values phi and G
ys (array-like (n,), optional) – classes of the reference points, defaults to a single class
Xt (array-like (n, d)) – values of the gradients at the reference points X
yt (optional) – ignored.
self – Returns self.
References
François-Pierre Paty, Alexandre d’Aspremont, and Marco Cuturi. Regularity as regularization: Smooth and strongly convex brenier potentials in optimal transport. In International Conference on Artificial Intelligence and Statistics, pages 1222–1232. PMLR, 2020.
See also
ot.mapping.nearest_brenier_potential_fitFitting the SSNB on source and target data
Computes the images of the new source samples Xs of classes ys by the fitted
Smooth Strongly Convex Nearest Brenier Potentials (SSNB) [58]. The output is the images of two SSNB optimal
maps, called ‘lower’ and ‘upper’ potentials (from [59], Theorem 3.14).
Wrapper for nearest_brenier_potential_predict_bounds.
Warning
This function requires the CVXPY library
Warning
Accepts any backend but will convert to Numpy then back to the backend.
Xs (array-like (m, d)) – input source points
ys (: array_like (m,), optional) – classes of the input source points, defaults to a single class
G_lu – gradients of the lower and upper bounding potentials at Y (images of the source inputs)
array-like (2, m, d)
References
François-Pierre Paty, Alexandre d’Aspremont, and Marco Cuturi. Regularity as regularization: Smooth and strongly convex brenier potentials in optimal transport. In International Conference on Artificial Intelligence and Statistics, pages 1222–1232. PMLR, 2020.
Adrien B Taylor. Convex interpolation and performance estimation of first-order methods for convex optimization. PhD thesis, Catholic University of Louvain, Louvain-la-Neuve, Belgium, 2017.
See also
ot.mapping.nearest_brenier_potential_predict_boundsPredicting SSNB images on new source data
Domain Adaptation OT method based on sinkhorn algorithm + L1L2 class regularization.
reg_e (float, optional (default=1)) – Entropic regularization parameter
reg_cl (float, optional (default=0.1)) – Class regularization parameter
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
max_inner_iter (int, float, optional (default=200)) – The number of iteration in the inner loop
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=10)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an infinite cost (10 times the maximum value of the cost matrix)
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
ot.da.SinkhornL1l2TransportDomain Adaptation OT method based on sinkhorn algorithm + LpL1 class regularization.
reg_e (float, optional (default=1)) – Entropic regularization parameter
reg_cl (float, optional (default=0.1)) – Class regularization parameter
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
max_inner_iter (int, float, optional (default=200)) – The number of iteration in the inner loop
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=np.inf)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit a cost defined by limit_max.
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
ot.da.SinkhornLpl1TransportOT for domain adaptation on empirical distributions
Domain Adaptation OT method based on Sinkhorn Algorithm
reg_e (float, optional (default=1)) – Entropic regularization parameter
max_iter (int, float, optional (default=1000)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
tol (float, optional (default=10e-9)) – The precision required to stop the optimization algorithm.
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (int, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values. Accepted values are ‘median’, ‘max’, ‘log’ and ‘loglog’.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="continuous")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the nearest neighbor method proposed in [6] while “continuous” use the out of sample method from [66] and [19].
limit_max (float, optional (default=np.inf)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an cost defined by this variable
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
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
M. Cuturi, Sinkhorn Distances : Lightspeed Computation of Optimal Transport, Advances in Neural Information Processing Systems (NIPS) 26, 2013
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Seguy, V., Bhushan Damodaran, B., Flamary, R., Courty, N., Rolet, A. & Blondel, M. Large-scale Optimal Transport and Mapping Estimation. International Conference on Learning Representation (2018)
Pooladian, Aram-Alexandre, and Jonathan Niles-Weed. “Entropic estimation of optimal transport maps.” arXiv preprint arXiv:2109.12004 (2021).
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Transports target samples \(\mathbf{X_t}\) onto source samples \(\mathbf{X_s}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for source samples
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels for target. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xt – The transport target samples.
array-like, shape (n_source_samples, n_features)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for source samples
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels for target. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
ot.da.SinkhornTransportOT with Laplacian regularization for domain adaptation
OT for image color adaptation with mapping estimation
OT for domain adaptation on empirical distributions
Domain Adaptation unbalanced OT method based on sinkhorn algorithm
reg_e (float, optional (default=1)) – Entropic regularization parameter
reg_m (float, optional (default=0.1)) – Mass regularization parameter
method (str) – method used for the solver either ‘sinkhorn’, ‘sinkhorn_stabilized’ or ‘sinkhorn_epsilon_scaling’, see those function for specific parameters
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=10)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an infinite cost (10 times the maximum value of the cost matrix)
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
Chizat, L., Peyré, G., Schmitzer, B., & Vialard, F. X. (2016). Scaling algorithms for unbalanced transport problems. arXiv preprint arXiv:1607.05816.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Base class for OTDA objects
Note
All estimators should specify all the parameters that can be set
at the class level in their __init__ as explicit keyword
arguments (no *args or **kwargs).
The fit method should:
estimate a cost matrix and store it in a cost_ attribute
estimate a coupling matrix and store it in a coupling_ attribute
estimate distributions from source and target data and store them in mu_s and mu_t attributes
store Xs and Xt in attributes to be used later on in transform and inverse_transform methods
transform method should always get as input a Xs parameter
inverse_transform method should always get as input a Xt parameter
transform_labels method should always get as input a ys parameter
inverse_transform_labels method should always get as input a yt parameter
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The training class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\) and transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for training samples
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
transp_Xs – The source samples samples.
array-like, shape (n_source_samples, n_features)
Transports target samples \(\mathbf{X_t}\) onto source samples \(\mathbf{X_s}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The source class labels
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The target class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xt – The transported target samples.
array-like, shape (n_source_samples, n_features)
Propagate target labels \(\mathbf{y_t}\) to obtain estimated source labels \(\mathbf{y_s}\)
yt (array-like, shape (n_target_samples,))
transp_ys – Estimated soft source labels.
array-like, shape (n_source_samples, nb_classes)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for source samples
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels for target. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
Propagate source labels \(\mathbf{y_s}\) to obtain estimated target labels as in [27].
ys (array-like, shape (n_source_samples,)) – The source class labels
transp_ys – Estimated soft target labels.
array-like, shape (n_target_samples, nb_classes)
References
Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia “Optimal transport for multi-source domain adaptation under target shift”, International Conference on Artificial Intelligence and Statistics (AISTATS), 2019.
Domain Adaptation OT method based on Earth Mover’s Distance with Laplacian regularization
reg_type (string optional (default='pos')) – Type of the regularization term: ‘pos’ and ‘disp’ for regularization term defined in [2] and [6], respectively.
reg_lap (float, optional (default=1)) – Laplacian regularization parameter
reg_src (float, optional (default=0.5)) – Source relative importance in regularization
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
similarity (string, optional (default="knn")) – The similarity to use either knn or gaussian
similarity_param (int or float, optional (default=None)) – Parameter for the similarity: number of nearest neighbors or bandwidth if similarity=”knn” or “gaussian”, respectively. If None is provided, it is set to 3 or the average pairwise squared Euclidean distance, respectively.
max_iter (int, optional (default=100)) – Max number of BCD iterations
tol (float, optional (default=1e-5)) – Stop threshold on relative loss decrease (>0)
max_inner_iter (int, optional (default=10)) – Max number of iterations (inner CG solver)
inner_tol (float, optional (default=1e-6)) – Stop threshold on error (inner CG solver) (>0)
log (int, optional (default=False)) – Controls the logs of the optimization algorithm
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
References
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
R. Flamary, N. Courty, D. Tuia, A. Rakotomamonjy, “Optimal transport with Laplacian regularization: Applications to domain adaptation and shape matching,” in NIPS Workshop on Optimal Transport and Machine Learning OTML, 2014.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Domain Adaptation OT method based on Earth Mover’s Distance
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
log (int, optional (default=False)) – Controls the logs of the optimization algorithm
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=10)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an infinite cost (10 times the maximum value of the cost matrix)
max_iter (int, optional (default=100000)) – The maximum number of iterations before stopping the optimization algorithm if it has not converged.
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
References
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
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Domain Adaptation OT method for multi-source target shift based on Wasserstein barycenter algorithm.
reg_e (float, optional (default=1)) – Entropic regularization parameter
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
A set of optimal couplings between each source domain and the target domain
list of array-like objects, shape K x (n_source_samples, n_target_samples)
Estimated class proportions in the target domain
array-like, shape (n_classes,)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia “Optimal transport for multi-source domain adaptation under target shift”, International Conference on Artificial Intelligence and Statistics (AISTATS), vol. 89, p.849-858, 2019.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Building coupling matrices from a list of source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (list of K array-like objects, shape K x (nk_source_samples, n_features)) – A list of the training input samples.
ys (list of K array-like objects, shape K x (nk_source_samples,)) – A list of the class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Propagate target labels \(\mathbf{y_t}\) to obtain estimated source labels \(\mathbf{y_s}\)
yt (array-like, shape (n_target_samples,)) – The target class labels
transp_ys – A list of estimated soft source labels
list of K array-like objects, shape K x (nk_source_samples, nb_classes)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (list of K array-like objects, shape K x (nk_source_samples, n_features)) – A list of the training input samples.
ys (list of K array-like objects, shape K x (nk_source_samples,)) – A list of the class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
Propagate source labels \(\mathbf{y_s}\) to obtain target labels as in [27]
ys (list of K array-like objects, shape K x (nk_source_samples,)) – A list of the class labels
yt – Estimated soft target labels.
array-like, shape (n_target_samples, nb_classes)
References
Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia “Optimal transport for multi-source domain adaptation under target shift”, International Conference on Artificial Intelligence and Statistics (AISTATS), 2019.
OT Gaussian Gromov-Wasserstein linear operator between empirical distributions
The function estimates the optimal linear operator that aligns the two empirical distributions optimally wrt the Gromov-Wasserstein distance. This is equivalent to estimating the closed form mapping between two Gaussian distributions \(\mathcal{N}(\mu_s,\Sigma_s)\) and \(\mathcal{N}(\mu_t,\Sigma_t)\) as proposed in [57].
The linear operator from source to target \(M\)
where the matrix \(\mathbf{A}\) and the vector \(\mathbf{b}\) are defined in [57].
sign_eigs (array-like (n_features), str, optional) – sign of the eigenvalues of the mapping matrix, by default all signs will be positive. If ‘skewness’ is provided, the sign of the eigenvalues is selected as the product of the sign of the skewness of the projected data.
log (bool, optional) – record log if True
References
Delon, J., Desolneux, A., & Salmona, A. (2022). Gromov–Wasserstein distances between Gaussian distributions. Journal of Applied Probability, 59(4), 1178-1198.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
OT linear operator between empirical distributions
The function estimates the optimal linear operator that aligns the two empirical distributions. This is equivalent to estimating the closed form mapping between two Gaussian distributions \(\mathcal{N}(\mu_s,\Sigma_s)\) and \(\mathcal{N}(\mu_t,\Sigma_t)\) as proposed in [14] and discussed in remark 2.29 in [15].
The linear operator from source to target \(M\)
where :
References
Knott, M. and Smith, C. S. “On the optimal mapping of distributions”, Journal of Optimization Theory and Applications Vol 43, 1984
Peyré, G., & Cuturi, M. (2017). “Computational Optimal Transport”, 2018.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Transports target samples \(\mathbf{X_t}\) onto source samples \(\mathbf{X_s}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xt – The transported target samples.
array-like, shape (n_source_samples, n_features)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
MappingTransport: DA methods that aims at jointly estimating a optimal transport coupling and the associated mapping
mu (float, optional (default=1)) – Weight for the linear OT loss (>0)
eta (float, optional (default=0.001)) – Regularization term for the linear mapping L (>0)
bias (bool, optional (default=False)) – Estimate linear mapping with constant bias
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
kernel (string, optional (default="linear")) – The kernel to use either linear or gaussian
sigma (float, optional (default=1)) – The gaussian kernel parameter
max_iter (int, optional (default=100)) – Max number of BCD iterations
tol (float, optional (default=1e-5)) – Stop threshold on relative loss decrease (>0)
max_inner_iter (int, optional (default=10)) – Max number of iterations (inner CG solver)
inner_tol (float, optional (default=1e-6)) – Stop threshold on error (inner CG solver) (>0)
log (bool, optional (default=False)) – record log if True
verbose (bool, optional (default=False)) – Print information along iterations
verbose2 (bool, optional (default=False)) – Print information along iterations
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The associated mapping
array-like, shape (n_features (+ 1), n_features), (if bias) for kernel == linear
array-like, shape (n_source_samples (+ 1), n_features), (if bias) for kernel == gaussian
The dictionary of log, empty dict if parameter log is not True
dictionary
References
M. Perrot, N. Courty, R. Flamary, A. Habrard, “Mapping estimation for discrete optimal transport”, Neural Information Processing Systems (NIPS), 2016.
Builds an optimal coupling and estimates the associated mapping from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
Smooth Strongly Convex Nearest Brenier Potentials (SSNB) is a method from [58] that computes an l-strongly convex potential \(\varphi\) with an L-Lipschitz gradient such that \(\nabla \varphi \# \mu \approx \nu\). This regularity can be enforced only on the components of a partition of the ambient space (encoded by point classes), which is a relaxation compared to imposing global regularity.
SSNBs approach the target measure by solving the optimisation problem:
where \(\mathcal{F}\) is the space functions that are on every set \(E_k\) l-strongly convex with an L-Lipschitz gradient, given \((E_k)_{k \in [K]}\) a partition of the ambient source space.
The problem is solved on “fitting” source and target data via a convex Quadratically Constrained Quadratic Program,
yielding the values phi and the gradients G at at the source points.
The images of “new” source samples are then found by solving a (simpler) Quadratically Constrained Linear Program
at each point, using the fitting “parameters” phi and G. We provide two possible images, which
correspond to “lower” and “upper potentials” ([59], Theorem 3.14). Each of these two images are optimal
solutions of the SSNB problem, and can be used in practice.
Warning
This function requires the CVXPY library
Warning
Accepts any backend but will convert to Numpy then back to the backend.
strongly_convex_constant (float, optional) – constant for the strong convexity of the input potential phi, defaults to 0.6
gradient_lipschitz_constant (float, optional) – constant for the Lipschitz property of the input gradient G, defaults to 1.4
its (int, optional) – number of iterations, defaults to 100
log (bool, optional) – record log if true
seed (int or RandomState or None, optional) – Seed used for random number generator (for the initialisation in fit.
References
François-Pierre Paty, Alexandre d’Aspremont, and Marco Cuturi. Regularity as regularization: Smooth and strongly convex brenier potentials in optimal transport. In International Conference on Artificial Intelligence and Statistics, pages 1222–1232. PMLR, 2020.
Adrien B Taylor. Convex interpolation and performance estimation of first-order methods for convex optimization. PhD thesis, Catholic University of Louvain, Louvain-la-Neuve, Belgium, 2017.
See also
ot.mapping.nearest_brenier_potential_fitFitting the SSNB on source and target data
ot.mapping.nearest_brenier_potential_predict_boundsPredicting SSNB images on new source data
Fits the Smooth Strongly Convex Nearest Brenier Potential [58] to the source data Xs to the target data
Xt, with the partition given by the (optional) labels ys.
Wrapper for ot.mapping.nearest_brenier_potential_fit.
Warning
This function requires the CVXPY library
Warning
Accepts any backend but will convert to Numpy then back to the backend.
Xs (array-like (n, d)) – source points used to compute the optimal values phi and G
ys (array-like (n,), optional) – classes of the reference points, defaults to a single class
Xt (array-like (n, d)) – values of the gradients at the reference points X
yt (optional) – ignored.
self – Returns self.
References
François-Pierre Paty, Alexandre d’Aspremont, and Marco Cuturi. Regularity as regularization: Smooth and strongly convex brenier potentials in optimal transport. In International Conference on Artificial Intelligence and Statistics, pages 1222–1232. PMLR, 2020.
See also
ot.mapping.nearest_brenier_potential_fitFitting the SSNB on source and target data
Computes the images of the new source samples Xs of classes ys by the fitted
Smooth Strongly Convex Nearest Brenier Potentials (SSNB) [58]. The output is the images of two SSNB optimal
maps, called ‘lower’ and ‘upper’ potentials (from [59], Theorem 3.14).
Wrapper for nearest_brenier_potential_predict_bounds.
Warning
This function requires the CVXPY library
Warning
Accepts any backend but will convert to Numpy then back to the backend.
Xs (array-like (m, d)) – input source points
ys (: array_like (m,), optional) – classes of the input source points, defaults to a single class
G_lu – gradients of the lower and upper bounding potentials at Y (images of the source inputs)
array-like (2, m, d)
References
François-Pierre Paty, Alexandre d’Aspremont, and Marco Cuturi. Regularity as regularization: Smooth and strongly convex brenier potentials in optimal transport. In International Conference on Artificial Intelligence and Statistics, pages 1222–1232. PMLR, 2020.
Adrien B Taylor. Convex interpolation and performance estimation of first-order methods for convex optimization. PhD thesis, Catholic University of Louvain, Louvain-la-Neuve, Belgium, 2017.
See also
ot.mapping.nearest_brenier_potential_predict_boundsPredicting SSNB images on new source data
Domain Adaptation OT method based on sinkhorn algorithm + L1L2 class regularization.
reg_e (float, optional (default=1)) – Entropic regularization parameter
reg_cl (float, optional (default=0.1)) – Class regularization parameter
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
max_inner_iter (int, float, optional (default=200)) – The number of iteration in the inner loop
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=10)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an infinite cost (10 times the maximum value of the cost matrix)
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Domain Adaptation OT method based on sinkhorn algorithm + LpL1 class regularization.
reg_e (float, optional (default=1)) – Entropic regularization parameter
reg_cl (float, optional (default=0.1)) – Class regularization parameter
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
max_inner_iter (int, float, optional (default=200)) – The number of iteration in the inner loop
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=np.inf)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit a cost defined by limit_max.
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Domain Adaptation OT method based on Sinkhorn Algorithm
reg_e (float, optional (default=1)) – Entropic regularization parameter
max_iter (int, float, optional (default=1000)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
tol (float, optional (default=10e-9)) – The precision required to stop the optimization algorithm.
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (int, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values. Accepted values are ‘median’, ‘max’, ‘log’ and ‘loglog’.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="continuous")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the nearest neighbor method proposed in [6] while “continuous” use the out of sample method from [66] and [19].
limit_max (float, optional (default=np.inf)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an cost defined by this variable
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
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
M. Cuturi, Sinkhorn Distances : Lightspeed Computation of Optimal Transport, Advances in Neural Information Processing Systems (NIPS) 26, 2013
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Seguy, V., Bhushan Damodaran, B., Flamary, R., Courty, N., Rolet, A. & Blondel, M. Large-scale Optimal Transport and Mapping Estimation. International Conference on Learning Representation (2018)
Pooladian, Aram-Alexandre, and Jonathan Niles-Weed. “Entropic estimation of optimal transport maps.” arXiv preprint arXiv:2109.12004 (2021).
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
Transports target samples \(\mathbf{X_t}\) onto source samples \(\mathbf{X_s}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for source samples
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels for target. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xt – The transport target samples.
array-like, shape (n_source_samples, n_features)
Transports source samples \(\mathbf{X_s}\) onto target ones \(\mathbf{X_t}\)
Xs (array-like, shape (n_source_samples, n_features)) – The source input samples.
ys (array-like, shape (n_source_samples,)) – The class labels for source samples
Xt (array-like, shape (n_target_samples, n_features)) – The target input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels for target. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
batch_size (int, optional (default=128)) – The batch size for out of sample inverse transform
transp_Xs – The transport source samples.
array-like, shape (n_source_samples, n_features)
Domain Adaptation unbalanced OT method based on sinkhorn algorithm
reg_e (float, optional (default=1)) – Entropic regularization parameter
reg_m (float, optional (default=0.1)) – Mass regularization parameter
method (str) – method used for the solver either ‘sinkhorn’, ‘sinkhorn_stabilized’ or ‘sinkhorn_epsilon_scaling’, see those function for specific parameters
max_iter (int, float, optional (default=10)) – The minimum number of iteration before stopping the optimization algorithm if it has not converged
tol (float, optional (default=10e-9)) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional (default=False)) – Controls the verbosity of the optimization algorithm
log (bool, optional (default=False)) – Controls the logs of the optimization algorithm
metric (string, optional (default="sqeuclidean")) – The ground metric for the Wasserstein problem
norm (string, optional (default=None)) – If given, normalize the ground metric to avoid numerical errors that can occur with large metric values.
distribution_estimation (callable, optional (defaults to the uniform)) – The kind of distribution estimation to employ
out_of_sample_map (string, optional (default="ferradans")) – The kind of out of sample mapping to apply to transport samples from a domain into another one. Currently the only possible option is “ferradans” which uses the method proposed in [6].
limit_max (float, optional (default=10)) – Controls the semi supervised mode. Transport between labeled source and target samples of different classes will exhibit an infinite cost (10 times the maximum value of the cost matrix)
The optimal coupling
array-like, shape (n_source_samples, n_target_samples)
The dictionary of log, empty dict if parameter log is not True
dictionary
References
Chizat, L., Peyré, G., Schmitzer, B., & Vialard, F. X. (2016). Scaling algorithms for unbalanced transport problems. arXiv preprint arXiv:1607.05816.
Ferradans, S., Papadakis, N., Peyré, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.
Build a coupling matrix from source and target sets of samples \((\mathbf{X_s}, \mathbf{y_s})\) and \((\mathbf{X_t}, \mathbf{y_t})\)
Xs (array-like, shape (n_source_samples, n_features)) – The training input samples.
ys (array-like, shape (n_source_samples,)) – The class labels
Xt (array-like, shape (n_target_samples, n_features)) – The training input samples.
yt (array-like, shape (n_target_samples,)) –
The class labels. If some target samples are unlabelled, fill the \(\mathbf{y_t}\)’s elements with -1.
Warning: Note that, due to this convention -1 cannot be used as a class label
self – Returns self.
estimates a uniform distribution from an array of samples \(\mathbf{X}\)
X (array-like, shape (n_samples, n_features)) – The array of samples
mu – The uniform distribution estimated from \(\mathbf{X}\)
array-like, shape (n_samples,)
Solve the optimal transport problem (OT) with Laplacian regularization
where:
\(\mathbf{a}\) and \(\mathbf{b}\) are source and target weights (sum to 1)
\(\mathbf{x_s}\) and \(\mathbf{x_t}\) are source and target samples
\(\mathbf{M}\) is the (ns, nt) metric cost matrix
\(\Omega_\alpha\) is the Laplacian regularization term
with \(\mathbf{S^s}_{i,j}, \mathbf{S^t}_{i,j}\) denoting source and target similarity matrices and \(T(\cdot)\) being a barycentric mapping.
The algorithm used for solving the problem is the conditional gradient algorithm as proposed in [5].
a (array-like (ns,)) – samples weights in the source domain
b (array-like (nt,)) – samples weights in the target domain
xs (array-like (ns,d)) – samples in the source domain
xt (array-like (nt,d)) – samples in the target domain
M (array-like (ns,nt)) – loss matrix
sim (string, optional) – Type of similarity (‘knn’ or ‘gauss’) used to construct the Laplacian.
sim_param (int or float, optional) – Parameter (number of the nearest neighbors for sim=’knn’ or bandwidth for sim=’gauss’) used to compute the Laplacian.
reg (string) – Type of Laplacian regularization
eta (float) – Regularization term for Laplacian regularization
alpha (float) – Regularization term for source domain’s importance in regularization
numItermax (int, optional) – Max number of iterations
stopThr (float, optional) – Stop threshold on error (inner emd solver) (>0)
numInnerItermax (int, optional) – Max number of iterations (inner CG solver)
stopInnerThr (float, optional) – Stop threshold on error (inner CG solver) (>0)
verbose (bool, optional) – Print information along iterations
log (bool, optional) – record log if True
gamma ((ns, nt) array-like) – Optimal transportation matrix for the given parameters
log (dict) – log dictionary return only if log==True in parameters
References
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
R. Flamary, N. Courty, D. Tuia, A. Rakotomamonjy, “Optimal transport with Laplacian regularization: Applications to domain adaptation and shape matching,” in NIPS Workshop on Optimal Transport and Machine Learning OTML, 2014.
See also
ot.lp.emdUnregularized OT
ot.optim.cgGeneral regularized OT
Solve the entropic regularization optimal transport problem with group lasso regularization
The function solves the following optimization problem:
where :
\(\mathbf{M}\) is the (ns, nt) metric cost matrix
\(\Omega_e\) is the entropic regularization term \(\Omega_e(\gamma)=\sum_{i,j} \gamma_{i,j}\log(\gamma_{i,j})\)
\(\Omega_g\) is the group lasso regularization term \(\Omega_g(\gamma)=\sum_{i,c} \|\gamma_{i,\mathcal{I}_c}\|^2\) where \(\mathcal{I}_c\) are the index of samples from class c in the source domain.
\(\mathbf{a}\) and \(\mathbf{b}\) are source and target weights (sum to 1)
The algorithm used for solving the problem is the generalized conditional gradient as proposed in [5, 7].
a (array-like (ns,)) – samples weights in the source domain
labels_a (array-like (ns,)) – labels of samples in the source domain
b (array-like (nt,)) – samples in the target domain
M (array-like (ns,nt)) – loss matrix
reg (float) – Regularization term for entropic regularization >0
eta (float, optional) – Regularization term for group lasso regularization >0
numItermax (int, optional) – Max number of iterations
numInnerItermax (int, optional) – Max number of iterations (inner sinkhorn solver)
stopInnerThr (float, optional) – Stop threshold on error (inner sinkhorn solver) (>0)
eps (float, optional (default=1e-12)) – Small value to avoid division by zero
verbose (bool, optional) – Print information along iterations
log (bool, optional) – record log if True
gamma ((ns, nt) array-like) – Optimal transportation matrix for the given parameters
log (dict) – log dictionary return only if log==True in parameters
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
See also
ot.optim.gcgGeneralized conditional gradient for OT problems
Solve the entropic regularization optimal transport problem with non-convex group lasso regularization
The function solves the following optimization problem:
where :
\(\mathbf{M}\) is the (ns, nt) metric cost matrix
\(\Omega_e\) is the entropic regularization term \(\Omega_e (\gamma)=\sum_{i,j} \gamma_{i,j}\log(\gamma_{i,j})\)
\(\Omega_g\) is the group lasso regularization term \(\Omega_g(\gamma)=\sum_{i,c} \|\gamma_{i,\mathcal{I}_c}\|^{1/2}_1\) where \(\mathcal{I}_c\) are the index of samples from class c in the source domain.
\(\mathbf{a}\) and \(\mathbf{b}\) are source and target weights (sum to 1)
The algorithm used for solving the problem is the generalized conditional gradient as proposed in [5, 7].
a (array-like (ns,)) – samples weights in the source domain
labels_a (array-like (ns,)) – labels of samples in the source domain
b (array-like (nt,)) – samples weights in the target domain
M (array-like (ns,nt)) – loss matrix
reg (float) – Regularization term for entropic regularization >0
eta (float, optional) – Regularization term for group lasso regularization >0
numItermax (int, optional) – Max number of iterations
numInnerItermax (int, optional) – Max number of iterations (inner sinkhorn solver)
stopInnerThr (float, optional) – Stop threshold on error (inner sinkhorn solver) (>0)
verbose (bool, optional) – Print information along iterations
log (bool, optional) – record log if True
gamma ((ns, nt) array-like) – Optimal transportation matrix for the given parameters
log (dict) – log dictionary return only if log==True in parameters
References
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
Rakotomamonjy, A., Flamary, R., & Courty, N. (2015). Generalized conditional gradient: analysis of convergence and applications. arXiv preprint arXiv:1510.06567.
See also
ot.lp.emdUnregularized OT
ot.bregman.sinkhornEntropic regularized OT
ot.optim.cgGeneral regularized OT