Say I have two or more matrices. The number of rows and columns are same across matrices. But the matrices are not necessarily square.
Matrix1
a b c
1 0.911 0.067 0.023
2 0.891 0.089 0.019
3 0.044 0.931 0.025
4 0.919 0.058 0.023
Matrix2
a b c
1 0.024 0.070 0.906
2 0.020 0.090 0.891
3 0.025 0.930 0.045
4 0.024 0.058 0.918
Rows always sum to 1. Columns may shift position from matrix to matrix. So column names do not mean anything much. Example above, column 'a' in mat 1 is column 'c' in mat2. The value will not be identical but similar.
What sort of approach/algorithm can I use to align the columns across many such matrices?
The desired result would be something like below
Matrix1
a b c
1 0.911 0.067 0.023
2 0.891 0.089 0.019
3 0.044 0.931 0.025
4 0.919 0.058 0.023
Matrix2
c b b
1 0.906 0.070 0.024
2 0.891 0.090 0.020
3 0.045 0.930 0.025
4 0.918 0.058 0.024
That the columns are aligned. 'a' in mat1 corresponds to 'c' in mat2 and so on. In this one possible result, mat1 is the reference and mat2 was aligned to it.
I am using R if anyone wants to try something.
mat1 <-
matrix(c(0.911,0.891,0.044,0.919,0.067,0.089,0.931,0.058,0.023,0.019,0.025,0.023),nrow=4)
mat2 <-
matrix(c(0.024,0.020,0.025,0.024,0.070,0.090,0.930,0.058,0.906,0.891,0.045,0.918),nrow=4)
mat2[,order(mat1[1,]- mat2[1,])]
ormat2[,max.col(-outer(mat1[1,], mat2[1,], function(i, j) abs(i-j)))]
– Sotos