MCPcopy Create free account
hub / github.com/cure-lab/deep-active-learning / GraphConvolution

Class GraphConvolution

models/gcn.py:9–42  ·  view source on GitHub ↗

Simple GCN layer, similar to https://arxiv.org/abs/1609.02907

Source from the content-addressed store, hash-verified

7from torch.nn.modules.module import Module
8
9class GraphConvolution(Module):
10 """
11 Simple GCN layer, similar to https://arxiv.org/abs/1609.02907
12 """
13
14 def __init__(self, in_features, out_features, bias=True):
15 super(GraphConvolution, self).__init__()
16 self.in_features = in_features
17 self.out_features = out_features
18 self.weight = Parameter(torch.FloatTensor(in_features, out_features))
19 if bias:
20 self.bias = Parameter(torch.FloatTensor(out_features))
21 else:
22 self.register_parameter('bias', None)
23 self.reset_parameters()
24
25 def reset_parameters(self):
26 stdv = 1. / math.sqrt(self.weight.size(1))
27 self.weight.data.uniform_(-stdv, stdv)
28 if self.bias is not None:
29 self.bias.data.uniform_(-stdv, stdv)
30
31 def forward(self, input, adj):
32 support = torch.mm(input, self.weight)
33 output = torch.spmm(adj, support)
34 if self.bias is not None:
35 return output + self.bias
36 else:
37 return output
38
39 def __repr__(self):
40 return self.__class__.__name__ + ' (' \
41 + str(self.in_features) + ' -> ' \
42 + str(self.out_features) + ')'
43
44
45class GCN(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected