grakel.Graph¶
- class grakel.Graph(initialization_object=None, node_labels=None, edge_labels=None, graph_format='auto', construct_labels=False)[source][source]¶
The general graph class.
A general graph class that supports adjacency, dictionary formats while beeing memory/computationaly sustainable.
- Parameters
- initialization_objectdict, list or array-like, square, default=None
The initialisation object for the graph (valid-graph-format).
If given a dictionary the input can be as follows:
2-level nested dictionaries from edge symbols to weights
Dictionary of symbols to list of symbols (unweighted)
Dictionary of tuples to weights (weighted)
Iterable of tuples of len 2 (unweighted)
Iterable of tuples of len 3 (vertex, vertex, weight)
If given an array the input can be as follows:
array-like lists of lists
np.array
sparse matrix (scipy.sparse)
- node_labelsdict, default=None
A label dictionary corresponding to all vertices of the graph:
for adjacency matrix labels should be given to numbers starting from 0 and ending in N-1, where the matrix has size N by N
for dictionary labels should correspond to all keys
- edge_labelsdict, default=None
A labels dictionary corresponding to all edges of the graph with keys: index/symbol-tuples and value: labels.
- graph_formatstr, valid_values={“dictionary”, “adjacency”, “all”, “auto”}, default=None
Defines the internal representation of the graph object which can be a dictionary as a matrix, or both:
for dictionary: “dictionary”
for adjacency_matrix: “adjacency”
for both: “all”
for the current_format (if existent): “auto”
- Attributes
- nint
The one dimension of the (square) adjacency matrix. Signifies the number of vertices.
- adjacency_matrixnp.array
The adjacency_matrix corresponding to the graph.
- index_node_labelsdict
Label dictionary for indeces, of adjacency matrix. Keys are valid numbers from 0 to n-1.
- index_edge_labelsdict
Label dictionary for edges, of adjacency matrix. Keys are tuple pairs of symbols with valid numbers from 0 to n-1, that have a positive adjacency matrix value.
- verticesset
The set of vertices corresponding to the edge_dictionary representation.
- edge_dictionarydict
A 2-level nested dictionary from edge symbols to weights.
- node_labelsdict
Label dictionary for nodes. Keys are vertex symbols inside vertices.
- edge_labelsdict
Label dictionary for edges. Keys are tuple pairs of symbols inside vertices and edges.
- edsamicdict
Edge-Dictionary-Symbols-Adjacency-Matrix-Index-Correspondance. A dictionary which translates dictionary symbols to adjacency matrix indexes, when storing both formats.
- shortest_path_matnp.array, square
Holds the shortest path matrix.
- label_groupdict
A 2-level nested dict that after the first level of a pair tuple for purpose: “adjacency”, “dictionary” and “vertex”,”edge” specification holds the inverse map of labels.
- laplacian_graphnp.array
Holds the graph laplacian.
- _formatstr, valid_values={“adjacency”, “dictionary”, “all”}
Private attribute that keeps the current format.
Methods
build_graph
(g[, node_labels, edge_labels])Build a graph structure, given a supported graph representation.
build_shortest_path_matrix
([algorithm_type, …])Build and return the shortest path matrix between all nodes.
change_format
(graph_format)Change the format of the graph from an existing to an other.
construct_labels
([label_type, purpose])Construct labels (if user does not provide).
convert_labels
([target_format, purpose, init])Convert labels to a desired format.
desired_format
(graph_format[, warn])Change the graph format, to include the desired.
get_adjacency_matrix
()Get the adjacency matrix.
get_edge_dictionary
()Get the edge dictionary.
get_edges
([purpose, with_weights])Create an iterable of edges as tuples.
get_graph_object
()Return the graph object corresponding to ‘any’.
get_label_group
([label_type, purpose])Calculate the inverse dictionary for vertex labels (once).
get_labels
([label_type, purpose, return_none])Get labels corresponding to the purpose.
get_subgraph
(vertices)Calculate the subgraph of object in the same format as the original.
get_vertices
([purpose])Create an iterable of vertices.
label
(obj[, label_type, purpose])Get the label of a vertex.
laplacian
([save])Calculate the laplacian of the given graph.
neighbors
(vertex[, purpose, with_weights])Find all neighbors of a vertex.
nv
()Get the number of vertices for any existing format.
produce_neighborhoods
([r, purpose, …])Calculate neighborhoods for each node of a Graph, up to a depth.
relabel
(new_labels[, purpose, label_type])Relabel the graph object, supporting the current format.
__init__ function of the graph object.
- Attributes
- laplacian_graph
- shortest_path_mat
Methods
build_graph
(g[, node_labels, edge_labels])Build a graph structure, given a supported graph representation.
build_shortest_path_matrix
([algorithm_type, …])Build and return the shortest path matrix between all nodes.
change_format
(graph_format)Change the format of the graph from an existing to an other.
construct_labels
([label_type, purpose])Construct labels (if user does not provide).
convert_labels
([target_format, purpose, init])Convert labels to a desired format.
desired_format
(graph_format[, warn])Change the graph format, to include the desired.
get_adjacency_matrix
()Get the adjacency matrix.
get_edge_dictionary
()Get the edge dictionary.
get_edges
([purpose, with_weights])Create an iterable of edges as tuples.
get_graph_object
()Return the graph object corresponding to ‘any’.
get_label_group
([label_type, purpose])Calculate the inverse dictionary for vertex labels (once).
get_labels
([label_type, purpose, return_none])Get labels corresponding to the purpose.
get_subgraph
(vertices)Calculate the subgraph of object in the same format as the original.
get_vertices
([purpose])Create an iterable of vertices.
label
(obj[, label_type, purpose])Get the label of a vertex.
laplacian
([save])Calculate the laplacian of the given graph.
neighbors
(vertex[, purpose, with_weights])Find all neighbors of a vertex.
nv
()Get the number of vertices for any existing format.
produce_neighborhoods
([r, purpose, …])Calculate neighborhoods for each node of a Graph, up to a depth.
relabel
(new_labels[, purpose, label_type])Relabel the graph object, supporting the current format.
- __init__(initialization_object=None, node_labels=None, edge_labels=None, graph_format='auto', construct_labels=False)[source][source]¶
__init__ function of the graph object.
Methods
__init__
([initialization_object, …])__init__ function of the graph object.
build_graph
(g[, node_labels, edge_labels])Build a graph structure, given a supported graph representation.
build_shortest_path_matrix
([algorithm_type, …])Build and return the shortest path matrix between all nodes.
change_format
(graph_format)Change the format of the graph from an existing to an other.
construct_labels
([label_type, purpose])Construct labels (if user does not provide).
convert_labels
([target_format, purpose, init])Convert labels to a desired format.
desired_format
(graph_format[, warn])Change the graph format, to include the desired.
get_adjacency_matrix
()Get the adjacency matrix.
get_edge_dictionary
()Get the edge dictionary.
get_edges
([purpose, with_weights])Create an iterable of edges as tuples.
get_graph_object
()Return the graph object corresponding to ‘any’.
get_label_group
([label_type, purpose])Calculate the inverse dictionary for vertex labels (once).
get_labels
([label_type, purpose, return_none])Get labels corresponding to the purpose.
get_subgraph
(vertices)Calculate the subgraph of object in the same format as the original.
get_vertices
([purpose])Create an iterable of vertices.
label
(obj[, label_type, purpose])Get the label of a vertex.
laplacian
([save])Calculate the laplacian of the given graph.
neighbors
(vertex[, purpose, with_weights])Find all neighbors of a vertex.
nv
()Get the number of vertices for any existing format.
produce_neighborhoods
([r, purpose, …])Calculate neighborhoods for each node of a Graph, up to a depth.
relabel
(new_labels[, purpose, label_type])Relabel the graph object, supporting the current format.
Attributes
adjacency_matrix
edge_dictionary
edge_labels
edsamic
index_edge_labels
index_node_labels
label_group
laplacian_graph
n
node_labels
shortest_path_mat
vertices