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

Method fit

ot/da.py:1261–1316  ·  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

1259 self.out_of_sample_map = out_of_sample_map
1260
1261 def fit(self, Xs=None, ys=None, Xt=None, yt=None):
1262 r"""Build a coupling matrix from source and target sets of samples
1263 :math:`(\mathbf{X_s}, \mathbf{y_s})` and :math:`(\mathbf{X_t}, \mathbf{y_t})`
1264
1265 Parameters
1266 ----------
1267 Xs : array-like, shape (n_source_samples, n_features)
1268 The training input samples.
1269 ys : array-like, shape (n_source_samples,)
1270 The class labels
1271 Xt : array-like, shape (n_target_samples, n_features)
1272 The training input samples.
1273 yt : array-like, shape (n_target_samples,)
1274 The class labels. If some target samples are unlabelled, fill the
1275 :math:`\mathbf{y_t}`'s elements with -1.
1276
1277 Warning: Note that, due to this convention -1 cannot be used as a
1278 class label
1279
1280 Returns
1281 -------
1282 self : object
1283 Returns self.
1284 """
1285
1286 super(SinkhornTransport, self).fit(Xs, ys, Xt, yt)
1287
1288 if self.out_of_sample_map == "continuous":
1289 self.log = True
1290 if not self.method == "sinkhorn_log":
1291 self.method = "sinkhorn_log"
1292 warnings.warn(
1293 "The method has been set to 'sinkhorn_log' as it is the only method available for out_of_sample_map='continuous'"
1294 )
1295
1296 # coupling estimation
1297 returned_ = sinkhorn(
1298 a=self.mu_s,
1299 b=self.mu_t,
1300 M=self.cost_,
1301 reg=self.reg_e,
1302 method=self.method,
1303 numItermax=self.max_iter,
1304 stopThr=self.tol,
1305 verbose=self.verbose,
1306 log=self.log,
1307 )
1308
1309 # deal with the value of log
1310 if self.log:
1311 self.coupling_, self.log_ = returned_
1312 else:
1313 self.coupling_ = returned_
1314 self.log_ = dict()
1315
1316 return self
1317
1318 def transform(self, Xs=None, ys=None, Xt=None, yt=None, batch_size=128):

Calls 2

sinkhornFunction · 0.90
fitMethod · 0.45