module special.propagation_epidemic

Inheritance diagram of ensae_teaching_cs.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__

addition

__div__

division by a scalar

__getitem__

usual

__iadd__

addition inplace

__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)[source]

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)[source]

usual

source on GitHub

__init__(cote=500, nb=(100, 1), **params)[source]

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__()[source]

usual

source on GitHub

__len__()[source]

usual

source on GitHub

count()[source]

return the distribution of healthy, sick, cured people

source on GitHub

evolution(dt=0.5)[source]

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)[source]

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.

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)[source]

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__()[source]

usual

source on GitHub

_get_new_acceleration()[source]

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)[source]

return the distance between this person and another one

source on GitHub

evolution(dt, population)[source]

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)[source]

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)[source]

Bases : object

Defines a point.

source on GitHub

constructor

Paramètres
  • x – x

  • y – y

source on GitHub

__add__(p)[source]

addition

source on GitHub

__div__(p)[source]

division by a scalar

source on GitHub

__iadd__(p)[source]

addition inplace

source on GitHub

__idiv__(p)[source]

divsion by a scalar inplace

source on GitHub

__imul__(p)[source]

multiplication by a scalar inplace

source on GitHub

__init__(x, y)[source]

constructor

Paramètres
  • x – x

  • y – y

source on GitHub

__isub__(p)[source]

soustraction inplace

source on GitHub

__mul__(p)[source]

multiplication by a scalar

source on GitHub

__sub__(p)[source]

soustraction

source on GitHub

norm()[source]

return the norm l2

source on GitHub

class ensae_teaching_cs.special.propagation_epidemic.Rect(a, b)[source]

Bases : object

Defines a rectangle.

source on GitHub

constructor

Paramètres
  • a – Point

  • b – Point

source on GitHub

__init__(a, b)[source]

constructor

Paramètres
  • a – Point

  • b – Point

source on GitHub

limit(pos)[source]

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)[source]

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)[source]

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)[source]

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)[source]

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

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