I've been trying for days to calculate a partial derivative in python, including several other posts on here!
I think I'm a step closer to figuring out what I need to do but I'm unsure how to implement a manual partial differentiation of the following formula in python.
aj(x) = cj * product (xi, si)
Which calculates the probability of a biochemical reaction firing in a system of multiple reactions. The partial differentiation needs to be with respect to xi which is an array of discrete molecule numbers for each molecular species in the model called popul_num.
Where product (xi, si) is the product of the binomial coefficient, for the array containing discrete molecule numbers and a second array LHS that contains the ratios of molecules in each reaction (si).
So over all my derivation equation should be something like: bj(x) = daj(x)/d(xi).
I have written the following function that calculates aj(x) for each reaction and returns an array:
import numpy
import scipy
def propensity_calc(LHS, popul_num, stoch_rate):
propensity = np.zeros(len(LHS))
for row in range(len(LHS)):
a = stoch_rate[row]
for i in range(len(popul_num)):
if (popul_num[i] >= LHS[row, i]):
binom_rxn = binom(popul_num[i], LHS[row, i])
aj = a*binom_rxn
else:
aj = 0
break
propensity[row] = aj
return propensity
where stoch_rate is an array containg the rate of each reaction.
I tried using scipys misc.derivation method, but my supervisor has since told me to do it by hand and I'm not sure how to implement that in python.
Its maybe a bit more a maths question, and if anyone knows a more appropriate place for me to ask or has any good links to online resources for me to read, please point me towards it!
Cheers