[graph-tool] optimize a function based on iterate_sync

BleakHeart cosmin.marin19 at gmail.com
Tue Jul 28 12:03:19 CEST 2020

Hi graphtool community! 
In this period I am stuck in a timing problem.
I need to execute this function:

def *evolutionSIR*(G, ep_beta, count, v0):
    state = SIRState(G, beta=ep_beta, gamma=gamma, v0=v0,
    s = state.get_state()
    temp_state = np.zeros((count + 1, G.num_vertices()), dtype=int)
    temp_state[0, :] = s.a[:]

    for i in range(count):
        s = state.get_state()
        temp_state[i + 1, :] = s.a[:]

    return temp_state

After this, I use a fuction to determine the timestep where each community
is infected. 
My pc runs the *evolutionSIR* function in 1.1 s ± 48 ms, and the total time
to run the both functions is 1.16 s ± 48 ms. For my study I need to run
O(1E6) the two functions, and it takes a long time on my personal computer. 
Reading the documentation, I noticed that *iterate_sync* has the *niter*
parameter and I tried it like this:

v0 = np.random.choice(G.get_vertices(), 1)
state = SIRState(G, beta=ep_beta, gamma=gamma, v0=v0, constant_beta=True)

Doing this, it results to be almost 2.85 times faster (385 ms ± 39.3 ms)
than the *evolutionSIR* I wrote before but the problem is that I can't have
the states in each evolution step. 
Is there a way to get the history of the diffusion using
Or is there a way to optimize the evolutionSIR function? 


Sent from: https://nabble.skewed.de/

More information about the graph-tool mailing list