dgld.models.ComGA.models
ComGA: Community-Aware Attributed Graph Anomaly Detection
- class dgld.models.ComGA.models.AttrDecoder(in_feats, n_enc_1, n_enc_2, n_enc_3, dropout)[source]
Bases:
Module
AttrDecoder, utilize attribute decoder to take the learned latent representation Z as input to decode them for reconstruction of original nodal attributes.
- Parameters
in_feats (int) – dimension of feature
n_enc_1 (int) – number of encode1 units
n_enc_2 (int) – number of encode2 units
n_enc_3 (int) – number of encode3 units
dropout (float) – Dropout rate
- forward(g, z)[source]
Forward Propagation
- Parameters
g (dgl.DGLGraph) – graph dataset
z (torch.Tensor) – the node latent representation
- Returns
Reconstructed attribute matrix
- Return type
torch.Tensor
- training: bool
- class dgld.models.ComGA.models.ComGA(num_nodes, num_feats, n_enc_1, n_enc_2, n_enc_3, dropout)[source]
Bases:
Module
ComGA: Community-Aware Attributed Graph Anomaly Detection ref:https://github.com/DASE4/ComGA
- Parameters
num_nodes (int) – number of nodes
num_feats (int) – dimension of feature
n_enc_1 (int) – number of encode1 units
n_enc_2 (int) – number of encode2 units
n_enc_3 (int) – number of encode3 units
dropout (float) – Dropout rate
- fit(graph, lr=0.005, num_epoch=1, alpha=0.7, eta=5.0, theta=40.0, device='cpu', patience=10)[source]
Fitting model
- Parameters
graph (dgl.DGLGraph) – graph dataset
lr (float, optional) – learning rate, by default 5e-3
num_epoch (int, optional) – number of training epochs , by default 1
alpha (float, optional) – balance parameter, by default 0.8
eta (float, optional) – Attribute penalty balance parameter, by default 5.0
theta (float, optional) – structure penalty balance parameter, by default 40.0
device (str, optional) – cuda id, by default ‘cpu’
patience (int, optional) – early stop patience , by default 10
- predict(graph, alpha=0.7, eta=5.0, theta=40.0, device='cpu')[source]
predict and return anomaly score of each node
- Parameters
graph (dgl.DGLGraph) – graph dataset
alpha (float, optional) – balance parameter, by default 0.8
eta (float, optional) – Attribute penalty balance parameter, by default 5.0
theta (float, optional) – structure penalty balance parameter, by default 40.0
device (str, optional) – cuda id, by default ‘cpu’
- Returns
anomaly score of each node
- Return type
numpy.ndarray
- training: bool
- class dgld.models.ComGA.models.ComGAModel(num_nodes, num_feats, n_enc_1, n_enc_2, n_enc_3, dropout)[source]
Bases:
Module
ComGA is an anomaly detector consisting of a Community Detection Module, a tGCN Module and an Anomaly Detection Module
- Parameters
num_nodes (int) – number of nodes
num_feats (int) – dimension of feature
n_enc_1 (int) – number of encode1 units
n_enc_2 (int) – number of encode2 units
n_enc_3 (int) – number of encode3 units
dropout (float) – Dropout rate
- forward(g, x, B)[source]
Forward Propagation
- Parameters
g (dgl.DGLGraph) – graph dataset
x (torch.Tensor) – features of nodes
B (torch.Tensor) – Modularity Matrix
- Returns
A_hat (torch.Tensor) – Reconstructed adj matrix
X_hat (torch.Tensor) – Reconstructed attribute matrix
B_hat (torch.Tensor) – Reconstructed Modularity Matrix
z (torch.Tensor) – the node latent representation of tgcnEnc
z_a (torch.Tensor) – the node latent representation of CommunityAE
- training: bool
- class dgld.models.ComGA.models.CommunityAE(num_nodes, n_enc_1, n_enc_2, n_enc_3, dropout)[source]
Bases:
Module
Community Detection Module, The modularity matrix B is reconstructed by autoencode to obtain a representation of each node with community information.
- Parameters
num_nodes (int) – number of nodes
n_enc_1 (int) – number of encode1 units
n_enc_2 (int) – number of encode2 units
n_enc_3 (int) – number of encode3 units
dropout (float) – Dropout rate
- forward(B)[source]
Forward Propagation
- Parameters
B (torch.Tensor) – Modularity Matrix
- Returns
hidden1 (torch.Tensor) – the node latent representation of encoder1
hidden2 (torch.Tensor) – the node latent representation of encoder2
z_a (torch.Tensor) – the node latent representation of encoder3
community_reconstructions (torch.Tensor) – Reconstructed Modularity Matrix
- training: bool
- class dgld.models.ComGA.models.StruDecoder(dropout)[source]
Bases:
Module
StruDecoder, utilize structure decoder to take the learned latent representation Z as input to decode them for reconstruction of original graph structure.
- Parameters
dropout (float) – Dropout rate
- forward(z)[source]
Forward Propagation
- Parameters
z (torch.Tensor) – the node latent representation
- Returns
Reconstructed adj matrix
- Return type
torch.Tensor
- training: bool
- dgld.models.ComGA.models.init_weights(module: Module) None [source]
Init Module Weights
- Parameters
module (nn.Module) – models to initialize linear weight
Examples
>>> for module in self.modules(): >>> init_weights(module)
- class dgld.models.ComGA.models.tGCNEncoder(in_feats, n_enc_1, n_enc_2, n_enc_3, dropout)[source]
Bases:
Module
tGCNEncoder, To effectively fuse community structure information to GCN model for structure anomaly, and learn more distinguishable anomalous node representations for local, global, and structure anomalies.
- Parameters
in_feats (int) – dimension of feature
n_enc_1 (int) – number of encode1 units
n_enc_2 (int) – number of encode2 units
n_enc_3 (int) – number of encode3 units
dropout (float) – Dropout rate
- forward(g, x, B_enc1, B_enc2, B_enc3)[source]
Forward Propagation
- Parameters
g (dgl.DGLGraph) – graph dataset
x (torch.Tensor) – features of nodes
B_enc1 (torch.Tensor) – the node latent representation of CommunityAE encoder1
B_enc2 (torch.Tensor) – the node latent representation of CommunityAE encoder2
B_enc3 (torch.Tensor) – the node latent representation of CommunityAE encoder3
- Returns
the node latent representation of tGCNEncoder
- Return type
torch.Tensor
- training: bool