dgld.models.DONE.done_utils

class dgld.models.DONE.done_utils.SubgraphNeighborSampler(num_neighbors=-1)[source]

Bases: Sampler

the neighbor sampler of the subgraph

Parameters

num_neighbors (int, optional) – number of sampling neighbors, by default -1

sample(g, indices)[source]

Abstract sample method.

Parameters
  • g (DGLGraph) – The graph.

  • indices (object) – Any object representing the indices selected in the current minibatch.

dgld.models.DONE.done_utils.get_subargs(args)[source]
dgld.models.DONE.done_utils.loss_func(x, x_hat, c, c_hat, h_a, h_s, hom_str, hom_attr, alphas, scale_factor, pretrain=False)[source]

loss function

Parameters
  • x (torch.Tensor) – adjacency matrix of the original graph

  • x_hat (torch.Tensor) – adjacency matrix of the reconstructed graph

  • c (torch.Tensor) – attribute matrix of the original graph

  • c_hat (torch.Tensor) – attribute matrix of the reconstructed graph

  • h_a (torch.Tensor) – embedding of attribute autoencoders

  • h_s (torch.Tensor) – embedding of structure autoencoders

  • hom_str (torch.Tensor) – intermediate value of homogeneity loss of structure autoencoder

  • hom_attr (torch.Tensor) – intermediate value of homogeneity loss of attribute autoencoder

  • alphas (list) – balance parameters

  • scale_factor (float) – scale factor

  • pretrain (bool, optional) – whether to pre-train, by default False

Returns

  • loss (torch.Tensor) – loss value

  • score (torch.Tensor) – outlier score

dgld.models.DONE.done_utils.random_walk_with_restart(g: DGLHeteroGraph, k=3, r=0.3, eps=1e-05)[source]

Consistent with the description of “Network Preprocessing” in Section 4.1 of the paper.

Parameters
  • g (dgl.DGLGraph) – graph data

  • k (int, optional) – The maximum length of the truncated random walk, by default 3

  • r (float, optional) – Probability of restart, by default 0.3

  • eps (float, optional) – To avoid errors when the reciprocal of a node’s out-degree is inf, by default 0.1

Return type

torch.Tensor

dgld.models.DONE.done_utils.set_subargs(parser)[source]
dgld.models.DONE.done_utils.test_step(model, g, adj, batch_size, alphas, device)[source]

test model in one epoch

Parameters
  • model (nn.Module) – DONE base model

  • g (dgl.DGLGraph) – graph data

  • adj (torch.Tensor) – adjacency matrix

  • batch_size (int) – the size of training batch

  • alphas (list) – balance parameters

  • device (str) – device of computation

Return type

numpy.ndarray

dgld.models.DONE.done_utils.train_step(model, optimizer: Optimizer, g: DGLHeteroGraph, adj: Tensor, batch_size: int, alphas: list, num_neighbors: int, device, pretrain=False)[source]

train model in one epoch

Parameters
  • model (class) – DONE base model

  • optimizer (torch.optim.Optimizer) – optimizer to adjust model

  • g (dgl.DGLGraph) – original graph

  • adj (torch.Tensor) – adjacency matrix

  • batch_size (int) – the size of training batch

  • alphas (list) – balance parameters

  • num_neighbors (int) – number of sampling neighbors

  • device (str) – device of computation

  • pretrain (bool, optional) – whether to pre-train, by default False

Returns

  • predict_score (numpy.ndarray) – outlier score

  • epoch_loss (torch.Tensor) – loss value for epoch