# tensorly.metrics.factors.congruence_coefficient

congruence_coefficient(matrix1, matrix2, absolute_value=True)[source]

Compute the optimal mean (Tucker) congruence coefficient between the columns of two matrices.

Another name for the congruence coefficient is the cosine similarity.

The congruence coefficient between two vectors, $$\mathbf{v}_1, \mathbf{v}_2$$, is given by

$\frac{\mathbf{v}_1^T \mathbf{v}_1^T}{\|\mathbf{v}_1^T\| \|\mathbf{v}_1^T\|}$

When we compute the congruence between two matrices, we find the optimal permutation of the columns and return the mean congruence and the permutation. The output permutation is the one that permutes the columns of matrix2 onto the closest columns in matrix1.

If a list of matrices is provided for each input, we define the congruence coefficient as the product of the absolute values of pairs of matrices. The lists must therefore have the same size. The output permutation also applies to each matrix of the lists.

Parameters:
matrix1tensorly.Tensor or list of tensorly.Tensor
matrix2tensorly.Tensor of list of tensorly.Tensor to permute.
absolute_valuebool

Whether to take the absolute value of all vector products before finding the optimal permutation.

Returns:
congruencefloat
permutationlist