AddDelete
: The addition-deletion process
- class epydemic.AddDelete
A process to manage an addition-deletion network, in which nodes are added and deleted at random according to some probability. Nodes that are added are connected to existing nodes.
The default behaviour has fixed addition and removal probabilities, independent of the size of the network, and a fixed degree for added nodes.
Addition-deletion networks are networks in which nodes are added and removed by some random process. They can be used for a number of purposes, perhaps most obviously to model births and deaths, They can be combined (with care) with disease processes to model situations where the underlying network is changing independently of the disease itself.
The canonical work on addition-deletion networks is Moore et alias
[MGN06], which also showed that the process is very complex in its most general case.
Specific solutions are analytically solvable, however: most notably the case where
newly-added nodes are connected to a fixed number of neighbours selected randomly, which
is the default behaviour of this class. Other behaviours can be implemented by overriding
the AddDelete.add()
method (and, less commonly, the AddDelete.delete()
method).
Note that this is a slightly different formulation to that in the paper, which defines
an “addition kernel” as a function independent of the actions of the process:
implementationally it seems to make more sense to provide this functionality by
sub-classing rather than through a separate object.
Parameters
The addition-deletion process is controlled by three parameters:
-
AddDelete.P_ADD:
Final
[str
] = 'epydemic.addDelete.pAdd' Parameter for the node addition probability.
-
AddDelete.P_DELETE:
Final
[str
] = 'epydemic.addDelete.pDelete' Parameter for the node deletion probability.
-
AddDelete.DEGREE:
Final
[str
] = 'epydemic.addDelete.addDegree' Degree of newly-added nodes.
Loci
The addition-deletion process works independently of the size of the network: it
simply adds and delete nodes according to the probabilities given by the
AddDelete.P_ADD
and AddDelete.P_DELETE
parameters. Since it’s
expensive in networkx to draw a random node, we keep track of them in a locus.
-
AddDelete.NODES:
Final
[str
] = 'allnodes' Name of the locus holding all nodes in the network.
Building the model
Building the model adds the add and remove events, independent of the network size.
- AddDelete.build(params)
Build the model. This method expects parameters for the node addition and deletion probabilities, and for the degree of newly-created nodes.
- Parameters:
params (
Dict
[str
,Any
]) – the model parameters
- AddDelete.setUp(params)
Set up the network under the given dynamics. The default does nothing: sub-classes should override it to initialise node states or establish other properties ready for the experiment.
- Parameters:
params (
Dict
[str
,Any
]) – the simulation parameters
Evolving the network
Addition-deletion networks are intrinsically dynamic, so we override some methods from the
Process
evolution interface and add a couple of helper methods to keep track
of the nodes added and deleted.
- AddDelete.addNode(n, **kwds)
Add a node to the working network. Any keyword arguments added as node attributes.
- Parameters:
n (
Any
) – the new nodekwds – (optional) node attributes
- AddDelete.removeNode(n)
Remove a node from the working network.
- Parameters:
n (
Any
) – the node
- AddDelete.addNewNode(**kwds)
Add a new node to the network with a new, unused name. Any keyword arguments are added as node attributes.
- Parameters:
kwds – (optional) node attributes
- Return type:
Any
- Returns:
the generated name of the new node
- AddDelete.newNodeName()
Generate a new name for a node to be added. This is guaranteed not to be the name of another node in the network (although it might possibly re-use a name of a node that’s been removed).
- Return type:
Any
- Returns:
the generated name
Events
There are two events that can be triggered: one to add a node, and one to remove a node. These two events provide the “kernel” of the addition-deletion process and can be specialised to explore new behaviours.
- AddDelete.add(t, e)
Add a node to the network, connecting it at random to other nodes. The degree of the new node is given by the
DEGREE
parameter, with the nodes being selected at random from the entire network.The node is added to the network by calling
addNewNode()
.- Parameters:
t (
float
) – the current simulation time (not used)e (
Union
[Any
,Tuple
[Any
,Any
]]) – the element (not used)
- AddDelete.delete(t, n)
Delete a node from the network. The node is deleted from the network by calling
removeNode()
.- Parameters:
t (
float
) – the current simulation time (not used)n (
Any
) – the node to be removed
Changed in version 1.0.0: This method was called remove
until version 1.0.0, when it was changed to
avoid a clash with the event function of the same name in SIR
.