Correlation Matrix Calculation for Feature Independence in PyTorch
The code above computes the correlation matrix 'c' between two feature maps 'z1' and 'z2'. It then normalizes 'c' by dividing it by the batch size 'z1.size(0)'.
Next, it calculates the sum of squared differences of the elements on the diagonal of 'c' minus 1 ('on_diag'), and the sum of squared differences of the off-diagonal elements of 'c' ('off_diag').
Finally, it returns the sum of 'on_diag' and λ times 'off_diag', where λ is a hyperparameter that controls the trade-off between encouraging independence between the features and preserving useful information.
原文地址: https://www.cveoy.top/t/topic/lNoT 著作权归作者所有。请勿转载和采集!