# numpy - Problem regarding using Gillespie algorithm with python

4.6k views

### numpy - Problem regarding using Gillespie algorithm with python

I'm working on a problem considering two events (`W`, `M`) and try to calculate the time decay from `W` to `M` using Gillespie. This is pictorial representation of the problem. I solved this using these code:

``````RMW = 1
RWM = 0.35
t = []

for i in range (0,10000):
if (i%2) == 0: #W present
tM = 0
dt = expon.rvs(RWM, size=1)
tM += dt
else:
tW = 0
dt = expon.rvs(RMW, size=1)
tW += dt
t.append(dt)
``````

Now I'm moving to a more complicated problem where there are three events (`W`, `M1` and `M2`). The rates are also different like `RWM1=0.35` and `RWM2=0.1`. This is the pictorial representation. Now I'm not able to understand from where I should start. It will be very helpful if someone can give me some suggestion based on the previous code to approach this kind of problem. by (71.8m points)

If the value of `dt` is supposed to add up as you've said, does this probably solve your problem?

``````RMW = 1
RWM = 0.35
t = []

for i in range (0,10000):
if (i%2) == 0: #W present
tM = 0
dt = expon.rvs(WM1, size=1)
dt += expon.rvs(WM1_M2M1, size=1)
tM += dt
else:
tW = 0
dt = expon.rvs(M2M, size=1)
dt += expon.rvs(M2M_M2M1, size=1)
tW += dt
t.append(dt)
``````