-
Notifications
You must be signed in to change notification settings - Fork 22
/
models.py
73 lines (54 loc) · 2.14 KB
/
models.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
# -*- coding:utf-8 -*-
import torch
import torch.nn.functional as F
from torch import nn
from torch_geometric.nn import GATConv, GCNConv, SAGEConv, SGConv
class GCN(torch.nn.Module):
def __init__(self, in_feats, h_feats, out_feats):
super(GCN, self).__init__()
self.conv1 = GCNConv(in_feats, h_feats)
self.conv2 = GCNConv(h_feats, out_feats)
def forward(self, data):
x, edge_index = data.x, data.edge_index
x = F.dropout(x, p=0.6, training=self.training)
x = F.relu(self.conv1(x, edge_index))
x = self.conv2(x, edge_index)
return x
class GraphSAGE(torch.nn.Module):
def __init__(self, in_feats, h_feats, out_feats):
super(GraphSAGE, self).__init__()
self.conv1 = SAGEConv(in_feats, h_feats, normalize=True)
self.conv2 = SAGEConv(h_feats, out_feats, normalize=True)
def forward(self, data):
x, edge_index = data.x, data.edge_index
x = F.dropout(x, p=0.6, training=self.training)
x = F.relu(self.conv1(x, edge_index))
x = self.conv2(x, edge_index)
return x
class GAT(torch.nn.Module):
def __init__(self, in_feats, h_feats, out_feats):
super(GAT, self).__init__()
self.conv1 = GATConv(in_feats, h_feats, heads=8, concat=False)
self.conv2 = GATConv(h_feats, out_feats, heads=8, concat=False)
def forward(self, data):
x, edge_index = data.x, data.edge_index
x = F.dropout(x, p=0.6, training=self.training)
x = F.relu(self.conv1(x, edge_index))
x = self.conv2(x, edge_index)
return x
class SGC(nn.Module):
def __init__(self, in_feats, out_feats):
super(SGC, self).__init__()
self.softmax = nn.Softmax(dim=1)
self.w = nn.Linear(in_feats, out_feats)
def forward(self, x):
out = self.w(x)
return out
class PyG_SGC(torch.nn.Module):
def __init__(self, in_feats, out_feats):
super(PyG_SGC, self).__init__()
self.conv = SGConv(in_feats, out_feats, K=2, cached=True)
def forward(self, data):
x, edge_index = data.x, data.edge_index
x = self.conv(x, edge_index)
return x