Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
7.6k views
in Technique[技术] by (71.8m points)

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.

enter image description here

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.

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...