Skip to content

A JS library implementing the SIR epidemic simulation model.

Notifications You must be signed in to change notification settings

petrosDemetrakopoulos/SIR.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SIR.js

SIR.js is a JS library implementing the SIR epidemic simulation model.

Installation

npm i --save sir.js

Example

let SIRjs = require('sir.js');

let solution = SIRjs.solve({S0: 100, I0: 10, R0: 0, t:1, N: 10, beta: 0.8, gamma: 0.4});
SIRjs.printChart(solution);

Functions

It has only 2 functions: solve() and printChart() solve() function takes an object argument with the following keys:

  • S0: Initial S (Susceptible) value
  • I0: Initial I (Infectious) value
  • R0: Initial R (Recovered) value
  • t: The time step
  • N: The time span (in units of time) aka the length of the simulation
  • beta: The parameter controlling how often a susceptible-infected contact results in a new infection
  • gamma: The rate an infected recovers and moves into the resistant phase

It returns an array of objects that contain S,I and R values for each moment.

printChart() function prints an ASCII chart for each one of the S,I,R variables

i.e

=========== S ===========

00.00   โ”ผโ”€โ”€โ”€โ”€โ•ฎ
87.95   โ”ค    โ•ฐโ”€โ”€โ”€โ•ฎ
75.90   โ”ค        โ•ฐโ”€โ”€โ”€โ”€โ”€โ•ฎ
63.84   โ”ค              โ•ฐโ”€โ”€โ”€โ•ฎ
51.79   โ”ค                  โ•ฐโ”€โ”€โ”€โ”€โ”€โ•ฎ
39.74   โ”ค                        โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
27.69   โ”ค                                    โ•ฐโ”€โ”€


=========== I ===========

22.27   โ”ค              โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
20.23   โ”ค          โ•ญโ”€โ”€โ”€โ•ฏ       โ•ฐโ”€โ”€โ”€โ•ฎ
18.18   โ”ค        โ•ญโ”€โ•ฏ               โ•ฐโ”€โ”€โ”€โ•ฎ
16.14   โ”ค      โ•ญโ”€โ•ฏ                     โ•ฐโ”€โ”€โ”€โ•ฎ
14.09   โ”ค  โ•ญโ”€โ”€โ”€โ•ฏ                           โ•ฐโ”€โ•ฎ
12.05   โ”คโ•ญโ”€โ•ฏ                                 โ•ฐโ”€โ”€
10.00   โ”ผโ•ฏ


=========== R ===========

70.63   โ”ผ                                  โ•ญโ”€โ”€โ”€โ”€
58.86   โ”ค                            โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฏ
47.08   โ”ค                      โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฏ
35.31   โ”ค                โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฏ
23.54   โ”ค          โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฏ
11.77   โ”ค    โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฏ
 0.00   โ”ผโ”€โ”€โ”€โ”€โ•ฏ

License

SIR.js is licensed under MIT license.

About

A JS library implementing the SIR epidemic simulation model.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published