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.

source on GitHub

Classes¶

class

truncated documentation

`EpidemicPopulation`

defines a population

`Person`

defines a person for the simulation colors

`Point`

Defines a point.

`Rect`

Defines a rectangle.

Functions¶

function

truncated documentation

`display_person`

display a person on a pygame screen

`display_population`

affichage

`numerical_simulation`

Run a simulation, `EpidemicPopulation`.

`pygame_simulation`

Runs a graphic simulation. The user can see a pygame screen showing the evolution of population. A healthy …

Methods¶

method

truncated documentation

`__add__`

`__div__`

division by a scalar

`__getitem__`

usual

`__iadd__`

`__idiv__`

divsion by a scalar inplace

`__imul__`

multiplication by a scalar inplace

`__init__`

constructeur

`__init__`

constructor

`__init__`

constructor

`__init__`

constructor

`__isub__`

soustraction inplace

`__iter__`

usual

`__len__`

usual

`__mul__`

multiplication by a scalar

`__str__`

usual

`__sub__`

soustraction

`_get_new_acceleration`

update the acceleration by adding a random gaussian vector to the current acceleration, check that acceleration …

`count`

return the distribution of healthy, sick, cured people

`distance`

return the distance between this person and another one

`evolution`

new iteration

`evolution`

update the population, random acceleration

`limit`

tells if point pos belongs to the area defined by the rectangle

`norm`

return the norm l2

`state_evolution`

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.

source on GitHub

class ensae_teaching_cs.special.propagation_epidemic.EpidemicPopulation(cote=500, nb=(100, 1), **params)

Bases : `object`

defines a population

source on GitHub

constructeur

Paramètres
• cote – size of the zone person move

• nb – tuple number of people (healthy, sick)

• params – others parameters

Draws a population.

source on GitHub

__getitem__(i)

usual

source on GitHub

__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.

source on GitHub

__iter__()

usual

source on GitHub

__len__()

usual

source on GitHub

count()

return the distribution of healthy, sick, cured people

source on GitHub

evolution(dt=0.5)

new iteration

Paramètres

dt – dt

Renvoie

nb1,nb2

We walk through everybody and call `evolution`.

source on GitHub

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

• 2: mort

• 3: gueris

A person moves by drawing a random gaussian vector added to its current acceleration.

source on GitHub

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

source on GitHub

__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

source on GitHub

__str__()

usual

source on GitHub

_get_new_acceleration()

update the acceleration by adding a random gaussian vector to the current acceleration, check that acceleration is not beyond some boundary

source on GitHub

distance(p)

return the distance between this person and another one

source on GitHub

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.

source on GitHub

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.

source on GitHub

class ensae_teaching_cs.special.propagation_epidemic.Point(x, y)

Bases : `object`

Defines a point.

source on GitHub

constructor

Paramètres
• x – x

• y – y

source on GitHub

source on GitHub

__div__(p)

division by a scalar

source on GitHub

source on GitHub

__idiv__(p)

divsion by a scalar inplace

source on GitHub

__imul__(p)

multiplication by a scalar inplace

source on GitHub

__init__(x, y)

constructor

Paramètres
• x – x

• y – y

source on GitHub

__isub__(p)

soustraction inplace

source on GitHub

__mul__(p)

multiplication by a scalar

source on GitHub

__sub__(p)

soustraction

source on GitHub

norm()

return the norm l2

source on GitHub

class ensae_teaching_cs.special.propagation_epidemic.Rect(a, b)

Bases : `object`

Defines a rectangle.

source on GitHub

constructor

Paramètres
• a – Point

• b – Point

source on GitHub

__init__(a, b)

constructor

Paramètres
• a – Point

• b – Point

source on GitHub

limit(pos)

tells if point pos belongs to the area defined by the rectangle

source on GitHub

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

source on GitHub

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

source on GitHub

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
Renvoie

population count

source on GitHub

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

• 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)
```

source on GitHub