This post was updated on .
Hi graphtool community!
In this period I am stuck in a timing problem. I need to run this function: def evolutionSIR(G, ep_beta, count, v0): state = SIRState(G, beta=ep_beta, gamma=gamma, v0=v0, constant_beta=True) 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): state.iterate_sync() 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) state.iterate_sync(niter=count) 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 iterate_sync(niter=count)? Or is there a way to optimize the evolutionSIR function? Greetings  Sent from: https://nabble.skewed.de/ _______________________________________________ graphtool mailing list graphtool@skewed.de https://lists.skewed.de/mailman/listinfo/graphtool 
Administrator

Am 28.07.20 um 12:03 schrieb BleakHeart:
> 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, > constant_beta=True) > > 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): > state.iterate_sync() > > 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) > state.iterate_sync(niter=count) > > 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 > *iterate_sync*(niter=count)? > Or is there a way to optimize the evolutionSIR function? not possible. But I don't believe you would get much of an improvement anyway, since the reason why it runs faster is mostly because it does not do any extra computation, such as collecting history. The version you have is basically as fast as you can get. The only thing I would suggest is to move the line s = state.get_state() outside of the loop, since that property map is always the same during the state's lifetime. Best, Tiago  Tiago de Paula Peixoto <[hidden email]> _______________________________________________ graphtool mailing list [hidden email] https://lists.skewed.de/mailman/listinfo/graphtool signature.asc (849 bytes) Download Attachment

Tiago de Paula Peixoto <tiago@skewed.de> 
Free forum by Nabble  Edit this page 