-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
145 lines (101 loc) · 3.66 KB
/
model.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from torch.nn import Linear
import torch.nn.functional as F
from utils import *
from torch import nn
from torch.nn import Parameter
from torch_geometric.nn import GINConv, SAGEConv
from torch.nn.utils import spectral_norm
class MLP_discriminator(torch.nn.Module):
def __init__(self, args):
super(MLP_discriminator, self).__init__()
self.args = args
self.lin = Linear(args.hidden, 1)
def reset_parameters(self):
self.lin.reset_parameters()
def forward(self, h, edge_index=None, mask_node=None):
h = self.lin(h)
return torch.sigmoid(h)
class MLP_encoder(torch.nn.Module):
def __init__(self, args):
super(MLP_encoder, self).__init__()
self.args = args
self.lin = Linear(args.num_features, args.hidden)
def reset_parameters(self):
self.lin.reset_parameters()
def forward(self, x, edge_index=None, mask_node=None):
h = self.lin(x)
return h
class GCN_encoder_scatter(torch.nn.Module):
def __init__(self, args):
super(GCN_encoder_scatter, self).__init__()
self.args = args
self.lin = Linear(args.num_features, args.hidden, bias=False)
self.bias = Parameter(torch.Tensor(args.hidden))
def reset_parameters(self):
self.lin.reset_parameters()
self.bias.data.fill_(0.0)
def forward(self, x, edge_index, adj_norm_sp):
h = self.lin(x)
h = propagate2(h, edge_index) + self.bias
return h
class GCN_encoder_spmm(torch.nn.Module):
def __init__(self, args):
super(GCN_encoder_spmm, self).__init__()
self.args = args
self.lin = Linear(args.num_features, args.hidden, bias=False)
self.bias = Parameter(torch.Tensor(args.hidden))
def reset_parameters(self):
self.lin.reset_parameters()
self.bias.data.fill_(0.0)
def forward(self, x, edge_index, adj_norm_sp):
h = self.lin(x)
h = torch.spmm(adj_norm_sp, h) + self.bias
return h
class GIN_encoder(nn.Module):
def __init__(self, args):
super(GIN_encoder, self).__init__()
self.args = args
self.mlp = nn.Sequential(
nn.Linear(args.num_features, args.hidden),
# nn.ReLU(),
nn.BatchNorm1d(args.hidden),
# nn.Linear(args.hidden, args.hidden),
)
self.conv = GINConv(self.mlp)
def reset_parameters(self):
self.conv.reset_parameters()
def forward(self, x, edge_index, adj_norm_sp):
h = self.conv(x, edge_index)
return h
class SAGE_encoder(nn.Module):
def __init__(self, args):
super(SAGE_encoder, self).__init__()
self.args = args
self.conv1 = SAGEConv(args.num_features, args.hidden, normalize=True)
self.conv1.aggr = 'mean'
self.transition = nn.Sequential(
nn.ReLU(),
nn.BatchNorm1d(args.hidden),
nn.Dropout(p=args.dropout)
)
self.conv2 = SAGEConv(args.hidden, args.hidden, normalize=True)
self.conv2.aggr = 'mean'
def reset_parameters(self):
self.conv1.reset_parameters()
self.conv2.reset_parameters()
def forward(self, x, edge_index, adj_norm_sp):
x = self.conv1(x, edge_index)
x = self.transition(x)
h = x
# h = self.conv2(x, edge_index)
return h
class MLP_classifier(torch.nn.Module):
def __init__(self, args):
super(MLP_classifier, self).__init__()
self.args = args
self.lin = Linear(args.hidden, args.num_classes)
def reset_parameters(self):
self.lin.reset_parameters()
def forward(self, h, edge_index=None):
h = self.lin(h)
return h