Project 7: Bacterial growth and parameter fitting

MCSB Bootcamp — Mathematical and Computational Track

Author

Jun Allard

Model simulation

Given the parameters of a model, we can use ODE solvers to predict the behavior of a model, x(t)x(t).

Given data, can we find which model parameters are the best fit?

  1. Write code to simulate the following model

dNdt=λN(1−(N/θ)α)(1)\frac{dN}{dt} = \lambda N \left( 1 - \left(N/\theta\right)^\alpha\right) \qquad(1)

where the user (you) specifies the parameter values λ=1\lambda=1, θ=103\theta=10^3, α=2\alpha=2, and the initial condition N(0)=200N(0)=200. Plot a time series of Nsim(t)N_\mathrm{sim}(t).

# Your code here.

Data analysis

  1. Write code that loads bacterial growth experimental data into two arrays: one for the amount of bacteria Nexp(ti)N_\mathrm{exp}(t_i) and the other for the measurement time points tit_i. Plot the time series Nexp(ti)N_\mathrm{exp}(t_i).
# Your code here.
  1. Plot the solution N(t)N(t) and the experimental data Nexp(t)N_\mathrm{exp}(t) on the same axes. Set N(0)N(0) to match the experimental data exactly. Manually explore different parameter values of λ,θ,α\lambda,\theta,\alpha to see which values best fit the data.
# Your code here.

Parameter learning

  1. Write code that computes the sum of squared error (SSE), which is

SSE=∑i(Nsim(ti)−Nexp(ti))2\mathrm{SSE} = \sum_i \left( N_\mathrm{sim}(t_i) - N_\mathrm{exp}(t_i)\right)^2

Hint: scipy.integrate.solve_ivp takes a t_eval argument, an array of times. Given one, it returns the solution at those times and no others. This is useful if you only need the solution at the measurement times tit_i.

# Your code here.
  1. Using the code from the previous part, create a function that takes parameters and returns the SSE. Hint: Define it with def in a cell of its own, so that the cells after it can call it.
# Your code here.
  1. Use an automated minimization algorithm like scipy.optimize.minimize to find the parameters that minimize the sum of squared error. These parameters are the “best fit” or “maximum likelihood” parameters λ̂,θ̂,α̂\hat\lambda,\hat\theta,\hat\alpha. Plot, on the same axes, the experimental and best-fit model time series, Nexp(t)N_\mathrm{exp}(t) and Nsim(t)N_\mathrm{sim}(t).
# Your code here.

Model learning

  1. Now repeat the above, but use the model with α=1\alpha=1. Did the fit improve, or worsen?
# Your code here.
  1. Now repeat the above, but with

dNdt=λN.\frac{dN}{dt} = \lambda N.

Note this is numerically the same as Equation 1 with θ≫N\theta \gg N. Did the fit improve, or worsen?

# Your code here.