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

Method inverse_transform

ot/da.py:767–830  ·  view source on GitHub ↗

r"""Transports target samples :math:`\mathbf{X_t}` onto source samples :math:`\mathbf{X_s}` Parameters ---------- Xs : array-like, shape (n_source_samples, n_features) The source input samples. ys : array-like, shape (n_source_samples,) The so

(self, Xs=None, ys=None, Xt=None, yt=None, batch_size=128)

Source from the content-addressed store, hash-verified

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}`
769
770 Parameters
771 ----------
772 Xs : array-like, shape (n_source_samples, n_features)
773 The source input samples.
774 ys : array-like, shape (n_source_samples,)
775 The source class labels
776 Xt : array-like, shape (n_target_samples, n_features)
777 The target input samples.
778 yt : array-like, shape (n_target_samples,)
779 The target class labels. If some target samples are unlabelled, fill the
780 :math:`\mathbf{y_t}`'s elements with -1.
781
782 Warning: Note that, due to this convention -1 cannot be used as a
783 class label
784 batch_size : int, optional (default=128)
785 The batch size for out of sample inverse transform
786
787 Returns
788 -------
789 transp_Xt : array-like, shape (n_source_samples, n_features)
790 The transported target samples.
791 """
792 nx = self.nx
793
794 # check the necessary inputs parameters are here
795 if check_params(Xt=Xt):
796 if nx.array_equal(self.xt_, Xt):
797 # perform standard barycentric mapping
798 transp_ = self.coupling_.T / nx.sum(self.coupling_, 0)[:, None]
799
800 # set nans to 0
801 transp_ = nx.nan_to_num(transp_, nan=0, posinf=0, neginf=0)
802
803 # compute transported samples
804 transp_Xt = nx.dot(transp_, self.xs_)
805 else:
806 # perform out of sample mapping
807 indices = nx.arange(Xt.shape[0])
808 batch_ind = [
809 indices[i : i + batch_size]
810 for i in range(0, len(indices), batch_size)
811 ]
812
813 transp_Xt = []
814 for bi in batch_ind:
815 D0 = dist(Xt[bi], self.xt_)
816 idx = nx.argmin(D0, axis=1)
817
818 # transport the target samples
819 transp_ = self.coupling_.T / nx.sum(self.coupling_, 0)[:, None]
820 transp_ = nx.nan_to_num(transp_, nan=0, posinf=0, neginf=0)
821 transp_Xt_ = nx.dot(transp_, self.xs_)
822
823 # define the transported points
824 transp_Xt_ = transp_Xt_[idx, :] + Xt[bi] - self.xt_[idx, :]

Calls 9

check_paramsFunction · 0.85
distFunction · 0.70
array_equalMethod · 0.45
sumMethod · 0.45
nan_to_numMethod · 0.45
dotMethod · 0.45
arangeMethod · 0.45
argminMethod · 0.45
concatenateMethod · 0.45