wiheto / teneto

Temporal Network Tools
GNU General Public License v3.0
85 stars 26 forks source link

temporal_betweenness_centrality out of bounds error #60

Closed maximelucas closed 4 years ago

maximelucas commented 4 years ago

When I run

import teneto as tnt
N = 4
n_t = 7

TN = tnt.TemporalNetwork()
TN.generatenetwork("rand_binomial", size=(N, n_t), prob=0.3)

tnt.networkmeasures.temporal_betweenness_centrality(TN, calc='pertime')

sometimes the code runs fine, but sometimes I get the following error (also when calc='overtime')

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-24-b3a8528aeb32> in <module>
      6 
      7 
----> 8 tnt.networkmeasures.temporal_betweenness_centrality(TN, calc='pertime')

~/.local/lib/python3.6/site-packages/teneto/networkmeasures/temporal_betweenness_centrality.py in temporal_betweenness_centrality(tnet, paths, calc)
     84     # if shortest paths are not calculated, calculate them
     85     if tnet is not None:
---> 86         paths = shortest_temporal_path(tnet)
     87 
     88     bet = np.zeros([paths[['from', 'to']].max().max() +

~/.local/lib/python3.6/site-packages/teneto/networkmeasures/shortest_temporal_path.py in shortest_temporal_path(tnet, steps_per_t, i, j, it, minimise)
    199                         # Only select i if directed, ij if undirected.
    200                         if tnet.nettype[1] == 'u':
--> 201                             network = tnet.get_network_when(ij=list(ij), t=t)
    202                         elif tnet.nettype[1] == 'd':
    203                             network = tnet.get_network_when(i=list(ij), t=t)

~/.local/lib/python3.6/site-packages/teneto/classes/network.py in get_network_when(self, **kwargs)
    477         """
    478         """
--> 479         return teneto.utils.get_network_when(self, **kwargs)
    480 
    481     def df_to_array(self):

~/.local/lib/python3.6/site-packages/teneto/utils/utils.py in get_network_when(tnet, i, j, t, ij, logic, copy, asarray, netshape, nettype)
    987             ind = np.hstack([ind, ind2])
    988 
--> 989         edges = network[ind[0], ind[1], ind[2]]
    990         ind = ind[:, edges != 0]
    991         edges = edges[edges != 0]

IndexError: index 7 is out of bounds for axis 2 with size 7
wiheto commented 4 years ago

Interesting. Will have a little look into this over the next few days. Looks like an error occurring when paths don’t exist. Will try and look into this ASAP.

9 mars 2020 kl. 11:18 skrev Maxime Lucas notifications@github.com:

 When I run

import teneto as tnt N = 4 n_t = 7

TN = tnt.TemporalNetwork() TN.generatenetwork("rand_binomial", size=(N, n_t), prob=0.3)

tnt.networkmeasures.temporal_betweenness_centrality(TN, calc='pertime') sometimes the code runs fine, but sometimes I get the following error (also when calc='overtime')


IndexError Traceback (most recent call last)

in 6 # TN.generatenetwork("rand_binomial", size=(N, n_t), prob=0.3) 7 ----> 8 tnt.networkmeasures.temporal_betweenness_centrality(TN, calc='pertime') 9 10 # tnt.networkmeasures.temporal_betweenness_centrality(TN, calc='overtime') ~/.local/lib/python3.6/site-packages/teneto/networkmeasures/temporal_betweenness_centrality.py in temporal_betweenness_centrality(tnet, paths, calc) 84 # if shortest paths are not calculated, calculate them 85 if tnet is not None: ---> 86 paths = shortest_temporal_path(tnet) 87 88 bet = np.zeros([paths[['from', 'to']].max().max() + ~/.local/lib/python3.6/site-packages/teneto/networkmeasures/shortest_temporal_path.py in shortest_temporal_path(tnet, steps_per_t, i, j, it, minimise) 199 # Only select i if directed, ij if undirected. 200 if tnet.nettype[1] == 'u': --> 201 network = tnet.get_network_when(ij=list(ij), t=t) 202 elif tnet.nettype[1] == 'd': 203 network = tnet.get_network_when(i=list(ij), t=t) ~/.local/lib/python3.6/site-packages/teneto/classes/network.py in get_network_when(self, **kwargs) 477 """ 478 """ --> 479 return teneto.utils.get_network_when(self, **kwargs) 480 481 def df_to_array(self): ~/.local/lib/python3.6/site-packages/teneto/utils/utils.py in get_network_when(tnet, i, j, t, ij, logic, copy, asarray, netshape, nettype) 987 ind = np.hstack([ind, ind2]) 988 --> 989 edges = network[ind[0], ind[1], ind[2]] 990 ind = ind[:, edges != 0] 991 edges = edges[edges != 0] IndexError: index 7 is out of bounds for axis 2 with size 7 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
wiheto commented 4 years ago

Again, sorry I did not get back to you earlier (obviously slightly weird times at the moment).

Anyhow, I looked into this and found the fix (basically a while loop was not ending for T+1).

The fix will be included in 0.5.2 which should be released on the main branch in a week or two once I've added a few more fixes and features. If needed urgently, it can be found on the development branch (https://github.com/wiheto/teneto/tree/develop)

wiheto commented 4 years ago

So my testing shows the issue ends with this. So I'm closing this issue for now. Feel free to reopen if you find any errors.