Models¶
The model of motion is organized into two distinct (but interacting) parts: a
model for the network structure and a model for the moving agent (walker). The
network model (NetworkModel
) is used to represent
the structure on which the agents move (the underlining graph, edges direction,
time evolution of the network). Instead, the agent model
(Walker
) implements the logic of the motion (e.g. how
is the next move chosen, how much time does it take to cross an edge).
Different implementations and combination of these entities make it possible to
flexibly represent different models of motion.
Network models¶
Network models represent the structure on which walkers move. Walkers interact
with the network models by means of the
neighbors()
method.
-
class
er.model.network.
MemorylessSwitch
(source, timescale)¶ Bases:
object
A switch object that does not have memory of past events.
Once its state is queried with open, it is not possible to retrieve the value of a previous state in time.
-
class
er.model.network.
NetworkModel
(graph: networkx.classes.graph.Graph, **params)¶ Bases:
object
The base network model.
-
abstract
neighbors
(node, time=0)¶ Returns a list of accessible neighbors of node.
- Parameters
node – The node from which the neighbors are searched.
time (float) – The current time, it is required if the network structure varies with time.
-
reset
() → None¶ Resets the network state.
-
size
() → int¶ Returns the number of nodes in the network.
-
abstract
-
class
er.model.network.
Switch
(source, timescale, batch=1000)¶ Bases:
object
A switch object that keeps memory of the past states.
-
clear
(time)¶ Clears the memory of events before given time.
- Args:
time: The time limit.
-
-
class
er.model.network.
SwitchingNetwork
(graph: networkx.classes.graph.Graph, **params)¶ Bases:
er.model.network.NetworkModel
Network model with switching edge direction.
SwitchingNetwork implements a directed network where the direction of edges changes in time as a Poisson’s process. Walkers moving on this network can only move through outward edges (if any).
-
clear_memory
(min_time)¶ Clears the memory of the switching events before the given time.
-
neighbors
(node, time)¶ Returns a list of accessible neighbors of node.
- Parameters
node – The node from which the neighbors are searched.
time (float) – The current time, it is required if the network structure varies with time.
-
reset
()¶ Resets the network state.
-
-
class
er.model.network.
SwitchingNetworkConstantRate
(graph: networkx.classes.graph.Graph, **params)¶ Bases:
er.model.network.SwitchingNetwork
Network model with switching edge direction and constant flow.
This class is a slightly modified version of
SwitchingNetwork
. In this implementation, the flow is not split across outward edges. In practical terms it means that for a node with \(N\) total edges, of which \(N_{outward}\) are outward directed, the particle will move to a neighbor with probability \(\frac{N_{outward}}{N}\) and remain in the current node with probability \(\frac{1- N_{outward}}{N}\).-
neighbors
(node, time)¶ Returns a list of accessible neighbors of node.
- Parameters
node – The node from which the neighbors are searched.
time (float) – The current time, it is required if the network structure varies with time.
-
-
class
er.model.network.
UndirectedNetwork
(graph: networkx.classes.graph.Graph, **params)¶ Bases:
er.model.network.NetworkModel
Undirected network model.
UndirectedNetwork is a simple model for the motion on an undirected graph. Walkers can go through the edges in both directions, independently of time.
-
neighbors
(node, time=0)¶ Returns a list of accessible neighbors of node.
- Parameters
node – The node from which the neighbors are searched.
time (float) – The current time, it is required if the network structure varies with time.
-
Walker models¶
Walkers represent agents moving on the network. Different implementations reflect the different logic used to choose the next move and the parameters of motion (e.g. waiting time in the nodes, edge crossing time).
-
class
er.model.walker.
ExponentialWalker
(start=0, **params)¶ Bases:
er.model.walker.Walker
ExponentialWalker spends an exponential time in nodes.
This walker steps to a random neighbor in (random) exponential time.
-
step
(network: er.model.network.NetworkModel)¶ Move the walker of one step on the network.
-
-
class
er.model.walker.
RandomWalker
(start=0, **params)¶ Bases:
er.model.walker.Walker
RandomWalker is a standard random walker.
The random walker steps to a random neighboring node.
-
step
(network: er.model.network.NetworkModel)¶ Move the walker of one step on the network.
-
-
class
er.model.walker.
Walker
(start=0, **kwargs)¶ Bases:
object
Base graph walker.
-
abstract
step
(network: er.model.network.NetworkModel)¶ Move the walker of one step on the network.
-
abstract