dgld.utils.dataset
This is a program about loading data.
- class dgld.utils.dataset.GraphNodeAnomalyDectionDataset(name='Cora', raw_dir=None, p=15, k=50, is_preprocess_features=True, g_data=None, y_data=None)[source]
Bases:
DGLDataset
This is a class to get graph and inject anomaly follow [CoLA](https://arxiv.org/abs/2103.00113),inject Anomaly to the oral graph We fix p = 15 and set q to 10, 15, 20, 5, 5, 20, 200 for BlogCatalog, Flickr, ACM, Cora, Citeseer, Pubmed and ogbn-arxiv, respectively.
- Parameters
name (str) – when name == ‘custom’, using custom data and please Specify custom data by g_data. and Specify label by y_data. [BlogCatalog, Flickr, Cora, Citeseer, Pubmed and ogbn-arxiv] is supported default follow CoLA.
raw_dir (str) – Save data path. Supports user customization.
p (int) – anomaly injection hyperparameter follow CoLA, for structural anomaly
k (int) – anomaly injection hyperparameter follow CoLA, for contextual anomaly
is_preprocess_features (bool) – follow the same preprocess as CoLA, default by True
g_data (DGL.Graph) – Specify custom data by g_data.
y_data (Torch.Tensor) – Specify custom label by g_data.
Examples
>>> import GraphNodeAnomalyDectionDataset >>> dataset = GraphNodeAnomalyDectionDataset('Cora', p = 15, k = 50) >>> print(dataset[0])
- property anomalies_idx
Functions that return the index of anomaly node
- Returns
out – index of anomaly node
- Return type
torch.Tensor
- property anomaly_label
- Functions that return the anomaly label of node
0: normal node 1: structural anomaly 2: contextual anomaly
- Returns
out – anomaly label of node
- Return type
torch.Tensor
- property contextual_anomalies_idx
Functions that return the index of contextual anomaly node
- Returns
out – index of contextual anomaly node
- Return type
torch.Tensor
- evaluation_multiround(predict_score_arr)[source]
Functions that evaluates mulit-round result(as CoLA)
- Parameters
predict_score_arr (torch.Tensor) – prediction to be evaluated
- Returns
final_score (numpy.float)
a_score (numpy.float)
s_score (numpy.float)
- evalution(prediction)[source]
Functions that evaluate prediction for separate anomaly and global, auc as metrics
- Parameters
prediction (torch.Tensor) – prediction to be evaluated
- Returns
final_score (numpy.float)
a_score (numpy.float)
s_score (numpy.float)
- init_anomaly_label(label=None)[source]
Functions that initialize the anomaly label of node
- Parameters
label (torch.Tensor) – initial anomaly label of node in ‘anomaly_label’ (default None)
- Return type
None
- property node_attr
Functions that return the attribute of node
- Returns
out – attribute of node
- Return type
torch.Tensor
- property normal_idx
Functions that return the index of normal node
- Returns
out – index of normal node
- Return type
torch.Tensor
- property num_anomaly
Functions that return the number of anomaly node
- Returns
out – number of anomaly node
- Return type
int
- property num_nodes
Functions that return the number of node
- Returns
out – number of node
- Return type
int
- preprocess_features(features)[source]
Functions that process features, here norm in row
- Parameters
features (torch.Tensor) – features to be processed
- Return type
None
- set_anomaly_label(label)[source]
Functions that set the anomaly label of node
- Parameters
attr (torch.Tensor) – anomaly label assigned to node in ‘anomaly_label’
- Return type
None
- set_node_attr(attr)[source]
Functions that set the attribute of node
- Parameters
attr (torch.Tensor) – attribute assigned to node in ‘feat’
- Return type
None
- property structural_anomalies_idx
Functions that return the index of structural anomaly node
- Returns
out – index of structural anomaly node
- Return type
torch.Tensor