dgld.models.AAGNN.AAGNN_batch
This is a model for large graph training based on the AAGNN model
- class dgld.models.AAGNN.AAGNN_batch.AAGNN_batch(feat_size, out_feats=300)[source]
Bases:
Module
This is a model for large graph training based on the AAGNN model.
- Parameters
in_feats (int) – The feature dimension of the input data.
out_feats (int) – The dimension of output feature.
Examples
>>> from DGLD.AAGNN import AAGNN_batch >>> model = AAGNN_batch(in_feats=in_feats, out_feats=300) >>> model.fit(graph, num_epoch=30, device='cuda:0', subgraph_size=32)
- Graph_batch_sample(graph, node_ids, device, edge_dic)[source]
Here is a function for sampling the large graph data.
- Parameters
graph (dgl) – The graph data you input.
node_ids (numpy) – The id of the target node you want to sample.
device (str) – The number of times you want to train the model.
edge_dic (dict) – The input node-to-node relationship dictionary.
- Returns
adj_matrix (numpy.ndarray) – This is an adjacency matrix of sampled subgraphs.
eye_matrix (numpy.ndarray) – This is an adjacency matrix of sampled subgraphs.
subgraph_feats (numpy.ndarray) – Node feature vector of the subgraph.
node_mask (numpy.ndarray) – This is a vector marking which nodes are the target nodes we need.
- cal_center(graph, model, device, subgraph_size, edge_dic)[source]
This is a function to calculate the center vector.
- Parameters
graph (dgl) – The graph data you input.
model (tensor) – The model we trained.
device (str) – The number of times you want to train the model.
subgraph_size (int) – The size of training subgraph.
edge_dic (dict) – The input node-to-node relationship dictionary.
- Returns
center – The center vector of all samples.
- Return type
numpy.ndarray
- fit(graph, num_epoch=100, device='cpu', lr=0.0001, subgraph_size=4096)[source]
This is a function used to train the model.
- Parameters
graph (dgl) – The graph data you input.
num_epoch (int) – The number of times you want to train the model.
device (str) – The number of times you want to train the model.
lr (float) – Learning rate for model training.
- subgraph_sizeint
The size of training subgraph.
- Return type
None
- loss_fun(out, center, model, super_param, device)[source]
This is a function used to calculate the error loss of the model.
- Parameters
out (tensor) – Output of the model.
center (numpy.ndarray) – The center vector of all samples.
model (tensor) – The model we trained.
super_param (float) – A hyperparameter that takes values in [0, 1].
device (str) – The number of times you want to train the model.
- Returns
loss – The loss of model output.
- Return type
tensor
- predict(graph, device='cpu', subgraph_size=4096)[source]
This is a function that loads a trained model for predicting graph data.
- Parameters
graph (dgl) – The graph data you input.
device (str) – The number of times you want to train the model.
subgraph_size (int) – The size of training subgraph.
- Returns
score – A vector of decimals representing the anomaly score for each node.
- Return type
numpy
- training: bool
- class dgld.models.AAGNN.AAGNN_batch.model_base(in_feats, out_feats)[source]
Bases:
Module
This is the basic structure model of AAGNN.
- Parameters
in_feats (int) – The feature dimension of the input data.
out_feats (int) – The dimension of output feature.
Examples
>>> self.model = model_base(in_feats, out_feats)
- anomaly_score(out)[source]
Here is a function that calculates the anomaly score.
- Parameters
out (tensor) – Node vector representation output after model training.
- Returns
score – Anomaly Score of Nodes.
- Return type
numpy.ndarray
- forward(adj_matrix, eye_matrix, subgraph_feats, node_mask)[source]
This is a function used to calculate the forward propagation of the model.
- Parameters
adj_matrix (tensor) – This is an adjacency matrix of sampled subgraphs.
eye_matrix (tensor) – This is an adjacency matrix of sampled subgraphs.
subgraph_feats (tensor) – Node feature vector of the subgraph.
node_mask (tensor) – This is a vector marking which nodes are the target nodes we need.
- Returns
h – Results of model forward propagation calculations.
- Return type
tensor
- get_normal_nodes(node_feats, p, device)[source]
Here is a function that computes normal nodes.
- Parameters
node_feats (tensor) – All node feature vectors of graph data.
p (float) – All node feature vectors of graph data.
device (str) – The number of times you want to train the model.
- Returns
node_ids – The ID of the positive sample node.
- Return type
numpy.ndarray
- training: bool