【问题标题】:Calculating propensity functions in python在python中计算倾向函数
【发布时间】:2020-04-25 17:47:00
【问题描述】:

我正在尝试使用以下等式在 python 中计算倾向函数:倾向函数 = stoch_rate*binom(xi, si) 的乘积 其中 xi 是反应中特定反应物的离散分子的数量,si 是每个方程式中反应物之间的比率,两者都存储在矩阵中。

popul_num = np.matrix([100, 200, 0, 0])
LHS = np.matrix([[1,1,0,0], [0,0,1,0], [0,0,1,0]]) --> three rows for 3 different reactions, each row has 4 elements describing the ratio of reactants in that particular reaction
stoch_rate = np.matrix([0.0016, 0.0001, 0.1000]) --> rates for each of the three reactions above

我的系统有 4 个实体;酶、底物、酶-底物复合物和产物。这些在 popul_num 和 LHS 矩阵中按顺序描述。

我编写了以下代码来迭代矩阵的元素计算每个反应物的二项式系数(基于 popul_num 中的分子数和 LHS 中的比率),然后乘以速率常数以生成倾向函数.

for j in LHS:
aj = stoch_rate
for i in popul_num: 
    if np.any(i >= LHS[i,j]):
        # ^^^IndexError --> index 100 is out of bounds for axis 0 with size 3^^^
        aj = list(aj*binom(i, LHS[i, j]))             
    else: 
        aj == 0 
        break
print(aj)

if 语句的意思是检查 popul_num 中离散分子的数量是否足够高,以允许根据 LHS 中的化学计量/比率发生反应。

我收到索引错误:index 100 is out of bounds for axis 0 with size 3

我知道索引从零开始,并尝试查找一些解决方案,但没有任何查找!

任何帮助将不胜感激

干杯

【问题讨论】:

    标签: python numpy matrix


    【解决方案1】:

    您在 for 循环中引用的是值而不是索引。更正代码:

    def stoch():
        popul_num = np.matrix([100, 200, 0, 0])
        LHS = np.matrix([[1,1,0,0], [0,0,1,0], [0,0,1,0]]) #--> three rows for 3 different reactions, each row has 4 elements describing the ratio of reactants in that particular reaction
        stoch_rate = np.matrix([0.0016, 0.0001, 0.1000]) #--> rates for each of the three reactions above
    
        for j in range(len(LHS)):
            aj = stoch_rate
            for i in range(len(popul_num)):
                if np.any(i >= LHS[i,j]):
                    aj = list(aj*binom(i, LHS[i, j]))             
            else: 
                aj == 0 
                break
        print(aj)
    

    输出:

    >>> stoch()
    [[ 0.0016  0.0001  0.1   ]]
    

    【讨论】:

      猜你喜欢
      • 2022-11-21
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多