04
Initial conditions and population conservation
Differential equations describe how an epidemic changes, but they cannot determine one particular epidemic until its starting state is supplied. In this lesson, we define initial conditions and use Python to check whether they form a valid closed SIR population.
Biological scenario
A town has 5,000 residents. At the beginning of an outbreak, 12 residents are infectious and 3 have already recovered. Everyone else is susceptible.
Before using these values in a model, we must calculate the missing compartment and verify that the initial state is biologically consistent.
What is an initial condition?
An initial condition gives the value of a model variable at the starting time, usually \(t=0\).
\[I(0)=12,\qquad R(0)=3.\]
Because \(N=5000\), the susceptible population is
\[S(0)=N-I(0)-R(0)=5000-12-3=4985.\]
The notation \(S(0)\) means “the susceptible population at time zero.” It is not multiplication of \(S\) by zero.
Conditions for a valid initial state
For individual counts, whole numbers are normally supplied initially. A deterministic solution may later contain decimal compartment values because it is a continuous approximation.
Counts and proportions
The same epidemic state can be represented by numbers of people or by population proportions.
| Compartment | Count | Proportion |
|---|---|---|
| Susceptible | 4,985 | 0.9970 |
| Infectious | 12 | 0.0024 |
| Recovered | 3 | 0.0006 |
| Total | 5,000 | 1.0000 |
For proportions, define \(s=S/N\), \(i=I/N\) and \(r=R/N\). Then
\[s(0)+i(0)+r(0)=1.\]
What population conservation means
A quantity that remains unchanged throughout a model is called an invariant. In the closed SIR model, infection and recovery move people between compartments but do not change the total population.
This conservation statement depends on the modelling assumptions. It would change if the model included births, deaths unrelated to the disease, immigration or emigration.
Valid and invalid examples
Valid
S = 4985
I = 12
R = 3
N = 5000
All values are non-negative and their sum is 5,000.
Invalid
S = 4990
I = 12
R = 3
N = 5000
The compartment sum is 5,005, so five people have been counted twice or the data are inconsistent.
Programming objective
We will write a function that calculates the compartment total, checks each validity condition and returns a clear validation report.
Programming ideas used in the check
| Python | Meaning |
|---|---|
S >= 0 | Checks whether \(S\) is non-negative. |
and | Requires all connected conditions to be true. |
== | Tests whether two values are equal; it does not assign a value. |
if | Runs a block only when its condition is true. |
else | Runs the alternative block when the condition is false. |
return | Sends the validation results back from the function. |
Build the validation program
Step 1: Calculate the missing susceptible population
S0 = N - I0 - R0
The zero in S0 is part of the variable name and indicates the value at time zero.
Step 2: Form Boolean conditions
non_negative = S0 >= 0 and I0 >= 0 and R0 >= 0
positive_population = N > 0
correct_total = S0 + I0 + R0 == N
Each comparison produces either True or False. These are Boolean values.
Step 3: Combine the checks
valid = non_negative and positive_population and correct_total
The state is valid only when every required condition is true.
Run the initial-condition validator
Change the values and run the code. The program will report each condition separately so that an invalid state can be diagnosed.
Output
Run the code to see the result.
Expected outcome
| Check | Outcome | Interpretation |
|---|---|---|
| Non-negative values | True | No compartment contains an impossible negative population |
| Positive population | True | The model has a population to describe |
| Correct total | True | The compartments contain exactly 5,000 people |
| Overall state | Valid | The initial conditions can be used in the closed SIR model |
Biological interpretation
The model begins with 4,985 susceptible, 12 infectious and 3 recovered residents. Infectious residents make up 0.24% of the population. The conditions are internally consistent and account for every resident exactly once.
Validation cannot prove that the data are factually correct. It checks that the values are mathematically and biologically consistent with the stated closed-population assumptions.
Why counts use exact equality here
The program uses compartment_total == N because the initial values are whole-person counts and their addition is exact. When checking calculated decimal proportions or numerical solutions, a small tolerance may be needed because decimal arithmetic can introduce tiny rounding differences.
Try an invalid state
Replace the calculated line S0 = N - I0 - R0 with S0 = 4990.
- Predict which condition will become False.
- Run the code and inspect the report.
- Calculate the compartment total by hand.
- Explain why the state violates the population assumption.