dgld.models.GUIDE.model

class dgld.models.GUIDE.model.GNAConv(in_feat, out_feat)[source]

Bases: Module

GNAConv for rebuild struct feature

Parameters
  • in_feat (int) – input data dimension

  • out_feat (int) – output data dimension

forward(block, feat)[source]

The function to compute forward

Parameters
  • block (DGL.Graph.DGLBlock) – input graph

  • feat (torch.tensor) – feature

Returns

out – out feature

Return type

torch.tensor

message_func(edges)[source]

the message function

Parameters

edges (dgl.DGLGraph.edges) –

Returns

msg – the message

Return type

dict

training: bool
class dgld.models.GUIDE.model.GUIDE(attrb_dim, attrb_hid, struct_dim, struct_hid, num_layers=4, dropout=0, act=<function relu>)[source]

Bases: object

Higher-order Structure Based Anomaly Detection on Attributed Networks 2021 IEEE International Conference on Big Data

Parameters
  • attrb_dim (int) – attributed feature dimensions of input data

  • attrb_hid (int) – Hidden dimension for attribute autoencoder

  • struct_dim (int) – struct feature dimensions of input data,you can use function get_struct_feat() to generate struct feature or use 6 as same as org paper

  • struct_hid (int) – Hidden dimension for struct autoencoder

  • num_layers (int, optional) – Total number of layers. Default: 4.

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

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

Examples

>>> gnd_dataset = GraphNodeAnomalyDectionDataset("Cora", p = 15, k = 50)
>>> g = gnd_dataset[0]
>>> label = gnd_dataset.anomaly_label
>>> model = GUIDE(g.ndata['feat'].shape[1],256,6,64,num_layers=4,dropout=0.6)
>>> model.fit(g,lr=0.001,num_epoch=200,device='0',alpha=0.9986,verbose=True,y_true=label)
>>> result = model.predict(g,alpha=0.9986)
>>> print(split_auc(label, result))
fit(graph, attrb_feat=None, struct_feat=None, lr=0.005, batch_size=0, num_epoch=100, alpha=None, device='cpu', verbose=False, y_true=None)[source]

train the model

Parameters
  • graph (DGL.Graph) – input graph with feature named “feat” in g.ndata

  • attrb_feat (torch.tensor, optional) – attribute feature,if don’t set, auto use the graph.ndata[‘feat’]. Default: None

  • struct_feat (torch.tensor, optional) – struct feature,if don’t set,auto generate by function get_struct_feat(). Default: None

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

  • logdir (str, optional) – tensorboard logdir. Default: ‘tmp’

  • num_epoch (int, optional) – number of epoch for training. Default: 100

  • alpha (float, optional) – the weight about attribute loss and struct loss,if don’t set, auto generate. Default: None

  • device (str, optional) – device. Default : ‘cpu’

  • verbose (bool, optional) – Verbosity mode. Turn on to print out log information. Default : False.

  • y_true (list , optional) – The optional outlier ground truth labels used to monitor the training progress. Default : None

init_model()[source]

Initialize model

predict(graph, attrb_feat=None, struct_feat=None, batch_size=0, alpha=None, device='cpu')[source]

test the model

Parameters
  • graph (DGL.Graph) – input graph with feature named “feat” in g.ndata

  • attrb_feat (torch.tensor, optional) – attribute feature,if don’t set, auto use the graph.ndata[‘feat’]. Default: None

  • struct_feat (torch.tensor, optional) – struct feature,if don’t set,auto generate by function get_struct_feat(). Default: None

  • alpha (float, optional) – the weight about attribute loss and struct loss,if don’t set, auto generate. Default: None

  • device (str, optional) – device. Default : ‘cpu’

Returns

  • score (torch.tensor)

  • the score of all nodes

class dgld.models.GUIDE.model.GUIDEModel(attrb_dim, attrb_hid, struct_dim, struct_hid, num_layers=4, dropout=0, act=<function relu>)[source]

Bases: Module

cal_loss(attrb_org, attrb_rb, struct_org, struct_rb, alpha)[source]

calculation the loss of the model

Parameters
  • attrb_org (torch.tensor) – original attribute feature

  • attrb_rb (torch.tensor) – rebuild attribute feature

  • struct_org (torch.tensor) – original struct feature

  • struct_rb (torch.tensor) – rebuild struct feature

  • alpha (float, optional) – the weight about attribute loss and struct loss

Returns

loss – the loss of the model

Return type

torch.tensor

forward(blocks, attr_feat, struct_feat)[source]

The function to compute forward

Parameters
  • blocks (list) – list of DGLBlock

  • attrb_feat (torch.tensor) – attribute feature

  • struct_feat (torch.tensor) – struct feature

Returns

  • attr_feat (torch.tensor) – rebuilded attribute feature

  • struct_feat (torch.tensor) – rebuilded struct feature

get_all_score(attrb_org, attrb_rb, struct_org, struct_rb, alpha)[source]

get all node’s score

Parameters
  • attrb_org (torch.tensor) – original attribute feature

  • attrb_rb (torch.tensor) – rebuild attribute feature

  • struct_org (torch.tensor) – original struct feature

  • struct_rb (torch.tensor) – rebuild struct feature

  • alpha (float, optional) – the weight about attribute loss and struct loss

Returns

score – shape is (num_node,1) the score of all nodes

Return type

torch.tensor

training: bool