cvt.utils package¶
Submodules¶
cvt.utils.base module¶
Mathematical utilities
-
cvt.utils.base.canonical_angle(X, Y)¶ Calculate cannonical angles beween subspaces
- Parameters
X (basis matrix, array-like, shape: (n_subdim_X, n_dim)) –
Y (basis matrix, array-like, shape: (n_subdim_Y, n_dim)) –
- Returns
c
- Return type
float, similarity of X, Y
-
cvt.utils.base.canonical_angle_matrix(X, Y)¶ Calculate canonical angles between subspaces example similarity = MathUtils.calc_basis_vector(X, Y)
- Parameters
X (set of basis matrix, array-like, shape: (n_set_X, n_subdim, n_dim)) – n_subdim can be variable on each subspaces
Y (set of basis matrix, array-like, shape: (n_set_Y, n_subdim, n_dim)) – n_set can be variable from n_set of X n_subdim can be variable on each subspaces
Returns – C: similarity matrix, array-like, shape: (n_set_X, n_set_Y)
-
cvt.utils.base.canonical_angle_matrix_f(X, Y)¶ Calculate canonical angles between subspaces example similarity = MathUtils.calc_basis_vector(X, Y)
- Parameters
X (set of basis matrix, array-like, shape: (n_set_X, n_subdim, n_dim)) – n_subdim can be variable on each subspaces
Y (set of basis matrix, array-like, shape: (n_set_Y, n_subdim, n_dim)) – n_set can be variable from n_set of X n_subdim can be variable on each subspaces
Returns – C: similarity matrix, array-like, shape: (n_set_X, n_set_Y)
-
cvt.utils.base.cross_similarities(refs, inputs)¶ Calc similarities between each reference spaces and each input subspaces
refs: list of array-like (n_dims, n_subdims_i) inputs: list of array-like (n_dims, n_subdims_j)
similarities: array-like, shape (n_refs, n_inputs)
-
cvt.utils.base.dual_vectors(K, n_subdims=None, higher=True, eps=1e-06)¶ Calc dual representation of vectors in kernel space
- Karray-like, shape: (n_samples, n_samples)
Grammian Matrix of X: K(X, X)
- n_subdims: int, default=None
Number of vectors of dual vectors to return
- higher: boolean, default=None
- If True, this function returns eigenbasis corresponding to
higher n_subdims eigenvalues in descending order.
- If False, this function returns eigenbasis corresponding to
lower n_subdims eigenvalues in descending order.
- eps: float, default=1e-20
lower limit of eigenvalues
- Aarray-like, shape: (n_samples, n_samples)
Dual replesentation vectors. it satisfies lambda[i] * A[i] @ A[i] == 1, where lambda[i] is i-th biggest eigenvalue
- e: array-like, shape: (n_samples, )
Eigen values descending sorted
-
cvt.utils.base.max_square_singular_values(X)¶ calculate mean square of singular values of X
X : array-like, shape: (n, m)
c: mean square of singular values
-
cvt.utils.base.mean_square_singular_values(X)¶ calculate mean square of singular values of X
X : array-like, shape: (n, m)
c: mean square of singular values
-
cvt.utils.base.subspace_bases(X, n_subdims=None, higher=True, return_eigvals=False)¶ Return subspace basis using PCA
- Parameters
X (array-like, shape (n_dimensions, n_vectors)) – data matrix
n_subdims (integer) – number of subspace dimension
higher (bool) – if True, this function returns eigenvectors collesponding top-n_subdims eigenvalues. default is True.
return_eigvals (bool) – if True, this function also returns eigenvalues.
- Returns
V (array-like, shape (n_dimensions, n_subdims)) – bases matrix
w (array-like shape (n_subdims)) – eigenvalues
cvt.utils.evaluation module¶
-
cvt.utils.evaluation.calc_eer(X, labels=None, data_type='S')¶ calculate Error Rate (ER)
- Parameters
X (ndarray, shape (n_samples, n_elements)) – data matrix
labels(optional) (ndarray, shape (n_elements)) – labels that represents what class each element(row) belongs to if it’s not given, each rows are treated as independent class
data_type(optional) (string) – ‘S’: Similarity (default) ‘D’: Distance
- Returns
eer (float) – equal error rate
thresh (float) – threashold
-
cvt.utils.evaluation.calc_er(X, y, labels=None, data_type='S')¶ calculate Error Rate (ER)
- Parameters
X (ndarray, shape (n_samples, n_elements)) – data matrix
y (ndarray, shape (n_samples)) – true label (integer)
labels(optional) (ndarray, shape (n_elements)) – labels that represents what class each element(row) belongs to if it’s not given, each rows are treated as independent class
data_type(optional) (string) – ‘S’: Similarity (default) ‘D’: Distance
- Returns
er – error rate
- Return type
float
cvt.utils.kernel_functions module¶
Kernel functions
-
cvt.utils.kernel_functions.l2_kernel(X, Y)¶
-
cvt.utils.kernel_functions.linear_kernel(X, Y)¶ Linear kernel. this calculates simple inner product. K(x, y) = x @ y
- Parameters
X (array of shape (n_dims, n_samples_X)) –
Y (array of shape (n_dims, n_samples_Y)) –
Returns –
-------- –
K (array-like, shape: (n_samples_X, n_samples_Y)) – Grammian matrix
-
cvt.utils.kernel_functions.rbf_kernel(X, Y, sigma=None)¶ RBF kernel. this is a wrapper of sklearn.metrics.pairwise.rbf_kernel. K(x, y) = exp(- (1/2) * (||x - y||/sigma)^2)
- Parameters
X (array of shape (n_dims, n_samples_X)) –
Y (array of shape (n_dims, n_samples_Y)) –
sigma (float, default None) – If None, defaults to sqrt(n_dims / 2)
Returns –
-------- –
K (array-like, shape: (n_samples_X, n_samples_Y)) – Grammian matrix