MCPcopy Create free account
hub / github.com/IBM/Project_CodeNet / GINConv

Class GINConv

model-experiments/gnn-based-experiments/src/model/conv.py:11–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10### GIN convolution along the graph structure
11class GINConv(MessagePassing):
12 def __init__(self, emb_dim, edge_attr_dim):
13 '''
14 emb_dim (int): node embedding dimensionality
15 '''
16
17 super(GINConv, self).__init__(aggr = "add")
18
19 self.mlp = torch.nn.Sequential(torch.nn.Linear(emb_dim, 2*emb_dim), torch.nn.BatchNorm1d(2*emb_dim), torch.nn.ReLU(), torch.nn.Linear(2*emb_dim, emb_dim))
20 self.eps = torch.nn.Parameter(torch.Tensor([0]))
21
22 # edge_attr is two dimensional after augment_edge transformation
23 self.edge_encoder = torch.nn.Linear(edge_attr_dim, emb_dim)
24
25 def forward(self, x, edge_index, edge_attr):
26 edge_embedding = self.edge_encoder(edge_attr)
27 out = self.mlp((1 + self.eps) *x + self.propagate(edge_index, x=x, edge_attr=edge_embedding))
28
29 return out
30
31 def message(self, x_j, edge_attr):
32 return F.relu(x_j + edge_attr)
33
34 def update(self, aggr_out):
35 return aggr_out
36
37### GCN convolution along the graph structure
38class GCNConv(MessagePassing):

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected