Performs a graph convolution operation. Args: input_tensor (torch.Tensor): Input tensor representing node features. adj_mat (torch.Tensor): Normalized adjacency matrix representing graph structure. Returns: torch.Tensor: Output tensor af
(self, input_tensor, adj_mat)
| 44 | nn.init.zeros_(self.bias) # Initialize the bias to zeros |
| 45 | |
| 46 | def forward(self, input_tensor, adj_mat): |
| 47 | """ |
| 48 | Performs a graph convolution operation. |
| 49 | |
| 50 | Args: |
| 51 | input_tensor (torch.Tensor): Input tensor representing node features. |
| 52 | adj_mat (torch.Tensor): Normalized adjacency matrix representing graph structure. |
| 53 | |
| 54 | Returns: |
| 55 | torch.Tensor: Output tensor after the graph convolution operation. |
| 56 | """ |
| 57 | |
| 58 | support = torch.mm(input_tensor, self.kernel) # Matrix multiplication between input and weight matrix |
| 59 | output = torch.spmm(adj_mat, support) # Sparse matrix multiplication between adjacency matrix and support |
| 60 | # Add the bias (if bias is not None) |
| 61 | if self.bias is not None: |
| 62 | output = output + self.bias |
| 63 | |
| 64 | return output |
| 65 | |
| 66 | |
| 67 | class GCN(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected