Previous topic

STATE_ATTR_NAME

This Page

ScriptedProcess

class nepidemix.process.ScriptedProcess(**kwargs)

A scripted process reads its node and edge rules, as well as states from a file.

This allows for rapid prototyping of processes without the need of overloading and implementing python classes. The state update rules are written in an ini/python like script outlined below.

None of the configuration sections in the ScriptedProcess ini file have fixed options. Rather the option names and values are taken on specific forms to declare states and rules. This is explained in the table below outlining the different sections and how to declare options in each:

ScriptedProcess configuration sections
Section Explanation
NodeAttributes Declaration of node attributes. Option names will be taken as attribute names, and the value (a single value, or a comma-separated list) is a list of all possible values this attribute can take.
EdgeAttributes Declaration of edge attributes. Option names will be taken as attribute names, and the value (a single value, or a comma-separated list) is a list of all possible values this attribute can take.
MeanFieldStates Declaration of mean field states. Declaration of mean fields. This serves two purposes. First it allows the node and edge rules to access the fraction of nodes/edges in this state using the MF operator (see below). Second, the number of nodes/edges in each mean field state will be given to simulation to be tracked over time. This field is not a standard ini-style option-value declaration. Rather only options (without the ‘=’ sign) is allowed here. Each option is taken to be a declaration of a mean field state, and should be on dictionary form. I.e. {attribute1:key1, attribute2:key2, ...}. Partial states are allowed here. Partial, meaning a dictionary that either only specifies some of the states declared in the NodeAttributes or EdgeAttributes sections, or which define their values on a form {attribute_n:(key1, key2,..., key_m), ...}. That is in the latter case, giving a tuple of alternative values for one or more attributes. In each of these cases a separate mean field state is created for every possible state being part of the state-sub-space defined by the partial state, and a special mean field state is created for the sub- space defined. It is also possible to use {} (the empty dictionary) to match every individual state, and the total mean field (constant).
NodeRules List of node transition rules. Each option-value pair is considered a node update rule. The option is a string defining which node attribute set should match the rule, and if the rule is followed which attribute updates should be performed to the dictionary (thereby sending it to another state). The value is an expression computing the unit-time probability of following the rule. First let’s give the option form. This is {attribute1:key1, attribute2:key2, ...} -> {attribute_k:key_k,...}. On the left side of the -> sign is a full or partial state as a node attribute dictionary (see the mean field notes above) and will be matched to the node state. If it is a partial state, rules for all possible states will be constructed. On the right side of the -> sign is the updates that should be performed to the dictionary in case the rule is followed through. Typically this is a change to a single attribute, but it is also possible to change multiple attributes. The option value is an expression that should compute a probability in unit time. This is the probability that the rule is followed through and the update to the node dictionary is made. Any variable name used in this expression is assumed to be a process parameter, and will have to be set in the simulation configuration. For variable names anything that is not a python specific names, or either MF or NN. The names MF and NN are specific functions that can be used in the expression. NN({attribute1:key1, attribute2:key2, ...}) yields the number of nearest neighbors in the given state (or partial state). There is also a special version that takes a second argument which should be a full or partial edge state. The counting of nearest neighbors is then only performed on edges matching this edge state. MF({attribute1:key1, attribute2:key2, ...}) gives the mean field (fraction of nodes/edges) in the given state. Note that for MF only declared mean field states are valid. See the tutorial for examples. Finally, several rules matching the same states can be written and they will be evaluated in the order declared.

Examples

SIR process ini-file The standard S-I-R model could be configured as follows:

[NodeAttributes]
# Declaration of node attributes and possible values.
# A single attribute called state with three different possible values

status = S,I,R

[MeanFieldStates]
# Declaration of mean filed states.
# As no mean field states are used in the SIR calculations this section
# could be left out. However, the Simulation will automatically log the
# mean field states so it is convenient to declare the ones we want to
# track.

{status:S}
{status:I}
{status:R}

[NodeRules]
# Declaration of update rules.
# Each rule is on the form <src state> -> <update> = <expression>
# The states are given as python dictionaries. The expressions should
# return the probability in unit time to execute the attribute update.
# Special function 'NN' give the number of neighbors matching some
# state dictionary. All undefined names are assumed to be parameters of
# the process.x

# From state S to state I: num. infected neighbors times a parameter beta.
{status:S} -> {status:I} = NN({status:I}) * beta

# From state I to state R: a flat rate gamma.
{status:I} -> {status:R} = gamma

Methods

deduceEdgeState(edge) Gives the state of a edge.
deduceNodeState(node) Gives the state of a node.
edgeUpdateRule(edge, srcNetwork, dt) Perform local edge change.
initializeNetwork(network, *args, **kwargs) Initialize the mean field states on the network.
initializeNetworkEdges(network, *args, **kwargs) Set initial edge states and parameters to a network.
initializeNetworkNodes(network, *args, **kwargs) Set initial node states and parameters to a network.
networkUpdateRule(network, dt) Perform update to global network structure and attributes.
nodeUpdateRule(node, srcNetwork, dt) Perform local node changes.
__init__(**kwargs)

Reads process configuration from file and initializes process.

If no node/edge rules are given the corresponding update functionality is turned off in Superclass Process.

Parameters :

file : string

The name and path of the configuration file.

kwargs : special

All additional parameters passed to __init__ will be treated as being process rule parameters and will be added to the rule evaluation namespace.

Methods

__init__(**kwargs) Reads process configuration from file and initializes process.
deduceEdgeState(edge) Gives the state of a edge.
deduceNodeState(node) Gives the state of a node.
edgeUpdateRule(edge, srcNetwork, dt) Perform local edge change.
initializeNetwork(network, *args, **kwargs) Initialize the mean field states on the network.
initializeNetworkEdges(network, *args, **kwargs) Set initial edge states and parameters to a network.
initializeNetworkNodes(network, *args, **kwargs) Set initial node states and parameters to a network.
networkUpdateRule(network, dt) Perform update to global network structure and attributes.
nodeUpdateRule(node, srcNetwork, dt) Perform local node changes.

Attributes

CFG_PARAM_config_file str(object) -> string
CFG_PARAM_deal_exact str(object) -> string
CFG_SECTION_edge_attribs str(object) -> string
CFG_SECTION_edge_rules str(object) -> string
CFG_SECTION_mean_field str(object) -> string
CFG_SECTION_node_attribs str(object) -> string
CFG_SECTION_node_rules str(object) -> string