Transformers
- class kalelinear.transformer.MPCA(var_ratio=0.97, max_iter=1, vectorize=False, n_components=None)[source]
Bases:
BaseEstimator,TransformerMixinMultilinear Principal Component Analysis (MPCA) estimator.
- Parameters:
var_ratio (float, default=0.97) – Target cumulative explained variance ratio per mode.
max_iter (int, default=1) – Maximum number of alternating optimization iterations.
vectorize (bool, default=False) – If
True, output projected tensors as vectors.n_components (int, optional) – Number of output features when
vectorize=True.
- proj_mats
Transposed projection matrices with shapes
(P_i, I_i).- Type:
list of ndarray
- idx_order
Feature ranking indices by descending projected variance.
- Type:
ndarray
- mean_
Per-feature empirical mean of the training data.
- Type:
ndarray
- shape_in
Input per-sample tensor shape.
- Type:
tuple
- shape_out
Output per-sample tensor shape after projection.
- Type:
tuple
References
Haiping Lu, K.N. Plataniotis, and A.N. Venetsanopoulos, “MPCA: Multilinear Principal Component Analysis of Tensor Objects”, IEEE Transactions on Neural Networks, Vol. 19, No. 1, Page: 18-39, January 2008. For initial Matlab implementation, please go to https://uk.mathworks.com/matlabcentral/fileexchange/26168.
Examples
>>> import numpy as np >>> from kalelinear.transformer import MPCA >>> x = np.random.random((40, 20, 25, 20)) >>> x.shape (40, 20, 25, 20) >>> mpca = MPCA() >>> x_projected = mpca.fit_transform(x) >>> x_projected.shape (40, 18, 23, 18) >>> x_projected = mpca.transform(x) >>> x_projected.shape (40, 7452) >>> x_projected = mpca.transform(x) >>> x_projected.shape (40, 50) >>> x_rec = mpca.inverse_transform(x_projected) >>> x_rec.shape (40, 20, 25, 20)
- fit(X, y=None)[source]
Fit MPCA to tensor data.
- Parameters:
X (ndarray of shape (n_samples, I_1, ..., I_N)) – Input tensor samples.
y (None, default=None) – Ignored. Present for scikit-learn API compatibility.
- Returns:
self – Fitted estimator.
- Return type:
- transform(X)[source]
Project data to the MPCA subspace.
- Parameters:
X (ndarray of shape (n_samples, I_1, ..., I_N) or (I_1, ..., I_N)) – Input tensor data.
- Returns:
x_projected – Projected data. Shape is
(n_samples, P_1, ..., P_N)whenvectorize=False. Otherwise returns vectorized features with optional truncation ton_components.- Return type:
ndarray
- class kalelinear.transformer.TCA(n_components=None, kernel='linear', lambda_=1.0, mu=1.0, gamma_=0.5, k=3, covariate_encoder=None, eigen_solver='auto', tol=0, max_iter=None, iterated_power='auto', remove_zero_eig=False, scale_components=False, random_state=None, copy=True, n_jobs=None, **kwargs)[source]
Bases:
BaseMMDDomainTransformerTransfer Component Analysis.
covariatesrepresent binary domain labels of lengthn_samples. They must contain both source and target domains duringfit().target_covariateselects which label is treated as the target domain.covariate_encoderis unsupported because TCA expects domain labels rather than general categorical side information.
- class kalelinear.transformer.JDA(n_components=None, kernel='linear', lambda_=1.0, covariate_encoder=None, eigen_solver='auto', tol=0, max_iter=None, iterated_power='auto', remove_zero_eig=False, scale_components=False, random_state=None, copy=True, n_jobs=None, **kwargs)[source]
Bases:
BaseMMDDomainTransformerJoint Distribution Adaptation.
covariatesrepresent binary domain labels of lengthn_samples. They must contain both source and target domains duringfit().target_covariateselects which label is treated as the target domain.covariate_encoderis unsupported because JDA expects domain labels rather than general categorical side information.
- class kalelinear.transformer.BDA(n_components=None, kernel='linear', lambda_=1.0, mu=0.5, covariate_encoder=None, eigen_solver='auto', tol=0, max_iter=None, iterated_power='auto', remove_zero_eig=False, scale_components=False, random_state=None, copy=True, n_jobs=None, **kwargs)[source]
Bases:
JDABalanced Distribution Adaptation.
covariatesrepresent binary domain labels of lengthn_samples. They must contain both source and target domains duringfit().target_covariateselects which label is treated as the target domain.covariate_encoderis unsupported because BDA expects domain labels rather than general categorical side information.
- class kalelinear.transformer.MIDA(n_components=None, mu=1.0, eta=1.0, ignore_y=False, augment=None, kernel='linear', gamma=None, degree=3, coef0=1, kernel_params=None, covariate_encoder=None, alpha=1, fit_inverse_transform=False, eigen_solver='auto', tol=0, max_iter=None, iterated_power='auto', remove_zero_eig=False, scale_components=False, random_state=None, copy=True, n_jobs=None)[source]
Bases:
BaseKernelDomainTransformerMaximum Independence Domain Adaptation (MIDA).
MIDA learns a covariate-invariant feature space by maximizing the Hilbert-Schmidt independence criterion (HSIC) with respect to the provided covariates.
covariatesare required duringfit(). Withcovariate_encoder=None, they must already be numeric and shaped as(n_samples,)or(n_samples, n_covariates). Usecovariate_encoder="onehot"to fit a one-hot encoder on raw categorical covariates before adaptation. Duringtransform(), covariates are only required whenaugmentis"pre"or"post".