# 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
compartmentsArray (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.keyObject (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
timeNumber (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
compartmentObject (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
compartmentArray (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.
# 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,
[1]: #model-2
"R": 0,
"p": 10100,
"u": 0.2
[3]: #get-data
let sirm = new Model([[susceptible, "S"], [infected, "I"], [recovered, "R"]], key)
sirm.remove(susceptible) // Removes the susceptible compartment.
sirm.add([susceptible, "S"]) // Adds the susceptible compartment back.
# mexport
NodeJS only! Exports models to a file which can then be imported later on.
# Parameters
modelThe EpiJS model to exportoutputString (opens new window) The output file path, doesn't have to existfile_typeString (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
inputString (opens new window) The input file path, as a relative path.file_typeString (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")