r"""Propagate source labels :math:`\mathbf{y_s}` to obtain target labels as in :ref:`[27] ` Parameters ---------- ys : list of K array-like objects, shape K x (nk_source_samples,) A list of the class labels
(self, ys=None)
| 2505 | return transp_Xs |
| 2506 | |
| 2507 | def transform_labels(self, ys=None): |
| 2508 | r"""Propagate source labels :math:`\mathbf{y_s}` to obtain target labels as in |
| 2509 | :ref:`[27] <references-jcpottransport-transform-labels>` |
| 2510 | |
| 2511 | Parameters |
| 2512 | ---------- |
| 2513 | ys : list of K array-like objects, shape K x (nk_source_samples,) |
| 2514 | A list of the class labels |
| 2515 | |
| 2516 | Returns |
| 2517 | ------- |
| 2518 | yt : array-like, shape (n_target_samples, nb_classes) |
| 2519 | Estimated soft target labels. |
| 2520 | |
| 2521 | |
| 2522 | .. _references-jcpottransport-transform-labels: |
| 2523 | References |
| 2524 | ---------- |
| 2525 | .. [27] Ievgen Redko, Nicolas Courty, Rémi Flamary, Devis Tuia |
| 2526 | "Optimal transport for multi-source domain adaptation under target shift", |
| 2527 | International Conference on Artificial Intelligence and Statistics (AISTATS), 2019. |
| 2528 | """ |
| 2529 | nx = self.nx |
| 2530 | |
| 2531 | # check the necessary inputs parameters are here |
| 2532 | if check_params(ys=ys): |
| 2533 | yt = nx.zeros( |
| 2534 | (len(nx.unique(nx.concatenate(ys))), self.xt_.shape[0]), type_as=ys[0] |
| 2535 | ) |
| 2536 | for i in range(len(ys)): |
| 2537 | ysTemp = label_normalization(ys[i]) |
| 2538 | classes = nx.unique(ysTemp) |
| 2539 | n = len(classes) |
| 2540 | ns = len(ysTemp) |
| 2541 | |
| 2542 | # perform label propagation |
| 2543 | transp = self.coupling_[i] / nx.sum(self.coupling_[i], 1)[:, None] |
| 2544 | |
| 2545 | # set nans to 0 |
| 2546 | transp = nx.nan_to_num(transp, nan=0, posinf=0, neginf=0) |
| 2547 | |
| 2548 | if self.log: |
| 2549 | D1 = self.log_["D1"][i] |
| 2550 | else: |
| 2551 | D1 = nx.zeros((n, ns), type_as=transp) |
| 2552 | |
| 2553 | for c in classes: |
| 2554 | D1[int(c), ysTemp == c] = 1 |
| 2555 | |
| 2556 | # compute propagated labels |
| 2557 | yt = yt + nx.dot(D1, transp) / len(ys) |
| 2558 | |
| 2559 | return yt.T |
| 2560 | |
| 2561 | def inverse_transform_labels(self, yt=None): |
| 2562 | r"""Propagate target labels :math:`\mathbf{y_t}` to obtain estimated source labels |