Network Classes¶
The neet
module provides the following abstract network classes from
which all concrete Neet networks inherit:
Network |
The Network class is the core base class for all Neet networks. |
UniformNetwork |
The UnformNetwork class represents a network in which every node has the same number of discrete states. |

These classes provide an abstract interface which algorithms can leverage for generic implementation of various network-theoretic analyses.
Network¶
-
class
neet.
Network
(shape, names=None, metadata=None)[source]¶ The Network class is the core base class for all Neet networks. It provides an interface for describing network state updating and simple graph-theoretic analyses.
names
Get or set the names of the nodes of the network. metadata
Any metadata associated with the network. _unsafe_update
Unsafely update the state of a network in place. update
Update the state of a network in place. neighbors_in
Get a set of all incoming neighbors of the node at index
.neighbors_out
Get a set of all outgoing neighbors of the node at index
.neighbors
Get a set of the neighbors of the node at index
.network_graph
The graph of the network as a networkx.DiGraph
.draw_network_graph
Draw network’s networkx graph using PyGraphviz. Network is an abstract class, meaning it cannot be instantiated, and inherits from
neet.LandscapeMixin
andneet.StateSpace
. Initialization of the Network requires, at a minimum, a specification of the shape of the network’s state space, and optionally allows the user to specify a list of names for the nodes of the network and a metadata dictionary for the network as a whole (e.g. citation information).Any concrete deriving class must overload the following methods:
Parameters: -
metadata
¶ Any metadata associated with the network.
-
names
¶ Get or set the names of the nodes of the network.
Raises: - TypeError – if the assigned value is not convertable to a list
- ValueError – if the length fo the assigned values does not match the networks’s size
-
_unsafe_update
(state, index, pin, values, *args, **kwargs)[source]¶ Unsafely update the state of a network in place.
This function accepts three optional arguments by default:
index
- update only the specified node (by index)pin
- do not update the state of any node in a listvalues
- set the state of some subset of nodes to specified values
Note
As an abstract method, every concrete class derving from Network must overload this method. The overload should not perform no ensurance checks on the arguments to maximize performance, as those check are performed in the
update()
method. Further, it is assumed that this method modifies thestate
argument in-place and no others.Parameters: - state (list, numpy.ndarray) – the state of the network to update
- index (int or None) – the index to update
- pin (list, numpy.ndarray or None) – which nodes to pin to their current state
- values (dict or None) – a dictionary mapping nodes to a state to which to reset the node to
Returns: the updated state
-
neighbors_in
(index, *args, **kwargs)[source]¶ Get a set of all incoming neighbors of the node at
index
.All concrete network classes must overload this method.
Parameters: index (int) – the index of the node target node Returns: a set of incoming neighbor indices
-
neighbors_out
(index, *args, **kwargs)[source]¶ Get a set of all outgoing neighbors of the node at
index
.All concrete network classes must overload this method.
Parameters: index (int) – the index of the node source node Returns: a set of outgoing neighbor indices
-
update
(state, index=None, pin=None, values=None, *args, **kwargs)[source]¶ Update the state of a network in place.
This function accepts three optional arguments by default:
index
- update only the specified node (by index)pin
- do not update the state of any node in a listvalues
- set the state of some subset of nodes to specified values
Examples
Updates States In-Place:
>>> rule = ECA(30, size=5) >>> state = [0, 0, 1, 0, 0] >>> rule.update(state) [0, 1, 1, 1, 0] >>> state [0, 1, 1, 1, 0]
Updating A Single Node:
>>> rule = ECA(30, size=5) >>> rule.update([0, 0, 1, 0, 0]) [0, 1, 1, 1, 0] >>> rule.update([0, 0, 1, 0, 0], index=1) [0, 1, 1, 0, 0]
Pinning States:
>>> rule = ECA(30, size=5) >>> rule.update([0, 0, 1, 0, 0]) [0, 1, 1, 1, 0] >>> rule.update([0, 0, 1, 0, 0], pin=[1]) [0, 0, 1, 1, 0]
Overriding States:
>>> rule = ECA(30, size=5) >>> rule.update([0, 0, 1, 0, 0]) [0, 1, 1, 1, 0] >>> rule.update([0, 0, 1, 0, 0], values={0: 1, 2: 0}) [1, 1, 0, 1, 0]
This function ensures that:
- If
index
is provided, then neitherpin
norvalues
is provided. - If
pin
andvalues
are both provided, then they do not affect the same nodes. - If
values
is provided, then the overriding states specified in it are consistent with the state space of the network.
Note
Typically, this method should not be overloaded unless the particular deriving class makes use of the
args
orkwargs
arguments. In that case, it should first ensure that those arguments are well-behaved, and and the delegate subsequent checks and the call to_unsafe_update()
to a call to thisneet.Network.update()
.Parameters: - state (list or numpy.ndarray) – the state of the network to update
- index (int or None) – the index to update
- pin (list, numpy.ndarray or None) – which nodes to pin to their current state
- values (dict or None) – a dictionary mapping nodes to a state to which to reset the node to
Returns: the updated state
-
neighbors
(index, direction='both', *args, **kwargs)[source]¶ Get a set of the neighbors of the node at
index
. Optionally, specify the directionality of the neighboring edges, e.g.'in'
,'out'
or'both'
.Examples
All Neighbors:
>>> s_pombe.neighbors(7) {1, 5, 7, 8}
Incoming Neighbors:
>>> s_pombe.neighbors(7, direction='in') {8, 1, 7}
Outgoing Neighbors:
>>> s_pombe.neighbors(7, direction='out') {5, 7}
Parameters: Returns: a set of neighboring node indices, respecting
direction
.
-
network_graph
(labels='indices', **kwargs)[source]¶ The graph of the network as a
networkx.DiGraph
.This method should only be overloaded by derived classes if additional metadata is to be added to the graph by default.
Examples
>>> s_pombe.network_graph() <networkx.classes.digraph.DiGraph object at 0x...>
Parameters: - labels – label to be applied to graph nodes (either
'indices'
or'names'
) - kwargs – kwargs to pass to the
networkx.DiGraph
constructor
Returns: a
networkx.DiGraph
object- labels – label to be applied to graph nodes (either
-
draw_network_graph
(graphkwargs={}, pygraphkwargs={})[source]¶ Draw network’s networkx graph using PyGraphviz.
Note
This method requires Graphviz and pygraphviz. The former requires manual installation (see https://graphviz.gitlab.io/download/), while the latter can be installed via
pip
.Parameters: - graphkwargs – kwargs to pass to
network_graph()
- pygraphkwargs – kwargs to pass to
neet.draw.view_pygraphviz()
- graphkwargs – kwargs to pass to
-
UniformNetwork¶
-
class
neet.
UniformNetwork
(size, base, names=None, metadata=None)[source]¶ The UnformNetwork class represents a network in which every node has the same number of discrete states. This allows for more efficient default implementations of several methods. If your particular concrete network type meets this condition, then you should derive from UniformNetwork rather than Network.
In addition to the methods provided by
Network
, UniformNetwork also provides the following attribute:base
Get the number of states each node can take. UniformNetwork derives from
Network
, but is still abstract, meaning it cannot be instantiated. Initialization of theUniformNetwork
requires, at a minimum, the number of nodes in the network (size
) and the number of states the nodes can take (base
). As withNetwork
, the user can optionally specify a list of names for the nodes of the network and a metadata dictionary for the network as a whole (e.g. citation information).Any concrete deriving class must overload the following methods:
_unsafe_update()
neighbors_in()
neighbors_out()
Parameters: -
base
¶ Get the number of states each node can take.
Examples
>>> ECA(30, size=5).base 2
Returns: the base of nodes of the network