Subspace Aligned Classifier¶
-
class
libtlda.suba.
SemiSubspaceAlignedClassifier
(loss_function='logistic', l2_regularization=None, subspace_dim=1)¶ Class of classifiers based on semi-supervised Subspace Alignment.
Methods contain the alignment itself, classifiers and general utilities.
Examples
>>>> X = np.random.randn(10, 2)>>>> y = np.vstack((-np.ones((5,)), np.ones((5,))))>>>> Z = np.random.randn(10, 2)>>>> clf = SubspaceAlignedClassifier()>>>> clf.fit(X, y, Z)>>>> preds = clf.predict(Z)Methods
align_classes
(X, Y, Z, u, CX, CZ, V)Project each class separately. find_medioid
(X, Y)Find point with minimal distance to all other points. fit
(X, Y, Z[, u])Fit/train a classifier on data mapped onto transfer components. get_params
()Get classifier parameters. is_pos_def
(A)Check for positive definiteness. predict
(Z[, zscore])Make predictions on new dataset. predict_proba
(Z[, zscore, signed_classes])Make predictions on new dataset. reg_cov
(X)Regularize covariance matrix until non-singular. score
(Z, U[, zscore])Compute classification error on test set. semi_subspace_alignment
(X, Y, Z, u[, …])Compute subspace and alignment matrix, for each class. -
align_classes
(X, Y, Z, u, CX, CZ, V)¶ Project each class separately.
Parameters: - X : array
source data set (N samples x D features)
- Y : array
source labels (N samples x 1)
- Z : array
target data set (M samples x D features)
- u : array
target labels (m samples x 2)
- CX : array
source principal components (K classes x D features x d subspaces)
- CZ : array
target principal components (K classes x D features x d subspaces)
- V : array
transformation matrix (K classes x d subspaces x d subspaces)
Returns: - X : array
transformed X (N samples x d features)
- Z : array
transformed Z (M samples x d features)
-
find_medioid
(X, Y)¶ Find point with minimal distance to all other points.
Parameters: - X : array
data set, with N samples x D features.
- Y : array
labels to select for which samples to compute distances.
Returns: - x : array
medioid
- ix : int
index of medioid
-
fit
(X, Y, Z, u=None)¶ Fit/train a classifier on data mapped onto transfer components.
Parameters: - X : array
source data (N samples x D features).
- Y : array
source labels (N samples x 1).
- Z : array
target data (M samples x D features).
- u : array
target labels, first column corresponds to index of Z and second column corresponds to actual label (number of labels x 2).
Returns: - None
-
get_params
()¶ Get classifier parameters.
-
is_pos_def
(A)¶ Check for positive definiteness.
- A : array
- square symmetric matrix.
Returns: - bool
whether matrix is positive-definite. Warning! Returns false for arrays containing inf or NaN.
-
predict
(Z, zscore=False)¶ Make predictions on new dataset.
Parameters: - Z : array
new data set (M samples x D features)
- zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns: - preds : array
label predictions (M samples x 1)
-
predict_proba
(Z, zscore=False, signed_classes=False)¶ Make predictions on new dataset.
Parameters: - Z : array
new data set (M samples x D features)
- zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns: - preds : array
label predictions (M samples x 1)
-
reg_cov
(X)¶ Regularize covariance matrix until non-singular.
Parameters: - C : array
square symmetric covariance matrix.
Returns: - C : array
regularized covariance matrix.
-
score
(Z, U, zscore=False)¶ Compute classification error on test set.
Parameters: - Z : array
new data set (M samples x D features)
- zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns: - preds : array
label predictions (M samples x 1)
-
semi_subspace_alignment
(X, Y, Z, u, subspace_dim=1)¶ Compute subspace and alignment matrix, for each class.
Parameters: - X : array
source data set (N samples x D features)
- Y : array
source labels (N samples x 1)
- Z : array
target data set (M samples x D features)
- u : array
target labels, first column is index in Z, second column is label (m samples x 2)
- subspace_dim : int
Dimensionality of subspace to retain (def: 1)
Returns: - V : array
transformation matrix (K, D features x D features)
- CX : array
source principal component coefficients
- CZ : array
target principal component coefficients
-
-
class
libtlda.suba.
SubspaceAlignedClassifier
(loss_function='logistic', l2_regularization=None, subspace_dim=1)¶ Class of classifiers based on Subspace Alignment.
Methods contain the alignment itself, classifiers and general utilities.
Examples
>>>> X = np.random.randn(10, 2)>>>> y = np.vstack((-np.ones((5,)), np.ones((5,))))>>>> Z = np.random.randn(10, 2)>>>> clf = SubspaceAlignedClassifier()>>>> clf.fit(X, y, Z)>>>> preds = clf.predict(Z)Methods
align_data
(X, Z, CX, CZ, V)Align data to components and transform source. fit
(X, Y, Z)Fit/train a classifier on data mapped onto transfer components. get_params
()Get classifier parameters. is_pos_def
(A)Check for positive definiteness. predict
(Z[, zscore])Make predictions on new dataset. predict_proba
(Z[, zscore, signed_classes])Make predictions on new dataset. reg_cov
(X)Regularize covariance matrix until non-singular. score
(Z, U[, zscore])Compute classification error on test set. subspace_alignment
(X, Z[, subspace_dim])Compute subspace and alignment matrix. zca_whiten
(X)Perform ZCA whitening (aka Mahalanobis whitening). -
align_data
(X, Z, CX, CZ, V)¶ Align data to components and transform source.
Parameters: - X : array
source data set (N samples x D features)
- Z : array
target data set (M samples x D features)
- CX : array
source principal components (D features x d subspaces)
- CZ : array
target principal component (D features x d subspaces)
- V : array
transformation matrix (d subspaces x d subspaces)
Returns: - X : array
transformed source data (N samples x d subspaces)
- Z : array
projected target data (M samples x d subspaces)
-
fit
(X, Y, Z)¶ Fit/train a classifier on data mapped onto transfer components.
Parameters: - X : array
source data (N samples x D features).
- Y : array
source labels (N samples x 1).
- Z : array
target data (M samples x D features).
Returns: - None
-
get_params
()¶ Get classifier parameters.
-
is_pos_def
(A)¶ Check for positive definiteness.
-
predict
(Z, zscore=False)¶ Make predictions on new dataset.
Parameters: - Z : array
new data set (M samples x D features)
- zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns: - preds : array
label predictions (M samples x 1)
-
predict_proba
(Z, zscore=False, signed_classes=False)¶ Make predictions on new dataset.
Parameters: - Z : array
new data set (M samples x D features)
- zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns: - preds : array
label predictions (M samples x 1)
-
reg_cov
(X)¶ Regularize covariance matrix until non-singular.
Parameters: - C : array
square symmetric covariance matrix.
Returns: - C : array
regularized covariance matrix.
-
score
(Z, U, zscore=False)¶ Compute classification error on test set.
Parameters: - Z : array
new data set (M samples x D features)
- zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns: - preds : array
label predictions (M samples x 1)
-
subspace_alignment
(X, Z, subspace_dim=1)¶ Compute subspace and alignment matrix.
Parameters: - X : array
source data set (N samples x D features)
- Z : array
target data set (M samples x D features)
- subspace_dim : int
Dimensionality of subspace to retain (def: 1)
Returns: - V : array
transformation matrix (D features x D features)
- CX : array
source principal component coefficients
- CZ : array
target principal component coefficients
-
zca_whiten
(X)¶ Perform ZCA whitening (aka Mahalanobis whitening).
Parameters: - X : array (M samples x D features)
data matrix.
Returns: - X : array (M samples x D features)
whitened data.
-