# Table of Contents
# Model
EpiJS module for creating custom models, which are made of compartments.
Import it with:
const model = require('@epispot/epijs').model
# Model
Create a model.
# Parameters
compartments
Array (opens new window) Compartments in the model. Each should be a list, with the first value being the compartment, and the second being it's start value in the key.key
Object (opens new window) The key of values for any variable used in the equation. If you use any variable which represents the population of a compartment, add the starting value into the key.
# Examples
let susceptible = new Idiom("S-(B*S*I/p)");
let infected = new Idiom("I+(B*S*I/p)-(u*I)");
let recovered = new Idiom("R+(u*I)");
let key = {
"S": 10000,
"B": 0.3,
"I": 100,
"R": 0,
"p": 10100,
"u": 0.2
};
let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
# get_data
Get data for the outbreak.
# Parameters
time
Number (opens new window) The total time to model.
# Examples
let susceptible = new Idiom("S-(B*S*I/p)");
let infected = new Idiom("I+(B*S*I/p)-(u*I)");
let recovered = new Idiom("R+(u*I)");
let key = {
"S": 10000,
"B": 0.3,
"I": 100,
"R": 0,
"p": 10100,
"u": 0.2
};
let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
model.get_data(100) // Get data for 100 days.
# remove
Remove a compartment from the model.
# Parameters
compartment
Object (opens new window) The compartment to remove.
# Examples
let susceptible = new Idiom("S-(B*S*I/p)");
let infected = new Idiom("I+(B*S*I/p)-(u*I)");
let recovered = new Idiom("R+(u*I)");
let key = {
"S": 10000,
"B": 0.3,
"I": 100,
"R": 0,
"p": 10100,
"u": 0.2
};
let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
sirm.remove(recovered) // Removes the recovered compartment.
# add
Add a compartment to the model.
# Parameters
compartment
Array (opens new window) The compartment to add, should be a list, with the first value being the compartment, and the second being it's value in the key.index
Number (opens new window) The index to add the compartment at.
# Examples
let susceptible = new Idiom("S-(B*S*I/p)");
let infected = new Idiom("I+(B*S*I/p)-(u*I)");
let recovered = new Idiom("R+(u*I)");
let key = {
"S": 10000,
"B": 0.3,
"I": 100,
"R": 0,
"p": 10100,
"u": 0.2
};
let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
sirm.remove(susceptible) // Removes the susceptible compartment.
sirm.add([susceptible, "S"], 0) // Adds the susceptible compartment back to the beginning
# mexport
NodeJS only! Exports models to a file which can then be imported later on.
# Parameters
model
The EpiJS model to exportoutput
String (opens new window) The output file path, doesn't have to existfile_type
String (opens new window) The file type to output. Supported inputs are ".json" and ".js". (optional, default".json"
)
# Examples
let susceptible = new Idiom("S-(B*S*I/p)");
let infected = new Idiom("I+(B*S*I/p)-(u*I)");
let recovered = new Idiom("R+(u*I)");
let key = {
"S": 10000,
"B": 0.3,
"I": 100,
"R": 0,
"p": 10100,
"u": 0.2
};
let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
mexport(sirm, "output.js", file_type=".js")
# mimport
NodeJS only! Imports a model from a file.
# Parameters
input
String (opens new window) The input file path, as a relative path.file_type
String (opens new window) The file type of the input. Supported inputs are ".json" and ".js". (optional, default".json"
)
# Examples
// Use mexport to export a model into a file
let sirm = mimport("./output.json")