This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
forked from Lifoof/MoGCN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.py
44 lines (40 loc) · 1.42 KB
/
layer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/8/8 16:19
# @Author : Li Xiao
# @File : layer.py
import torch
import math
from torch import nn
from torch.nn.parameter import Parameter
class GraphConvolution(nn.Module):
def __init__(self, infeas, outfeas, bias=True):
super(GraphConvolution,self).__init__()
self.in_features = infeas
self.out_features = outfeas
self.weight = Parameter(torch.FloatTensor(infeas, outfeas))
if bias:
self.bias = Parameter(torch.FloatTensor(outfeas))
else:
self.register_parameter('bias', None)
self.reset_parameters()
def reset_parameters(self):
stdv = 1. / math.sqrt(self.weight.size(1))
self.weight.data.uniform_(-stdv, stdv)
if self.bias is not None:
self.bias.data.uniform_(-stdv,stdv)
'''
for name, param in GraphConvolution.named_parameters(self):
if 'weight' in name:
#torch.nn.init.constant_(param, val=0.1)
torch.nn.init.normal_(param, mean=0, std=0.1)
if 'bias' in name:
torch.nn.init.constant_(param, val=0)
'''
def forward(self, x, adj):
x1 = torch.mm(x, self.weight)
output = torch.mm(adj, x1)
if self.bias is not None:
return output + self.bias
else:
return output