The graph data structure¶
Classes for creating graph objects compatible with hcga.
Graphs can be constructed in various formats in Python, from Networkx Graph objects to numpy matrices. To provide a consistent and reliable format for hcga we have constructed a Graph class and a GraphCollection class.
When loading graphs into hcga, the Graph classes will attempt to convert the input graph type into a generic hcga Graph object.
-
class
hcga.graph.
Graph
(nodes, edges, label, graph_type=None, label_name=None)[source]¶ Class to encode a generic graph structure for hcga.
A graph can be attributed nodes, edges, a graph label and node features.
Defining the main graphs quantities.
- Parameters
nodes (DataFrame) – node dataframe, index as node id, and optional label and attributes columns (with lists elements)
edges (DataFrame) – edge dataframe, with two columns ‘start_node’ and ‘end_node’ with id corresponding to indices in nodes. And a third optional column ‘weight’ which if absent all edges will default to weight 1.
label (int) – label of the graph, it has to be an integer
graph_type (str) – set to ‘directed’ for directed graphs
label_name (any) – name or other information on the graph label
-
class
hcga.graph.
GraphCollection
[source]¶ A collection of Graph objects (see Graph class).
Initialise an empty list of graphs.
-
add_graph
(graph, node_features=None, label=None, graph_type=None)[source]¶ Add a graph to the list.
- Parameters
graph (graph-like object) – valid data representig graph (see convert_graph)
node_feature (array) – node feature matrix
label (int) – label of the graph
graph_type (str) – set to ‘directed’ for directed graphs
-
add_graph_list
(graph_list, node_features_list=None, graph_labels=None, graph_type=None)[source]¶ Add a list of graphs.
- Parameters
graph_list (list(graph-like object)) – valid data representig graphs (see convert_graph)
node_feature_list (list(array)) – node feature matrices
graph_labels (list(int)) – label of the graphs
graph_type (str) – set to ‘directed’ for directed graphs
-
-
hcga.graph.
convert_graph
(graph, node_features=None, label=None, graph_type=None)[source]¶ Function to convert different graph types to the class Graph.
- Parameters
graph (graph like object) – valid graph data (NetowrkX or np.ndarray)
label (int) – label of the graph
graph_type (str) – set to ‘directed’ for directed graphs
- Returns
converted Graph object
- Return type
(Graph)