MCPcopy Create free account
hub / github.com/pytorch/examples / forward

Method forward

gcn/main.py:46–64  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
67class GCN(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected