Featured image of post Agent-based demographic simulation on Python

Agent-based demographic simulation on Python

Results, plots, and code of my demographic simulation project.

During my master thesis, I implemented an agent-based simulation that imitates some aspects of human reproductive behavior. One result of the simulation is a figure like the following:

oscilation_explanation

In this fantasy example we have, the evolution of population pyramid with number of habitants, and house occupation.

Features

The project was implemented in Python. It has some of the following features:

  • Initial conditions can be defined with a .yaml config file.
  • For non extinction cases, the last simulation state is saved. This allows to set a simulated system as initial condition.
  • Save execution time, mean and max memory usage.
  • The simulation tags the output by its state in the last iteration.
  • Capacity to plot figures by specific iteration number intervals.
  • Explore statistical metrics in specific iteration number intervals.
  • Can set the proportion of same gender couples to be created.
  • Save for every iteration: population pyramid, birth rate, death rate, couples, number of deaths, number of births.

Observations

For a certain set of parameters, the system stabilizes itself. Let’s suppose we restrict the system to only allow births and natural deaths. Population can only change if there is a difference in these two quantities. Therefore, if population starts to stabilize, we should expect the \(\text{death rate}\) and \(\text{birth rate}\) to start to be similar. That is, for every decrease in population by deaths, we have an equal injection of people trough births, mathematically:

$$ \text{birth rate} \approx \text{death rate} $$

Since they are similar values, we can expect them to be positively correlated, let’s take quick look to it:

birth_rate_Vs_death_rate

Both rates are correlated, and the variance starts to fall as times goes on.


Invitame un café en cafecito.app

Built with Hugo
Theme Stack designed by Jimmy