DONEBase

class pygod.nn.DONEBase(x_dim, s_dim, hid_dim=64, num_layers=4, dropout=0.0, act=<function relu>, w1=0.2, w2=0.2, w3=0.2, w4=0.2, w5=0.2, **kwargs)[source]

Bases: Module

Deep Outlier Aware Attributed Network Embedding

DONE consists of an attribute autoencoder and a structure autoencoder. It estimates five losses to optimize the model, including an attribute proximity loss, an attribute homophily loss, a structure proximity loss, a structure homophily loss, and a combination loss. It calculates three outlier scores, and averages them as an overall scores. This model is transductive only.

See [BVM20] for details.

Parameters:
  • x_dim (int) – Input dimension of attribute.

  • s_dim (int) – Input dimension of structure.

  • 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.

  • w1 (float, optional) – Weight of structure proximity loss. Default: 0.2.

  • w2 (float, optional) – Weight of structure homophily loss. Default: 0.2.

  • w3 (float, optional) – Weight of attribute proximity loss. Default: 0.2.

  • w4 (float, optional) – Weight of attribute homophily loss. Default: 0.2.

  • w5 (float, optional) – Weight of combination loss. Default: 0.2.

  • **kwargs – Other parameters for the backbone.

forward(x, s, edge_index)[source]

Forward computation.

Parameters:
  • x (torch.Tensor) – Input attribute embeddings.

  • s (torch.Tensor) – Input structure embeddings.

  • edge_index (torch.Tensor) – Edge index.

Returns:

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

  • s_ (torch.Tensor) – Reconstructed structure embeddings.

  • h_a (torch.Tensor) – Attribute hidden embeddings.

  • h_s (torch.Tensor) – Structure hidden embeddings.

  • dna (torch.Tensor) – Attribute neighbor distance.

  • dns (torch.Tensor) – Structure neighbor distance.

loss_func(x, x_, s, s_, h_a, h_s, dna, dns)[source]

Loss function for DONE.

Parameters:
  • x (torch.Tensor) – Input attribute embeddings.

  • x – Reconstructed attribute embeddings.

  • s (torch.Tensor) – Input structure embeddings.

  • s – Reconstructed structure embeddings.

  • h_a (torch.Tensor) – Attribute hidden embeddings.

  • h_s (torch.Tensor) – Structure hidden embeddings.

  • dna (torch.Tensor) – Attribute neighbor distance.

  • dns (torch.Tensor) – Structure neighbor distance.

Returns:

  • loss (torch.Tensor) – Loss value.

  • oa (torch.Tensor) – Attribute outlier scores.

  • os (torch.Tensor) – Structure outlier scores.

  • oc (torch.Tensor) – Combined outlier scores.

static process_graph(data)[source]

Obtain the dense adjacency matrix of the graph.

Parameters:

data (torch_geometric.data.Data) – Input graph.