- Go to the terminal (mac) or command line (windows), copy and paste:
pip3 install KTensors
- Go to the terminal (mac) or command line (windows), copy and paste:
pip3 install git+https://github.com/Hanchao-Zhang/KTensors.git
- Open a python console, copy and paste:
import KTensors as kt
KTensors(Psis, K, max_iter=1000).clustering()
input:
- Psis: a 3D array of size (n, p, p) where n is the number of matrices and p is the dimension of the positive semi-definite matrices.
- K: number of clusters
- max_iter: maximum number of iterations, default is 1000, usually finish within 10 iterations
return:
- group: a vector of length n, each element is an index of group membership
- CPCs: K orthonormal basis matrices of size p by p for each cluster
-
$\mathbf F$ :$\mathbf F = \mathbf B^\top \mathbf\Psi \mathbf B$ -
$\text{diag}(\mathbf F)$ :$\text{diag}(\mathbf F) = (\mathbf B^\top \mathbf\Psi \mathbf B) \circ \mathbf I$ the diagonal of matrix$\mathbf F$ - centers: Mean of each cluster
- loss: loss function for each iteration
KMetrics(Psis, K, metrics).clustering()
input:
- Psis: a 3D array of size (n, p, p) where n is the number of matrices and p is the dimension of the positive semi-definite matrices.
- K: number of clusters
- metrics: a string of metrics, including 'euclidean', 'affine_invariant', 'log_euclidean', 'log_det', and 'symmetric_stein'.
output:
- a vector of length n, each element is an index of group membership
- loss function for each iteration
where
For more technical details, please refer to the paper: K-Tensors: Clustering Positive Definite Matrices