Utility Functions for Graph Classification

fedgraph.utils_gc.convert_to_node_attributes(graphs: Any) list[source]

Use only the node attributes of the graphs. This function will treat the graphs as callable objects.

Parameters:

graphs (Any) – The object of of graphs

Returns:

new_graphs – List of graphs with only the node attributes

Return type:

list

fedgraph.utils_gc.convert_to_node_degree_features(graphs: list) list[source]

Convert the node attributes of the graphs to node degree features.

Parameters:

graphs (list) – List of graphs

Returns:

new_graphs – List of graphs with node degree features

Return type:

list

fedgraph.utils_gc.decryption_he(context, template_model_params, enc_model_params)[source]
fedgraph.utils_gc.encryption_he(context, model_params, total_client_number)[source]
fedgraph.utils_gc.fedavg_he(context, list_enc_model_params)[source]
fedgraph.utils_gc.generate_context(poly_modulus_degree=8192, coeff_mod_bit_sizes=[60, 40, 40, 60])[source]
fedgraph.utils_gc.get_avg_nodes_edges(graphs: list) tuple[source]

Calculate the average number of nodes and edges in the dataset.

Parameters:

graphs (list) – List of graphs

Returns:

  • avg_nodes (float) – The average number of nodes in the dataset

  • avg_edges (float) – The average number of edges in the dataset

fedgraph.utils_gc.get_max_degree(graphs: Any) int[source]

Get the maximum degree of the graphs in the dataset.

Parameters:

graphs (Any) – The object of graphs

Returns:

max_degree – The maximum degree of the graphs in the dataset

Return type:

int

fedgraph.utils_gc.get_num_graph_labels(dataset: list) int[source]

Get the number of unique graph labels in the dataset.

Parameters:

dataset (list) – List of graphs

Returns:

(labels.length) – Number of unique graph labels in the dataset

Return type:

int

fedgraph.utils_gc.get_stats(df: DataFrame, dataset: str, graphs_train: list = [], graphs_val: list = [], graphs_test: list = []) DataFrame[source]

Calculate and store the statistics of the dataset, including the number of graphs, average number of nodes and edges for the training, validation, and testing sets.

Parameters:
  • df (pd.DataFrame) – An empty DataFrame to store the statistics of the dataset.

  • dataset (str) – The name of the dataset.

  • graphs_train (list) – List of training graphs.

  • graphs_val (list) – List of validation graphs.

  • graphs_test (list) – List of testing graphs.

Returns:

df – The filled statistics of the dataset.

Return type:

pd.DataFrame

fedgraph.utils_gc.setup_server(base_model: Any, args: Namespace) Server_GC[source]

Setup server.

Parameters:
  • base_model (Any) – The base model for the server. The base model shown in the example is GIN_server.

  • args (argparse.ArgumentParser) – The input arguments

Returns:

server – The server object

Return type:

Server_GC

fedgraph.utils_gc.setup_trainers(splited_data: dict, base_model: Any, args: Namespace) tuple[source]

Setup trainers for graph classification.

Parameters:
  • splited_data (dict) – The data for each trainer.

  • base_model (Any) – The base model for the trainer. The base model shown in the example is GIN.

  • args (argparse.ArgumentParser) – The input arguments.

Returns:

(trainers, idx_trainers) – trainers: List of trainers idx_trainers: Dictionary with the index of the trainer as the key and the dataset name as the value

Return type:

tuple(list, dict)

fedgraph.utils_gc.split_data(graphs: list, train_size: float = 0.8, test_size: float = 0.2, shuffle: bool = True, seed: int = 42) tuple[source]

Split the dataset into training and test sets.

Parameters:
  • graphs (list) – List of graphs

  • train_size (float) – The proportion (ranging from 0.0 to 1.0) of the dataset to include in the training set

  • test_size (float) – The proportion (ranging from 0.0 to 1.0) of the dataset to include in the test set

  • shuffle (bool) – Whether or not to shuffle the data before splitting

  • seed (int) – Seed for the random number generator

Returns:

  • graphs_train (list) – List of training graphs

  • graphs_test (list) – List of testing graphs

Note

The function uses sklearn.model_selection.train_test_split to split the dataset into training and test sets. If the dataset needs to be split into training, validation, and test sets, the function should be called twice.