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 training input samples. Returns ------- transp_Xs : array-like, shape
(self, Xs)
| 2134 | return self |
| 2135 | |
| 2136 | def transform(self, Xs): |
| 2137 | r"""Transports source samples :math:`\mathbf{X_s}` onto target ones :math:`\mathbf{X_t}` |
| 2138 | |
| 2139 | Parameters |
| 2140 | ---------- |
| 2141 | Xs : array-like, shape (n_source_samples, n_features) |
| 2142 | The training input samples. |
| 2143 | |
| 2144 | Returns |
| 2145 | ------- |
| 2146 | transp_Xs : array-like, shape (n_source_samples, n_features) |
| 2147 | The transport source samples. |
| 2148 | """ |
| 2149 | nx = self.nx |
| 2150 | |
| 2151 | # check the necessary inputs parameters are here |
| 2152 | if check_params(Xs=Xs): |
| 2153 | if nx.array_equal(self.xs_, Xs): |
| 2154 | # perform standard barycentric mapping |
| 2155 | transp = self.coupling_ / nx.sum(self.coupling_, 1)[:, None] |
| 2156 | |
| 2157 | # set nans to 0 |
| 2158 | transp = nx.nan_to_num(transp, nan=0, posinf=0, neginf=0) |
| 2159 | |
| 2160 | # compute transported samples |
| 2161 | transp_Xs = nx.dot(transp, self.xt_) |
| 2162 | else: |
| 2163 | if self.kernel == "gaussian": |
| 2164 | K = kernel(Xs, self.xs_, method=self.kernel, sigma=self.sigma) |
| 2165 | elif self.kernel == "linear": |
| 2166 | K = Xs |
| 2167 | if self.bias: |
| 2168 | K = nx.concatenate( |
| 2169 | [K, nx.ones((Xs.shape[0], 1), type_as=K)], axis=1 |
| 2170 | ) |
| 2171 | transp_Xs = nx.dot(K, self.mapping_) |
| 2172 | |
| 2173 | return transp_Xs |
| 2174 | |
| 2175 | |
| 2176 | class UnbalancedSinkhornTransport(BaseTransport): |