pygod.generator

pygod.generator.gen_contextual_outlier(data, n, k, seed=None)[source]

Generating contextual outliers according to paper [DLBL19]. We randomly select n nodes as the attribute perturbation candidates. For each selected node \(i\), we randomly pick another k nodes from the data and select the node \(j\) whose attributes \(x_j\) deviate the most from node \(i\)’s attribute \(x_i\) among k nodes by maximizing the Euclidean distance \(\| x_i − x_j \|\). Afterwards, we then substitute the attributes \(x_i\) of node \(i\) to \(x_j\).

Parameters:
  • data (torch_geometric.data.Data) – The input data.

  • n (int) – Number of nodes converting to outliers.

  • k (int) – Number of candidate nodes for each outlier node.

  • seed (int, optional) – The seed to control the randomness, Default: None.

Returns:

  • data (torch_geometric.data.Data) – The contextual outlier graph with modified node attributes.

  • y_outlier (torch.Tensor) – The outlier label tensor where 1 represents outliers and 0 represents normal nodes.

pygod.generator.gen_structural_outlier(data, m, n, p=0, directed=False, seed=None)[source]

Generating structural outliers according to paper : cite:ding2019deep. We randomly select m nodes from the network and then make those nodes fully connected, and then all the m nodes in the clique are regarded as outliers. We iteratively repeat this process until a number of n cliques are generated and the total number of structural outliers is m * n.

Parameters:
  • data (torch_geometric.data.Data) – The input data.

  • m (int) – Number nodes in the outlier cliques.

  • n (int) – Number of outlier cliques.

  • p (int, optional) – Probability of edge drop in cliques. Default: 0.

  • directed (bool, optional) – Whether the edges added are directed. Default: False.

  • seed (int, optional) – The seed to control the randomness, Default: None.

Returns:

  • data (torch_geometric.data.Data) – The structural outlier graph with injected edges.

  • y_outlier (torch.Tensor) – The outlier label tensor where 1 represents outliers and 0 represents normal nodes.