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

Method fit

ot/da.py:919–974  ·  view source on GitHub ↗

r"""Build a coupling matrix from source and target sets of samples :math:`(\mathbf{X_s}, \mathbf{y_s})` and :math:`(\mathbf{X_t}, \mathbf{y_t})` Parameters ---------- Xs : array-like, shape (n_source_samples, n_features) The training input samples.

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

Source from the content-addressed store, hash-verified

917 self.distribution_estimation = distribution_estimation
918
919 def fit(self, Xs=None, ys=None, Xt=None, yt=None):
920 r"""Build a coupling matrix from source and target sets of samples
921 :math:`(\mathbf{X_s}, \mathbf{y_s})` and :math:`(\mathbf{X_t}, \mathbf{y_t})`
922
923 Parameters
924 ----------
925 Xs : array-like, shape (n_source_samples, n_features)
926 The training input samples.
927 ys : array-like, shape (n_source_samples,)
928 The class labels
929 Xt : array-like, shape (n_target_samples, n_features)
930 The training input samples.
931 yt : array-like, shape (n_target_samples,)
932 The class labels. If some target samples are unlabelled, fill the
933 :math:`\mathbf{y_t}`'s elements with -1.
934
935 Warning: Note that, due to this convention -1 cannot be used as a
936 class label
937
938 Returns
939 -------
940 self : object
941 Returns self.
942 """
943 nx = self._get_backend(Xs, ys, Xt, yt)
944 self.nx = nx
945
946 self.mu_s = self.distribution_estimation(Xs)
947 self.mu_t = self.distribution_estimation(Xt)
948
949 # coupling estimation
950 returned_ = empirical_bures_wasserstein_mapping(
951 Xs,
952 Xt,
953 reg=self.reg,
954 ws=nx.reshape(self.mu_s, (-1, 1)),
955 wt=nx.reshape(self.mu_t, (-1, 1)),
956 bias=self.bias,
957 log=self.log,
958 )
959
960 # deal with the value of log
961 if self.log:
962 self.A_, self.B_, self.log_ = returned_
963 else:
964 (
965 self.A_,
966 self.B_,
967 ) = returned_
968 self.log_ = dict()
969
970 # re compute inverse mapping
971 self.A1_ = nx.inv(self.A_)
972 self.B1_ = -nx.dot(self.B_, self.A1_)
973
974 return self
975
976 def transform(self, Xs=None, ys=None, Xt=None, yt=None, batch_size=128):

Callers 1

Calls 5

_get_backendMethod · 0.80
reshapeMethod · 0.45
invMethod · 0.45
dotMethod · 0.45

Tested by 1