请考虑一个非马尔可夫过程,该过程描述了从状态A到状态B的转变,该过程由连续时间的响应时间分布控制,并且有额外的恒定流入状态A和状态B的流出。{{ 0}}
例如,我有100个类型为A的单元格,它们转换为类型B,其中事件之间的分布是非指数分布的。为了模拟这一点,我需要单独查看每个单元并检查何时发生状态转换。 我努力将恒定的通量整合到状态A中,同时还考虑了过渡到状态B中的情况,我是否需要分别关注每个单元格,还是应该从指数分布中得出答案何时将另一个单元添加到系统?我的头脑完全被卡住了。
def semi_markov(start, stop, nsteps, ncells, nstates = 3):
# initialize cells
cells = np.zeros((ncells, nsteps, nstates))
time = np.linspace(start, stop, nsteps)
# generate random number for each cell to compare with integral
# of response-time distribution
numbers_rnd = [np.random.rand() for i in range(ncells)]
fate_times = [np.random.exponential(1.) for i in range(ncells)]
# for each time point loop over each cell and check if transition occurs
for i in range(len(time)-1):
t = time[i]
t_new = time[i+1]
cell_j = cells[:,i,:]
for j in range(cells.shape[0]):
cell = cell_j[j,:]
n_rnd = numbers_rnd[j]
fate_time = fate_times[j]
# if cell is type A check if transition to B occurs
if cell[0] == 0:
if n_rnd > cell[1]:
cell[1] = cell[1]+ (non_exp_cdf(t_new)-non_exp_cdf(t))
else:
cell[0] = 1
cell[2] = t
# if cell is type B check if transition occurs
if cell[0] == 1 and fate_time < (t - cell[2]):
cell[0] = 2
cells[j,i+1,:] = cell
return [cells, time]