class pygod.nn.DMGDBase(in_dim, hid_dim=64, num_layers=2, dropout=0.0, act=<function relu>, backbone=<class 'torch_geometric.nn.models.mlp.MLP'>, alpha=1, beta=1, gamma=1, warmup=2, k=2, **kwargs)[source]

Bases: Module

Deep Multiclass Graph Description

DMGD is a support vector based multiclass outlier detector. Its backbone is an autoencoder that reconstructs the adjacency matrix of the graph with MSE loss and homophily loss. It applies k-means to cluster the nodes embedding and then uses support vector to detect outliers.

See [BVVM20] for details.

  • in_dim (int) – Input dimension.

  • hid_dim (int, optional) – Hidden dimension of model. Default: 64.

  • num_layers (int, optional) – Total number of layers in model. A half (floor) of the layers are for the encoder, the other half (ceil) of the layers are for decoders. Default: 4.

  • dropout (float, optional) – Dropout rate. Default: 0..

  • weight_decay (float, optional) – Weight decay (L2 penalty). Default: 0..

  • act (callable activation function or None, optional) – Activation function if not None. Default: torch.nn.functional.relu.

  • backbone (torch.nn.Module, optional) – The backbone of the deep detector implemented in PyG. Default: torch_geometric.nn.MLP.

  • alpha (float, optional) – Weight of the radius loss. Default: 1.

  • beta (float, optional) – Weight of the reconstruction loss. Default: 1.

  • gamma (float, optional) – Weight of the homophily loss. Default: 1.

  • k (int, optional) – The number of clusters. Default: 2.

  • **kwargs – Other parameters for the backbone.

forward(x, edge_index)[source]

Forward computation.


  • x_ (torch.Tensor) – Reconstructed attribute embeddings.

  • nd (torch.Tensor) – Neighbor distance.

loss_func(x, x_, nd, emb)[source]

Loss function for DMGD.


loss – Loss value.

Return type:


static process_graph(data)[source]

Obtain the dense adjacency matrix of the graph.


data ( – Input graph.