# 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.

Parameters
matrix1tensorly.Tensor
matrix2tensorly.Tensor
absolute_valuebool

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

Returns
congruencefloat
permutationlist