I would like to know how to extract the intial values for the state variables.
Basically, the intial values are also considered as parameters.
I'm providing the initial values because they are needed for integration. However, these values are sometimes considered as additional parameters (next to the model parameters), so that the initial values provided are also considered are initial guesses. In fact, when doing growth experiments, we have some initial conditions, but we may not know all of them (depending on the specific experimental conditions and system under investigation).
Consider a simple microbial growth model with the growth rate mu governed by the well-known Monod kinetic (parameters mumax and ks) and a constant biomass-substrate yield (parameter yxs) and a growth-associated product formation (parameter ypx). See the code below.
For further implementations I would like to calculate first-order sensitivities over time, parameter correlations, etc.
from symfit import variables, parameters, ODEModel, Fit, D
import numpy as np
from matplotlib import pyplot as plt
# define ODE model
ks, mumax, ypx, yxs = parameters('ks, mumax, ypx, yxs')
p, s, x, t = variables('p, s, x, t')
model_dict = {
D(x, t): mumax * s / (ks + s) * x,
D(s, t): -1/yxs * mumax * s / (ks + s) * x,
D(p, t): ypx * mumax * s / (ks + s) * x,
}
ode_model = ODEModel(model_dict, initial={t:0.0, x:0.1, s:20.0, p:0.0})
# Generate noisy measurement data
tSample = np.array([1, 2, 4, 6, 8, 12])
pSample, sSample, xSample = ode_model(t=tSample, ks=0.01, mumax=0.4, ypx=0.2, yxs=0.5)
xRelErr = 0.05
sRelErr = 0.10
pRelErr = 0.10
xNoise = xSample + xSample * xRelErr * np.random.randn(xSample.size)
sNoise = sSample + sSample * sRelErr * np.random.randn(sSample.size)
pNoise = pSample + pSample * pRelErr * np.random.randn(pSample.size)
# constraints for parameters
ks.min = 0.0
mumax.min = 0.0
ypx.min = 0.0
yxs.min = 0.0
# initial guesses for parameters
ks.value = 0.01
mumax.value = 0.4
ypx.value = 0.2
yxs.value = 0.5
# perform fitting
fit = Fit(ode_model, t=tSample, x=xNoise, s=sNoise, p=pNoise)
fit_result = fit.execute()
# show fit
print(fit_result)
print(fit_result.covariance_matrix)