dgld.models.MLPAE.model

Multilayer Perceptron Autoencoder

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

Bases: Module

Base MLP model

forward(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.MLPAE.model.MLPAE(feat_size, hidden_dim=128, n_layers=2, dropout=0.3, act=<function relu>)[source]

Bases: Module

Multilayer Perceptron Autoencoder

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

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

  • 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.MLPAE import MLPAE
>>> model = MLPAE(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=0)[source]

Fitting model

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

  • lr (float, optional) – learning rate. Defaults: 1e-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: 1.

  • 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.MLPAE.model.MLPAEModel(feat_size, hidden_dim=64, n_layers=2, dropout=0.3, act=<function relu>)[source]

Bases: Module

This is a basic model of MLPAE.

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(features)[source]

Forward Propagation

Parameters

features (torch.tensor) – features of nodes

Returns

x – Reconstructed node matrix

Return type

torch.tensor

training: bool