In my opinion, the current KeyPy code calculates the explained standard deviation, not the explained variance.
In agreement with formulas 10-12 of Pascual-Marqui's 1995 IEEE paper, the projection of the momentous map on the model map (which in KeyPy is calculated as the dot product in line 293) should be squared, and divided by the variance (not std). The same changes should be made in modelmaps.py.
Here is a simple test program with 3 channels, one model map, and one time-frame.
KeyPy gives 0.5 for the explained variance, which probably should be 0.25.
import numpy as np
from math import sqrt
nch = 3
a = sqrt (2);
model = ([-a,0,a])
b=np.sum(np.abs(model)2,axis=-1)(1./2)
for col in range(nch):
model[col]=model[col]/b
In my opinion, the current KeyPy code calculates the explained standard deviation, not the explained variance. In agreement with formulas 10-12 of Pascual-Marqui's 1995 IEEE paper, the projection of the momentous map on the model map (which in KeyPy is calculated as the dot product in line 293) should be squared, and divided by the variance (not std). The same changes should be made in modelmaps.py.
Here is a simple test program with 3 channels, one model map, and one time-frame. KeyPy gives 0.5 for the explained variance, which probably should be 0.25.
import numpy as np from math import sqrt
nch = 3 a = sqrt (2); model = ([-a,0,a]) b=np.sum(np.abs(model)2,axis=-1)(1./2) for col in range(nch): model[col]=model[col]/b
org_data = ([0,-a,a]) covm_all=np.dot(org_data,model) loading_all=covm_all b_loading_all=(1.0loading_all)/sqrt(nch) eeg = org_data exp_var_tot=(b_loading_allb_loading_all)/np.var(eeg)
print (exp_var_tot)