graph_datasets.utils package

Submodules

graph_datasets.utils.common module

Common utils.

graph_datasets.utils.common.format_value(value) Any[source]

Return number as string with comma split.

Parameters:

value (int) – number.

Returns:

string of the number with comma split.

Return type:

str

graph_datasets.utils.common.tab_printer(args: Dict, thead: List[str] | None = None, cols_align: List[str] | None = None, cols_valign: List[str] | None = None, cols_dtype: List[str] | None = None, sort: bool = True) None[source]

Function to print the logs in a nice tabular format.

Parameters:
  • args (Dict) – value dict.

  • thead (List[str], optional) – table head. Defaults to None.

  • cols_align (List[str], optional) – horizontal alignment of the columns. Defaults to None.

  • cols_valign (List[str], optional) – vertical alignment of the columns. Defaults to None.

  • cols_dtype (List[str], optional) – value types of the columns. Defaults to None.

  • sort (bool, optional) – whether to sort the keys. Defaults to True.

Returns:

table string to print.

Return type:

str

graph_datasets.utils.common.download_tip(info: Dict) None[source]

Tips for Downloading datasets

Parameters:
  • data_file (str) – filepath.

  • url (str) – url for downloading.

graph_datasets.utils.common.print_dataset_info(dataset_name: str, n_nodes: int, n_edges: int, n_feats: int, n_clusters: int, self_loops: int | None = None, is_directed: bool | None = None, thead: List[str] | None = None) None[source]
graph_datasets.utils.common.bar_progress(current, total, _)[source]

create this bar_progress method which is invoked automatically from wget

graph_datasets.utils.common.download_from_google_drive(gid: str, output: str, quiet: bool = False, file_name: str | None = None) None[source]

Download data from google drive.

Parameters:
  • id (str) – Id for google drive url.

  • output (str) – Path to save data.

  • quiet (bool) – Suppress terminal output. Default is False.

  • file_name (str) – File name. Default to None.

graph_datasets.utils.statistics module

Graph information statistics.

graph_datasets.utils.statistics.node_homo(adj: spmatrix, labels: Tensor) float[source]

Calculate node homophily.

Parameters:
  • adj (sp.spmatrix) – adjacent matrix.

  • labels (torch.Tensor) – labels.

Returns:

node homophily.

Return type:

float

graph_datasets.utils.statistics.edge_homo(adj: spmatrix, labels: Tensor) float[source]

Calculate edge homophily.

Parameters:
  • adj (sp.spmatrix) – adjacent matrix.

  • labels (torch.Tensor) – labels.

Returns:

edge homophily.

Return type:

float

graph_datasets.utils.statistics.get_long_edges(graph)[source]

Internal function for getting the edges of a graph as long tensors.

graph_datasets.utils.statistics.get_same_class_deg(graph, labels)[source]
graph_datasets.utils.statistics.statistics(graph: DGLGraph, labels: Tensor, dataset_name: str = '', h_1=True, h_2=True) dict[source]

Calculate homophily metrics of graphs.

Parameters:
  • graph (dgl.DGLGraph) – Graph

  • labels (torch.Tensor) – Labels

  • dataset_name (str, optional) – Dataset name. Defaults to ‘’.

  • h_1 (bool, optional) – 1-hop graph metrics. Defaults to True.

  • h_2 (bool, optional) – 2-hop graph metrics. Defaults to True.

Raises:

MemoryError – OOM.

Returns:

Dict of metric results.

Return type:

dict

Module contents

Utils