pygod.utils

Data Loading

class pygod.utils.load_data(name, cache_dir=None)[source]

Data loading function. See data repository for supported datasets. For injected/generated datasets, the labels meanings are as follows.

  • 0: inlier

  • 1: contextual outlier only

  • 2: structural outlier only

  • 3: both contextual outlier and structural outlier

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

  • cache_dir (str, optional) – The directory for dataset caching. Default: None.

Returns:

data – The outlier dataset.

Return type:

torch_geometric.data.Data

Examples

>>> from pygod.utils import load_data
>>> data = load_data(name='weibo') # in PyG format
>>> y = data.y.bool()    # binary labels (inlier/outlier)
>>> yc = data.y >> 0 & 1 # contextual outliers
>>> ys = data.y >> 1 & 1 # structural outliers

Score Conversion

pygod.utils.to_edge_score(score, edge_index)[source]

Convert outlier node score to outlier edge score by averaging the scores of two nodes connected by an edge.

Parameters:
  • score (torch.Tensor) – The node score.

  • edge_index (torch.Tensor) – The edge index.

Returns:

score – The edge score.

Return type:

torch.Tensor

pygod.utils.to_graph_score(score)[source]

Convert outlier node score to outlier graph score by averaging the scores of all nodes in a graph.

Parameters:

score (torch.Tensor) – The node score.

Returns:

score – The graph score.

Return type:

torch.Tensor