@@ -28,6 +28,7 @@ class GraphConv(nn.Module):
28
28
input features per node.
29
29
A: Adjacency matrix of the graph with shape (N, N), representing the relationships between nodes.
30
30
W: Learnable weight matrix with shape (F_in, F_out), where F_out is the number of output features per node.
31
+ D: The degree matrix.
31
32
"""
32
33
def __init__ (self , input_dim , output_dim , use_bias = False ):
33
34
super (GraphConv , self ).__init__ ()
@@ -48,7 +49,7 @@ def forward(self, input_tensor, adj_mat):
48
49
49
50
Args:
50
51
input_tensor (torch.Tensor): Input tensor representing node features.
51
- adj_mat (torch.Tensor): Adjacency matrix representing graph structure.
52
+ adj_mat (torch.Tensor): Normalized adjacency matrix representing graph structure.
52
53
53
54
Returns:
54
55
torch.Tensor: Output tensor after the graph convolution operation.
@@ -92,7 +93,7 @@ def forward(self, input_tensor, adj_mat):
92
93
Args:
93
94
input_tensor (torch.Tensor): Input node feature matrix with shape (N, input_dim), where N is the number of nodes
94
95
and input_dim is the number of input features per node.
95
- adj_mat (torch.Tensor): Adjacency matrix of the graph with shape (N, N), representing the relationships between
96
+ adj_mat (torch.Tensor): Normalized adjacency matrix of the graph with shape (N, N), representing the relationships between
96
97
nodes.
97
98
98
99
Returns:
@@ -113,7 +114,7 @@ def forward(self, input_tensor, adj_mat):
113
114
114
115
def load_cora (path = './cora' , device = 'cpu' ):
115
116
"""
116
- The graph convolutional operation rquires normalize the adjacency matrix: D^(-1/2) * A * D^(-1/2). This step
117
+ The graph convolutional operation rquires the normalized adjacency matrix: D^(-1/2) * A * D^(-1/2). This step
117
118
scales the adjacency matrix such that the features of neighboring nodes are weighted appropriately during
118
119
aggregation. The steps involved in the renormalization trick are as follows:
119
120
- Compute the degree matrix.
@@ -249,7 +250,7 @@ def test(model, criterion, input, target, mask):
249
250
idx = torch .randperm (len (labels )).to (device )
250
251
idx_test , idx_val , idx_train = idx [:1000 ], idx [1000 :1500 ], idx [1500 :]
251
252
252
- gcn = GCN (features .shape [1 ], args .hidden_dim , labels .max ().item () + 1 ,args .include_bias , args .dropout_p ).to (device )
253
+ gcn = GCN (features .shape [1 ], args .hidden_dim , labels .max ().item () + 1 , args .include_bias , args .dropout_p ).to (device )
253
254
optimizer = Adam (gcn .parameters (), lr = args .lr , weight_decay = args .l2 )
254
255
criterion = nn .NLLLoss ()
255
256
0 commit comments