Generator#

class pygod.generator.gen_contextual_outliers(data, n, k, random_state=None)[source]#

Generating contextual outliers according to paper “Deep Anomaly Detection on Attributed Networks” <https://epubs.siam.org/doi/abs/10.1137/1.9781611975673.67>. 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 deviate the most from node i among the k nodes by maximizing the Euclidean distance ||xi − xj ||2. Afterwards, we then change the attributes xi of node i to xj.

Parameters
  • data (PyTorch Geometric Data instance (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.

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

Returns

  • data (PyTorch Geometric Data instance (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 regular nodes.

class pygod.generator.gen_structural_outliers(data, m, n, p=0, random_state=None)[source]#

Generating structural outliers according to paper “Deep Anomaly Detection on Attributed Networks” <https://epubs.siam.org/doi/abs/10.1137/1.9781611975673.67>. 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 (PyTorch Geometric Data instance (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.

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

Returns

  • data (PyTorch Geometric Data instance (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 regular nodes.