I try to check the equality or the inequality between 2 Fisher matrices.
The goal is too see if the projection (with Jacobian) and marginalisation (inversion of matrix and remove a row/column and reinversion) commute.
Each of these 2 matrices is computed slightly differently. These 2 matrices are Fisher matrices.
Actually, this is the computation of changing parameters between initial parameters for each row/colum and final parameters for the final matrix. That's why in both computations, I am using the Jacobian J
formulating the derivatives between initial and final parameters :
The formula is : F_final = J^T F_initial J
The first matrix has size 5x5 and the second one has 4x4 size. They are identical except the 4th row/column.
Finally, I perform a projection with a Jacobian 4x4 with formula : F_final = J^T F_initial J
: so I get at the end a 4x4 matrix
I perform this projection with the Jacobian 5x5. Then I get the second projected matrix 5x5. Finally, I remove the 4th row/column on this 5x5 matrix to get a 4x4 matrix new projected matrix.
I wonder under which conditions I could have equality between the 2 matrices 4x4. I don't know if my method is correct.
To show you a practical example, I put below a small Matlab script that tries to follow all the reasoning explained above :
clear;
clc;
% Big_31 Fisher :
FISH_Big_1_SYM = sym('sp_', [4,4], 'real');
% Force symmetry for Big_31
FISH_Big_1_SYM = tril(FISH_Big_1_SYM.') + triu(FISH_Big_1_SYM,1);
% Big_32 Fisher :
FISH_Big_2_SYM = sym('sp_', [5,5], 'real');
% Force symmetry for Big_32
FISH_Big_2_SYM = tril(FISH_Big_2_SYM.') + triu(FISH_Big_2_SYM,1);
% Jacobian 1
J_1_SYM = sym('j_', [4,4], 'real');
% Jacobian 2
J_2_SYM = sym('j_', [5,5], 'real');
% Remove 4th row/column
J_2_SYM(4,:) = [];
J_2_SYM(:,4) = [];
% Projection
FISH_proj_1 = J_1_SYM'*FISH_Big_1_SYM*J_1_SYM;
size(FISH_proj_1)
% Invert Fisher_2
COV_Big_2_SYM = inv(FISH_Big_2_SYM);
% Remove 4th row/column
COV_Big_2_SYM(4,:) = [];
COV_Big_2_SYM(:,4) = [];
% Re-inverse
FISH_Big_2_SYM_new = inv(COV_Big_2_SYM);
% Projection 2x2
FISH_proj_2 = J_2_SYM'*FISH_Big_2_SYM_new*J_2_SYM;
size(FISH_proj_2)
% Test equality between 2 matrices
isequal(FISH_proj_1,FISH_proj_2)
The problem with this script is even I have small matrices (4x4 or 5x5), the code takes a little bit long runtime but the result is that matrices are different.
I gave some feedback from persons. An important point is at this portion of Matlab code :
When I do :
% Remove 4th row/column
J_2_SYM(4,:) = [];
J_2_SYM(:,4) = [];
I don't remove elements line j_5_1
, j_5_2
, j_5_3
of Jacobian J
, these terms won't disappear when I do the projection. On the other side, these terms will remain in the other method, in the sense that I take into account of them.
So is it a lost battle ?
If yes, which modifications or assumptions could lead to have an equality ? i.e to have both operations do commute.
To do np.dot
last dimension of first matrix must be the same as first dimension of second one. They are not, so you are getting ValueError, that shapes are not aligned.
Everything seems to be fine as you printed, but then you forgot about lines:
j_temp = np.copy(J_2_SYM)
# Add row/col into J_2_SYM
j_temp = np.insert(j_temp, 2, J_NEU_row_SYM[0,:], axis=0)
j_temp = np.insert(j_temp, 2, J_NEU_col_SYM[:,0], axis=1)
# Copy built J_2_SYM
J_2_SYM = np.copy(j_temp)
So that's where you change size of J_2_SYM, and after all it is (33, 16), so you cannot do dot product with (32, 32) array.