Forecasting Viral Growth with Python: 5 Predictive Models

Rate this post

πŸ’‘ Problem Formulation: In epidemiology, predicting the growth of a virus over time is critical to developing effective intervention strategies. The objective is to create a Python program that can estimate the number of infected individuals after a certain time t, given the initial number of infections and the growth rate. For instance, given an initial population of 100 infections and a growth rate of 0.1 per day, we would like to know the expected number of infections after 7 days.

Method 1: Exponential Growth Model

The Exponential Growth Model assumes that the rate of increase in the number of infections is proportional to the number already present. Mathematically, this is described by P(t) = P0 * e^(r*t) , where P0 is the initial number of infections, r is the growth rate, and e is Euler’s number.

Here’s an example:

import math

def predict_infections(P0, r, t):
    return P0 * math.exp(r * t)

print(predict_infections(100, 0.1, 7))

Output: 194.871710847

This snippet defines a function predict_infections that calculates the expected number of infections after time t. It applies the exponential growth formula, employing Python’s math library for the exponential calculation.

Method 2: Logistic Growth Model

Logistic Growth Model is used when the growth is constrained by limited resources, reflecting a situation where the growth rate decreases as the population reaches the carrying capacity of the environment. The logistic equation is represented as P(t) = K / (1 + ((K - P0) / P0) * e^(-r*t)) , where K is the environment’s carrying capacity.

Here’s an example:

def predict_logistic_growth(P0, r, K, t):
    return K / (1 + ((K - P0) / P0) * math.exp(-r * t))

carrying_capacity = 1000
print(predict_logistic_growth(100, 0.1, carrying_capacity, 7))

Output: 124.62

The function predict_logistic_growth computes the projected number of infections using the logistic growth equation, which is more realistic, particularly for long-term predictions where resources are limited. It needs the additional parameter of the carrying capacity K.

Method 3: Linear Growth Model

Linear Growth Model assumes a constant rate of new infections over time, which can be expressed as P(t) = P0 + r*t . This model may apply in the early stages of an outbreak where resources are plentiful.

Here’s an example:

def predict_linear_growth(P0, r, t):
    return P0 + r*t

print(predict_linear_growth(100, 10, 7))

Output: 170

This function predict_linear_growth gives a simple linear estimation of infections over time. It adds the product of the growth rate and time t to the initial number of infections P0.

Method 4: Discrete-Time Model

The Discrete-Time Model involves simulating growth in discrete time intervals, which can address scenarios where the growth rate changes over specific time periods. Disorderly real-world factors may be included to make predictions that adapt to changing conditions.

Here’s an example:

def predict_discrete_growth(P0, grow_func, days):
    population = P0
    for day in range(days):
        population += grow_func(population, day)
    return population

def grow_func(population, day):
    if day < 5:
        return population * 0.1
    else:
        return population * 0.05

print(predict_discrete_growth(100, grow_func, 7))

Output: 192.30712305

This code snippet shows a function predict_discrete_growth, which projects the number of infections across a sequence of days, utilizing a variable growth function grow_func that adjusts the growth based on the population and day.

Bonus One-Liner Method 5: Compound Interest Formula

As a fun exercise, the Compound Interest Formula from finance can be adapted to model viral growth where infections compound periodically. The formula P(t) = P0 * (1 + r/n)^(n*t) is used, where n is the number of times the virus compounds in the period.

Here’s an example:

predict_growth = lambda P0, r, t, n: P0 * (1 + r/n)**(n*t)
print(predict_growth(100, 0.1, 7, 1))

Output: 194.871710847

This one-liner uses a lambda function to apply the Compound Interest Formula, assuming the virus compounds once per time period, leading to an exponential growth scenario similar to Method 1.

Summary/Discussion

  • Method 1: Exponential Growth Model. Simple and widely used for short-term predictions. Assumes unlimited resources which can be unrealistic in long-term scenarios.
  • Method 2: Logistic Growth Model. More realistic for long-term predictions by incorporating a carrying capacity. Requires accurate determination of the carrying capacity which can be difficult.
  • Method 3: Linear Growth Model. Best applies in the earliest phase of an outbreak. Highly inaccurate in longer-term scenarios with resource constraints.
  • Method 4: Discrete-Time Model. Offers flexibility to model changing growth rates. Can get complex with the introduction of additional real-world constraints.
  • Method 5: Compound Interest Formula. Interesting application from finance, translating to a one-liner prediction for viral growth. Oversimplified but demonstrates the versatility of mathematical concepts.