Different implementations to compute global efficiency using bct.charpath and bct.efficiency_wei unclear
JohannesWiesner opened this issue · 1 comments
I would like to compute the global efficiency for my undirected weighted matrices. Higher values in my matrices correspond to a "weaker connection" (or in my field to a more "effortful transition" from node i to node j). The matrices are not normalized. I saw that there are two functions to achieve this: bct.charpath
(the second returned object is efficiency
) or bct.efficiency_wei
.
I am struggling with understanding those two implementations, the different inputs and the corresponding documentation. So if I would use bct.charpath
, the input would have to be a distance matrix returned by distance_wei
. But in the docs for this function, it says that the input is not an adjacency matrix but instead a directed/undirected connection-length matrix L, which I think you can get by using bct.weight_conversion
with wcm='lenghts
? So am I right that you would have to do these steps to obtain the global efficiency when using bct.charpath
?:
L = bct.weight_conversion(W,wcm='lengths')
D,_ = bct.distance_wei(L)
_,efficiency,_,_,_ = bct.charpath(D)
In contrast, bct.efficiency_wei
apparently can directly work with the first matrix without having to take the detour over distance_wei
but still you have to apply bct.weight_conversion(W,wcm='lengths')
before? But why do these two implementations then give the same results?
# create example adjacency matrix
W = np.array([[np.nan, 2.37315958, 2.57765794, 2.80687395],
[2.49980561, np.nan, 2.54130546, 2.68085856],
[2.47684487, 2.48506384, np.nan, 2.83927864],
[2.77334217, 2.6091044, 2.82154979, np.nan]])
# using bct.charpath
L = bct.weight_conversion(W,wcm='lengths')
D,_ = bct.distance_wei(L)
_,efficiency,_,_,_ = bct.charpath(D)
# using bct.efficiency_wei (it says, the input has to be normalized,
# but even if you don't do this efficiency == efficiency_2)
efficiency_2 = bct.efficiency_wei(W)
Seems like you have understood it correctly. I'm not sure why all of the functions exist as they do, I am not responsible for writing the entire library, various other people have written various utilities for them.
Your efficiency_wei()
call appears to be working as intended.