1

I'm trying to calculate in percentage how symmetric a concrete Matrix is.

The "traditional" way of calculating symmetry would be that I have as input an arbitrary square matrix M of size N×N and that the algorithm's output must be true (=symmetric) if M[i,j] = M[j,i] for all j≠i, false otherwise.

How would be a adequate handling of calculating the percentage? So not just saying symmetric or asymmetric? Maybe counting the times j≠i and divide it by the overall amount of (i,j) ?

So f.e. if I have the following Matrixes:

    1 1 1        1 1 1 
A = 2 2 2    B = 2 2 2
    1 1 2        3 4 5

then I need to know that A is "more symmetric" than B, even both are not symmetric.

user3386109
  • 34,287
  • 7
  • 49
  • 68
lydiaP
  • 123
  • 1
  • 13
  • 1
    If you are simply doing this for comparison between matrices, does it matter your methodology as long as each matrix is treated the same? If they are the same size, you could simply count the symmetric values. Over variable sizes, count the symmetric vs the total. (symmetric/total as a percentage) – Easton Bornemeier Aug 07 '18 at 18:18

2 Answers2

3

You should first define your symmetry distance metric per cell. This should be zero if the symmetric cells is the same or some other number if they aren't.

For example:

s(i,j):= (m(i,j)==m(j,i) ? 0:1) // returns 0/1 if the symmetric cell is/isn't the same

or

s(i,j):= |m(i,j)-m(j,i)| // returns the absolute difference between the two cells

Then just sum the distances for all the cells:

int SymmetricDistance(matrix){
  for (int i=0; i<matrix.Width; i++)
    for (int j=i; j<matrix.Width; j++) // check if th matrix is square first
      dist = dist + s(i,j);
  return dist;
}

now you can say matrix A is "more symmetric" than matrix B iff

SymmetricDistance(A) < SymmetricDistance(B)
Sten Petrov
  • 10,943
  • 1
  • 41
  • 61
1

I agree with @Sten Petrov's answer in general. However, if you are looking for a percentage of symmetry specifically:

First, find the total number of pairs of elements which could be symmetric in an NxN matrix.

You could find this by splitting the matrix along the diagonal and counting the number of elements. Since adding 1 to N increases the total number of pairs by N, a general rule for finding the total pairs is to sum the numbers from 1 to N. However, rather than looping just use the sum formula:

Total Possible = N * (N + 1) / 2

The matrix is perfectly symmetrical iff all the pairs are symmetrical. Therefore, percentage of symmetry can be defined as the fraction of symmetric pairs to total possible pairs.

Symmetry = Symmetric Pairs / Total Pairs

Pseudo-code:

int matchingPairs= 0;
int N = matrix.Width;
int possiblePairs = N * (N + 1 ) / 2;

for(int i = 0; i < N; ++i){
    for(int j = 0; j <= i; ++j){
        matchingPairs += (matrix[i][j] == matrix[j][i]) ? 1 : 0;
    }
}

float percentSymmetric = matchingPairs / possiblePairs ;