dgld.models.GCNAE.model

Graph Convolutional Network Autoencoder

class dgld.models.GCNAE.model.GCN(in_feats, n_hidden, out_feats, n_layers, dropout, activation)[source]

Bases: Module

Base GCN model

forward(g, features)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class dgld.models.GCNAE.model.GCNAE(feat_size, hidden_dim=64, n_layers=2, dropout=0.3, act=<function relu>)[source]

Bases: Module

Graph Convolutional Networks Autoencoder

Parameters
  • feat_size (int) – dimension of input node feature.

  • hidden_dim (int, optional) – dimension of hidden layers’ feature. Defaults: 64.

  • n_layers (int, optional) – number of network layers. Defaults: 2.

  • dropout (float, optional) – dropout probability. Defaults: 0.3.

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

Examples

>>> from dgld.models.GCNAE import GCNAE
>>> model = GCNAE(feat_size=1433)
>>> model.fit(g, num_epoch=1)
>>> result = model.predict(g)
fit(g, lr=0.005, batch_size=0, num_epoch=100, weight_decay=0.0, device='cpu')[source]

Fitting model

Parameters
  • g (dgl.DGLGraph) – graph dataset.

  • lr (float, optional) – learning rate. Defaults: 5e-3.

  • batch_size (int, optional) – the size of training batch. Defaults: 0 for full graph train.

  • num_epoch (int, optional) – number of training epochs. Defaults: 100.

  • weight_decay (float, optional) – weight decay (L2 penalty). Defaults: 0.

  • device (str, optional) – device of computation. Defaults: ‘cpu’.

loss_func(x, x_hat)[source]

Calculate the loss

Parameters
  • x (torch.tensor) – The original features of node data.

  • x_hat (torch.tensor) – The output by model.

Returns

loss – The loss of model.

Return type

torch.tensor

predict(g, batch_size=0, device='cpu')[source]

predict and return anomaly score of each node

Parameters
  • g (dgl.DGLGraph) – graph dataset.

  • batch_size (int, optional) – the size of predict batch. Defaults: 0 for full graph predict.

  • device (str, optional) – device of computation. Defaults: ‘cpu’.

Returns

predict_score – anomaly score of each node.

Return type

numpy.ndarray

training: bool
class dgld.models.GCNAE.model.GCNAEModel(feat_size, hidden_dim=64, n_layers=2, dropout=0.3, act=<function relu>)[source]

Bases: Module

This is a basic model of GCNAE.

Parameters
  • feat_size (int) – dimension of input node feature.

  • hidden_dim (int, optional) – dimension of hidden layers’ feature. Defaults: 64.

  • n_layers (int, optional) – number of network layers. Defaults: 2.

  • dropout (float, optional) – dropout probability. Defaults: 0.3.

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

forward(g, features)[source]

Forward Propagation

Parameters
  • g (dgl.DGLGraph) – graph dataset

  • features (torch.tensor) – features of nodes

Returns

x – Reconstructed node matrix

Return type

torch.tensor

training: bool