module special.propagation_epidemic
#
Short summary#
module ensae_teaching_cs.special.propagation_epidemic
Simple simulation of an epidemic. It makes a couple of assumption on how the disease is transmitted and its effect on a person. The user can specify many parameters.
Classes#
class |
truncated documentation |
---|---|
defines a population |
|
defines a person for the simulation colors |
|
Defines a point. |
|
Defines a rectangle. |
Functions#
function |
truncated documentation |
---|---|
display a person on a pygame screen |
|
affichage |
|
Run a simulation, |
|
Runs a graphic simulation. The user can see a pygame screen showing the evolution of population. A healthy … |
Methods#
method |
truncated documentation |
---|---|
addition |
|
division by a scalar |
|
usual |
|
addition inplace |
|
divsion by a scalar inplace |
|
multiplication by a scalar inplace |
|
constructeur |
|
constructor |
|
constructor |
|
constructor |
|
soustraction inplace |
|
usual |
|
usual |
|
multiplication by a scalar |
|
usual |
|
soustraction |
|
update the acceleration by adding a random gaussian vector to the current acceleration, check that acceleration … |
|
return the distribution of healthy, sick, cured people |
|
return the distance between this person and another one |
|
new iteration |
|
update the population, random acceleration |
|
tells if point pos belongs to the area defined by the rectangle |
|
return the norm l2 |
|
update the state of the person: healthy –> sick –> cured or dead |
Documentation#
Simple simulation of an epidemic. It makes a couple of assumption on how the disease is transmitted and its effect on a person. The user can specify many parameters.
- class ensae_teaching_cs.special.propagation_epidemic.EpidemicPopulation(cote=500, nb=(100, 1), **params)#
Bases :
object
defines a population
constructeur
- Paramètres:
cote – size of the zone person move
nb – tuple number of people (healthy, sick)
params – others parameters
Draws a population.
- __getitem__(i)#
usual
- __init__(cote=500, nb=(100, 1), **params)#
constructeur
- Paramètres:
cote – size of the zone person move
nb – tuple number of people (healthy, sick)
params – others parameters
Draws a population.
- __iter__()#
usual
- __len__()#
usual
- count()#
return the distribution of healthy, sick, cured people
- evolution(dt=0.5)#
new iteration
- Paramètres:
dt – dt
- Renvoie:
nb1,nb2
We walk through everybody and call
evolution
.
- class ensae_teaching_cs.special.propagation_epidemic.Person(position, borne_pos=None, borne_acc=None, alea_acc=5, sick_vit=0.25, rayon=10, nb_day=70, prob_die=0.5, prob_cont=0.5)#
Bases :
object
defines a person for the simulation
colors
0: sain
1: malade
2: mort
3: gueris
A person moves by drawing a random gaussian vector added to its current acceleration.
constructor
- Paramètres:
position – position
borne_pos – upper bound for the position (rectangle)
borne_acc – upper bound for the acceleration (rectangle)
alea_acc – sigma to draw random acceleration
sick_vit – when people are sick, they go slower, this muliplies the acceleration by a factor
rayon – radius, below that distance, a sick person is contagious for the neighbours
nb_day – number of days a person will be sick, after, the person either recovers, either dies
prob_die – probability to die at each iteration
prob_cont – probability to transmit the disease to a neighbour
- __init__(position, borne_pos=None, borne_acc=None, alea_acc=5, sick_vit=0.25, rayon=10, nb_day=70, prob_die=0.5, prob_cont=0.5)#
constructor
- Paramètres:
position – position
borne_pos – upper bound for the position (rectangle)
borne_acc – upper bound for the acceleration (rectangle)
alea_acc – sigma to draw random acceleration
sick_vit – when people are sick, they go slower, this muliplies the acceleration by a factor
rayon – radius, below that distance, a sick person is contagious for the neighbours
nb_day – number of days a person will be sick, after, the person either recovers, either dies
prob_die – probability to die at each iteration
prob_cont – probability to transmit the disease to a neighbour
- __str__()#
usual
- _get_new_acceleration()#
update the acceleration by adding a random gaussian vector to the current acceleration, check that acceleration is not beyond some boundary
- distance(p)#
return the distance between this person and another one
- evolution(dt, population)#
update the population, random acceleration
- Paramètres:
dt – time delta (only used to update the position)
population – other set of people
The function updates the state of the person, draws a new acceleration and updates the position.
- state_evolution(population)#
update the state of the person: healthy –> sick –> cured or dead
- Paramètres:
population – sets of other persons
The function updates the state of the persons. One of steps involves looking over the entire population to check if some sick people are close enough to transmis the disease.
- class ensae_teaching_cs.special.propagation_epidemic.Point(x, y)#
Bases :
object
Defines a point.
constructor
- Paramètres:
x – x
y – y
- __add__(p)#
addition
- __div__(p)#
division by a scalar
- __iadd__(p)#
addition inplace
- __idiv__(p)#
divsion by a scalar inplace
- __imul__(p)#
multiplication by a scalar inplace
- __init__(x, y)#
constructor
- Paramètres:
x – x
y – y
- __isub__(p)#
soustraction inplace
- __mul__(p)#
multiplication by a scalar
- __sub__(p)#
soustraction
- norm()#
return the norm l2
- class ensae_teaching_cs.special.propagation_epidemic.Rect(a, b)#
Bases :
object
Defines a rectangle.
constructor
- Paramètres:
a – Point
b – Point
- __init__(a, b)#
constructor
- Paramètres:
a – Point
b – Point
- limit(pos)#
tells if point pos belongs to the area defined by the rectangle
- ensae_teaching_cs.special.propagation_epidemic.display_person(self, screen, pygame)#
display a person on a pygame screen
- Paramètres:
self – Person
screen – screen
pygame – module pygame
- ensae_teaching_cs.special.propagation_epidemic.display_population(self, screen, pygame, font, back_ground)#
affichage
- Paramètres:
self – Person
screen – screen
font – font (pygame)
back_ground – back ground color
pygame – module pygame
- ensae_teaching_cs.special.propagation_epidemic.numerical_simulation(nb=(200, 20), cote=600, iter=1000, fLOG=<function noLOG>, **params)#
Run a simulation,
EpidemicPopulation
.- Paramètres:
iter – number of iterations to run
cote –
EpidemicPopulation
nb –
EpidemicPopulation
params –
EpidemicPopulation
fLOG – to display status every 10 iterations
- Renvoie:
population count
- ensae_teaching_cs.special.propagation_epidemic.pygame_simulation(pygame, first_click=False, folder=None, iter=1000, cote=600, nb=(200, 20), flags=0, **params)#
Runs a graphic simulation. The user can see a pygame screen showing the evolution of population. A healthy person is white, green is sick, blue is healed, black is dead. The function can save an image for every iteration. They can be merged into a video with function
make_video
.- Paramètres:
pygame – module pygame (avoids importing in this file)
first_click – starts the simulation after a first click
folder – to save the simulation, an image per simulation
iter – number of iterations to run
cote –
EpidemicPopulation
nb –
EpidemicPopulation
params –
EpidemicPopulation
flags – see pygame.display.set_mode
fLOG – logging function
The simulation looks like this:
Pour lancer la simulation:
from ensae_teaching_cs.special.propagation_epidemic import pygame_simulation import pygame pygame_simulation(pygame)