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

_check_length()[source]

Verify if the graph is large enough to be considered.

get_graph(encoding=None)[source]

Get usable graph structure with given encoding.

For now, only networkx is implemented.

maximal_subgraph()[source]

Overwrite the graph with its maximal subgraph.

remove_weights()[source]

Set edge weights to one.

set_networkx()[source]

Set the networkx graph encoding.

set_node_features()[source]

Set the node features and get the dimension of features.

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

get_graph_ids()[source]

Get the list of active graph ids.

get_n_node_features()[source]

Get the number of features of the nodes.

get_num_disabled_graphs()[source]

Get the number of disabled graphs.

maximal_subgraphs()[source]

Overwrites each graph with its maximal subgraph.

remove_edge_weights()[source]

Remove edge weights.

remove_node_features()[source]

Remove the node features.

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)