Graphs
Contents
Graphs#
Theory#
A graph
The adjacency matrix contains the weights
The state vector contains the states
The neighborhood
We can also define the n-th neighborhood
Examples#
The Graph
class can be instantiated with two inputs: an adjacency matrix and a state vector both in the form of nested arrays.
import gra
graph = gra.Graph([ # adjacency matrix
[0, 1, 1, 1],
[1, 0, 1, 1],
[1, 1, 0, 1],
[1, 1, 1, 0]
],[ # state vector
[1],
[0],
[0],
[0]
])
Graph objects have three atributes:
adjacency_matrix
( an instance of the SparseTensor class of TensorFlow )state_vector
( an instance of the Tensor class of TensorFlow )dtype
( a numpy data type object: np.int32 or np.float32 )
and eight methods:
.plot()
: plots the graph.evolve(rule)
: evolves the graph according therule
.order()
: returns the order of the graph.diameter()
: returns the diameter of the graph.clone()
: returns a copy of the graph, this allows to use rules without modifying the original graph.to_igraph()
: returns an igraph object.to_networkx()
: returns a networkx object.to_mathematica()
: returns a string corresponding to a Mathematica compatible version of the graph
In the case of binary graphs
“alive” vertices
are colored purple,“dead” vertices
are colored orange.
graph.plot()
Graphs with a different ordering of vertices are equivalent. This equivalence can be checked with ==
.
graph == gra.Graph([ # adjacency matrix
[0, 1, 1, 1],
[1, 0, 1, 1],
[1, 1, 0, 1],
[1, 1, 1, 0]
],[ # state vector
[0],
[0],
[1],
[0]
])
True