![]() |
STAG Python
1.2.1
Spectral Toolkit of Algorithms for Graphs
|
The core object used to represent graphs for use with the library.
Graphs are always constructed from sparse matrices, and this is the internal representation used as well. Vertices of the graph are always referred to by their unique integer index. This index corresponds to the position of the vertex in the stored adjacency matrix of the graph.
Public Member Functions | |
def | __init__ (self, scipy.sparse.spmatrix adj_mat, stag_internal.Graph internal_graph=None) |
Initialise the graph with an adjacency matrix. | |
scipy.sparse.csc_matrix | adjacency (self) |
Return the sparse adjacency matrix of the graph. | |
scipy.sparse.csc_matrix | laplacian (self) |
Construct the Laplacian matrix of the graph. | |
scipy.sparse.csc_matrix | normalised_laplacian (self) |
Construct the normalised Laplacian matrix of the graph. | |
scipy.sparse.csc_matrix | normalised_laplacian (self) |
Construct the normalised Laplacian matrix of the graph. | |
scipy.sparse.csc_matrix | signless_laplacian (self) |
Construct the signless Laplacian matrix of the graph. | |
scipy.sparse.csc_matrix | normalised_signless_laplacian (self) |
Construct the normalised signless Laplacian matrix of the graph. | |
scipy.sparse.csc_matrix | degree_matrix (self) |
The degree matrix of the graph. | |
scipy.sparse.csc_matrix | inverse_degree_matrix (self) |
The inverse degree matrix of the graph. | |
scipy.sparse.csc_matrix | lazy_random_walk_matrix (self) |
The lazy random walk matrix of the graph. | |
float | total_volume (self) |
The volume of the graph. | |
float | average_degree (self) |
The average degree of the graph. | |
int | number_of_vertices (self) |
The number of vertices in the graph. | |
int | number_of_edges (self) |
The number of edges in the graph. | |
float | degree (self, int v) |
Given a vertex v, return its weighted degree. | |
int | degree_unweighted (self, int v) |
Given a vertex v, return its unweighted degree. | |
List[Edge] | neighbors (self, int v) |
Given a vertex v, return a list of edges representing the neighbors of v. | |
List[int] | neighbors_unweighted (self, int v) |
Given a vertex v, return a list of neighbors of v. | |
bool | vertex_exists (self, int v) |
Given a vertex ID, returns true or false to indicate whether the vertex exists in the graph. | |
networkx.Graph | to_networkx (self) |
Construct a networkx graph object which is equivalent to this STAG graph. | |
def | draw (self, **kwargs) |
Plot the graph with matplotlib. | |
![]() | |
def | __init__ (self) |
Default LocalGraph constructor. | |
float | degree (self, int v) |
Given a vertex v, return its weighted degree. | |
int | degree_unweighted (self, int v) |
Given a vertex v, return its unweighted degree. | |
List[Edge] | neighbors (self, int v) |
Given a vertex v, return a list of edges representing the neighbors of v. | |
List[int] | neighbors_unweighted (self, int v) |
Given a vertex v, return a list of neighbors of v. | |
List[float] | degrees (self, List[int] vertices) |
Given a list of vertices, return a list of their weighted degrees. | |
List[int] | degrees_unweighted (self, List[int] vertices) |
Given a list of vertices, return a list of their unweighted degrees. | |
bool | vertex_exists (self, int v) |
Given a vertex ID, returns true or false to indicate whether the vertex exists in the graph. | |
def stag.graph.Graph.__init__ | ( | self, | |
scipy.sparse.spmatrix | adj_mat, | ||
stag_internal.Graph | internal_graph = None |
||
) |
Initialise the graph with an adjacency matrix.
For example:
adj_mat | A sparse scipy matrix, such as scipy.sparse.csc_matrix . |
internal_graph | (optional) specify a STAG C++ graph object to initialise with. Use this only if you understand the internal workings of the STAG library. |
Reimplemented from stag.graph.LocalGraph.
scipy.sparse.csc_matrix stag.graph.Graph.adjacency | ( | self | ) |
Return the sparse adjacency matrix of the graph.
scipy.sparse.csc_matrix
representing the graph adjacency matrix scipy.sparse.csc_matrix stag.graph.Graph.laplacian | ( | self | ) |
Construct the Laplacian matrix of the graph.
The Laplacian matrix is defined by
\[ L = D - A \]
where \(D\) is the diagonal matrix of vertex degrees and \(A\) is the adjacency matrix of the graph.
scipy.sparse.csc_matrix
representing the graph Laplacian scipy.sparse.csc_matrix stag.graph.Graph.normalised_laplacian | ( | self | ) |
Construct the normalised Laplacian matrix of the graph.
The normalised Laplacian matrix is defined by
\[ \mathcal{L} = D^{-1/2} L D^{-1/2} \]
where \(D\) is the diagonal matrix of vertex degrees and \(L\) is the Laplacian matrix of the graph.
scipy.sparse.csc_matrix
representing the normalised Laplacian scipy.sparse.csc_matrix stag.graph.Graph.normalised_laplacian | ( | self | ) |
Construct the normalised Laplacian matrix of the graph.
The normalised Laplacian matrix is defined by
\[ \mathcal{L} = D^{-1/2} L D^{-1/2} \]
where \(D\) is the diagonal matrix of vertex degrees and \(L\) is the Laplacian matrix of the graph.
scipy.sparse.csc_matrix
representing the normalised Laplacian scipy.sparse.csc_matrix stag.graph.Graph.signless_laplacian | ( | self | ) |
Construct the signless Laplacian matrix of the graph.
The signless Laplacian matrix is defined by
\[ J = D + A \]
where \(D\) is the diagonal matrix of vertex degrees and \(A\) is the adjacency matrix of the graph.
scipy.sparse.csc_matrix
representing the signless graph Laplacian scipy.sparse.csc_matrix stag.graph.Graph.normalised_signless_laplacian | ( | self | ) |
Construct the normalised signless Laplacian matrix of the graph.
The normalised signless Laplacian matrix is defined by
\[ \mathcal{J} = D^{-1/2} J D^{-1/2} \]
where \(D\) is the diagonal matrix of vertex degrees and \(J\) is the signless Laplacian matrix of the graph.
scipy.sparse.csc_matrix
representing the normalised signless Laplacian scipy.sparse.csc_matrix stag.graph.Graph.degree_matrix | ( | self | ) |
The degree matrix of the graph.
The degree matrix \(D \in \mathbb{R}^{n \\times n}\) is a diagonal matrix such that \(D(i, i) = \mathrm{deg}(i)\) where \(\mathrm{deg}(i)\) is the degree of vertex \(i\) and \(n\) is the number of vertices in the graph.
scipy.sparse.csc_matrix
representing the degree matrix scipy.sparse.csc_matrix stag.graph.Graph.inverse_degree_matrix | ( | self | ) |
The inverse degree matrix of the graph.
The degree matrix \(D^{-1} \in \mathbb{R}^{n \times n}\) is a diagonal matrix such that
\[ D(i, i) = \left\{ \begin{array}{lll} \mathrm{deg}(i) & \mbox{if } \mathrm{deg}(i) > 0 \\ 0 & \mbox{otherwise} \end{array} \right. \]
where \(\mathrm{deg}(i)\) is the degree of vertex \(i\) and \(n\) is the number of vertices in the graph.
scipy.sparse.csc_matrix
representing the inverse degree matrix scipy.sparse.csc_matrix stag.graph.Graph.lazy_random_walk_matrix | ( | self | ) |
The lazy random walk matrix of the graph.
The lazy random walk matrix is defined by
\[ W = \frac 1 2 I + \frac 1 2 A D^{-1} \]
where \(I\) is the identity matrix, \(A\) is the graph adjacency matrix and \(D\) is the degree matrix of the graph.
scipy.sparse.csc_matrix
representing the lazy random walk matrix float stag.graph.Graph.total_volume | ( | self | ) |
The volume of the graph.
The volume of a graph \(G = (V, E, w)\) is defined by
\[ \mathrm{vol}(G) = \sum_{u \in V} \mathrm{deg}(u), \]
where \(\mathrm{deg}(u)\) is the degree of vertex \(u\).
float stag.graph.Graph.average_degree | ( | self | ) |
The average degree of the graph.
This is defined as the sum of the node degrees divided by the number of nodes.
int stag.graph.Graph.number_of_vertices | ( | self | ) |
The number of vertices in the graph.
int stag.graph.Graph.number_of_edges | ( | self | ) |
The number of edges in the graph.
This method ignores the weights of the edges.
float stag.graph.Graph.degree | ( | self, | |
int | v | ||
) |
Given a vertex v, return its weighted degree.
Reimplemented from stag.graph.LocalGraph.
int stag.graph.Graph.degree_unweighted | ( | self, | |
int | v | ||
) |
Given a vertex v, return its unweighted degree.
That is, the number of neighbors of v, ignoring the edge weights.
Reimplemented from stag.graph.LocalGraph.
List[Edge] stag.graph.Graph.neighbors | ( | self, | |
int | v | ||
) |
Given a vertex v, return a list of edges representing the neighbors of v.
The returned edge objects will all have the ordering (v1, v2)
such that edge.v1 = v
.
v | the ID of some vertex in the graph |
Reimplemented from stag.graph.LocalGraph.
List[int] stag.graph.Graph.neighbors_unweighted | ( | self, | |
int | v | ||
) |
Given a vertex v, return a list of neighbors of v.
The weights of edges to the neighbors are not returned by this method.
v | the ID of some vertex in the graph |
Reimplemented from stag.graph.LocalGraph.
bool stag.graph.Graph.vertex_exists | ( | self, | |
int | v | ||
) |
Given a vertex ID, returns true or false to indicate whether the vertex exists in the graph.
v | the vertex index to check |
Reimplemented from stag.graph.LocalGraph.
networkx.Graph stag.graph.Graph.to_networkx | ( | self | ) |
Construct a networkx graph object which is equivalent to this STAG graph.
See the networkx documentation.
def stag.graph.Graph.draw | ( | self, | |
** | kwargs | ||
) |
Plot the graph with matplotlib.
This uses the networkx draw method and accepts any the keyword arguments will be passed through directly.