r"""Transports source samples :math:`\mathbf{X_s}` onto target ones :math:`\mathbf{X_t}` Parameters ---------- Xs : array-like, shape (n_source_samples, n_features) The source input samples. ys : array-like, shape (n_source_samples,) The class
(self, Xs=None, ys=None, Xt=None, yt=None, batch_size=128)
| 659 | return self.fit(Xs, ys, Xt, yt).transform(Xs, ys, Xt, yt) |
| 660 | |
| 661 | def transform(self, Xs=None, ys=None, Xt=None, yt=None, batch_size=128): |
| 662 | r"""Transports source samples :math:`\mathbf{X_s}` onto target ones :math:`\mathbf{X_t}` |
| 663 | |
| 664 | Parameters |
| 665 | ---------- |
| 666 | Xs : array-like, shape (n_source_samples, n_features) |
| 667 | The source input samples. |
| 668 | ys : array-like, shape (n_source_samples,) |
| 669 | The class labels for source samples |
| 670 | Xt : array-like, shape (n_target_samples, n_features) |
| 671 | The target input samples. |
| 672 | yt : array-like, shape (n_target_samples,) |
| 673 | The class labels for target. If some target samples are unlabelled, fill the |
| 674 | :math:`\mathbf{y_t}`'s elements with -1. |
| 675 | |
| 676 | Warning: Note that, due to this convention -1 cannot be used as a |
| 677 | class label |
| 678 | batch_size : int, optional (default=128) |
| 679 | The batch size for out of sample inverse transform |
| 680 | |
| 681 | Returns |
| 682 | ------- |
| 683 | transp_Xs : array-like, shape (n_source_samples, n_features) |
| 684 | The transport source samples. |
| 685 | """ |
| 686 | nx = self.nx |
| 687 | |
| 688 | # check the necessary inputs parameters are here |
| 689 | if check_params(Xs=Xs): |
| 690 | if nx.array_equal(self.xs_, Xs): |
| 691 | # perform standard barycentric mapping |
| 692 | transp = self.coupling_ / nx.sum(self.coupling_, axis=1)[:, None] |
| 693 | |
| 694 | # set nans to 0 |
| 695 | transp = nx.nan_to_num(transp, nan=0, posinf=0, neginf=0) |
| 696 | |
| 697 | # compute transported samples |
| 698 | transp_Xs = nx.dot(transp, self.xt_) |
| 699 | else: |
| 700 | # perform out of sample mapping |
| 701 | indices = nx.arange(Xs.shape[0]) |
| 702 | batch_ind = [ |
| 703 | indices[i : i + batch_size] |
| 704 | for i in range(0, len(indices), batch_size) |
| 705 | ] |
| 706 | |
| 707 | transp_Xs = [] |
| 708 | for bi in batch_ind: |
| 709 | # get the nearest neighbor in the source domain |
| 710 | D0 = dist(Xs[bi], self.xs_) |
| 711 | idx = nx.argmin(D0, axis=1) |
| 712 | |
| 713 | # transport the source samples |
| 714 | transp = self.coupling_ / nx.sum(self.coupling_, axis=1)[:, None] |
| 715 | transp = nx.nan_to_num(transp, nan=0, posinf=0, neginf=0) |
| 716 | transp_Xs_ = nx.dot(transp, self.xt_) |
| 717 | |
| 718 | # define the transported points |