pythonsi.domain_adaptation
Domain adaptation methods with selective inference.
Classes
- class pythonsi.domain_adaptation.OptimalTransportDA[source]
Optimal Transport Domain Adaptation with selective inference support.
The optimal transport problem solved is:
\[\min_{T \in \mathcal{P}} \langle C, T \rangle\]where \(\mathcal{P}\) is the set of transport plans with given marginals and \(C\) is the cost matrix between domains.
- interval
Feasible interval for the last inference call
- Type:
list or None
- x_output_data
Stored adapted features from last inference call
- Type:
array-like or None
- y_output_data
Stored adapted labels from last inference call
- Type:
tuple or None
- forward(xs: ndarray[tuple[Any, ...], dtype[floating]], ys: ndarray[tuple[Any, ...], dtype[floating]], xt: ndarray[tuple[Any, ...], dtype[floating]], yt: ndarray[tuple[Any, ...], dtype[floating]])[source]
Solve optimal transport and construct adapted dataset.
- Parameters:
xs (array-like, shape (ns, d)) – Source domain features
ys (array-like, shape (ns, 1)) – Source domain labels
xt (array-like, shape (nt, d)) – Target domain features
yt (array-like, shape (nt, 1)) – Target domain labels
- Returns:
x_tilde (array-like, shape (ns+nt, d)) – Adapted feature matrix
y_tilde (array-like, shape (ns+nt, 1)) – Adapted label vector
B (list of int) – Basic feasible solution indices
c_features (array-like, shape (ns*nt, 1)) – Feature space cost matrix
Omega (array-like, shape (ns+nt, ns+nt)) – Transformation matrix for adaptation
Notes
The adapted dataset is constructed as:
\[ \begin{align}\begin{aligned}\begin{split}\tilde{\mathbf{x}} = \Omega \begin{bmatrix} \mathbf{x}_s \\ \mathbf{x}_t \end{bmatrix}\end{split}\\\begin{split}\tilde{\mathbf{y}} = \Omega \begin{bmatrix} \mathbf{y}_s \\ \mathbf{y}_t \end{bmatrix}\end{split}\end{aligned}\end{align} \]where \(\Omega\) incorporates the optimal transport plan.
- inference(z: float) Tuple[list, ndarray[tuple[Any, ...], dtype[floating]]] [source]
Find feasible interval of the Optimal Transport for the parametrized data at z .
- Parameters:
z (float) – Scalar parameter
- Returns:
final_interval – Feasible interval [lower, upper] for z
- Return type:
list
- run(xs: Data, ys: Data, xt: Data, yt: Data) Data [source]
Configure domain adaptation with input data.
- Parameters:
xs (array-like, shape (ns, d)) – Source domain features
ys (array-like, shape (ns, 1)) – Source domain labels
xt (array-like, shape (nt, d)) – Target domain features
yt (array-like, shape (nt, 1)) – Target domain labels
- Returns:
x_output_node (Data) – Node containing adapted features
y_output_node (Data) – Node containing adapted labels
Examples
>>> ot_da = OptimalTransportDA() >>> x_out, y_out = ot_da.run(xs, ys, xt, yt) >>> adapted_x = x_out()