MCPcopy Create free account
hub / github.com/PythonOT/POT / transform_labels

Method transform_labels

ot/da.py:727–765  ·  view source on GitHub ↗

r"""Propagate source labels :math:`\mathbf{y_s}` to obtain estimated target labels as in :ref:`[27] `. Parameters ---------- ys : array-like, shape (n_source_samples,) The source class labels Returns

(self, ys=None)

Source from the content-addressed store, hash-verified

725 return transp_Xs
726
727 def transform_labels(self, ys=None):
728 r"""Propagate source labels :math:`\mathbf{y_s}` to obtain estimated target labels as in
729 :ref:`[27] <references-basetransport-transform-labels>`.
730
731 Parameters
732 ----------
733 ys : array-like, shape (n_source_samples,)
734 The source class labels
735
736 Returns
737 -------
738 transp_ys : array-like, shape (n_target_samples, nb_classes)
739 Estimated soft target labels.
740
741
742 .. _references-basetransport-transform-labels:
743 References
744 ----------
745 .. [27] Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia
746 "Optimal transport for multi-source domain adaptation under target shift",
747 International Conference on Artificial Intelligence and Statistics (AISTATS), 2019.
748
749 """
750 nx = self.nx
751
752 # check the necessary inputs parameters are here
753 if check_params(ys=ys):
754 # perform label propagation
755 transp = self.coupling_ / nx.sum(self.coupling_, axis=0)[None, :]
756
757 # set nans to 0
758 transp = nx.nan_to_num(transp, nan=0, posinf=0, neginf=0)
759
760 # compute propagated labels
761 labels = label_normalization(ys)
762 masks = labels_to_masks(labels, nx=nx, type_as=transp)
763 transp_ys = nx.dot(masks.T, transp)
764
765 return transp_ys.T
766
767 def inverse_transform(self, Xs=None, ys=None, Xt=None, yt=None, batch_size=128):
768 r"""Transports target samples :math:`\mathbf{X_t}` onto source samples :math:`\mathbf{X_s}`

Calls 6

check_paramsFunction · 0.85
label_normalizationFunction · 0.85
labels_to_masksFunction · 0.85
sumMethod · 0.45
nan_to_numMethod · 0.45
dotMethod · 0.45