-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModel.py
70 lines (46 loc) · 1.92 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
from unicodedata import bidirectional
import torch
import torch.nn.functional as F
from torch import nn
from torch.nn.utils import spectral_norm
from torch.nn.parameter import Parameter
import torch
from torch_geometric.nn import GCNConv,GATConv
from dgl.nn import GraphConv
import dgl.function as fn
import dgl.nn as dglnn
class DNN(nn.Module):
def __init__(self, input_dim, hidden_dim,device):
super().__init__()
self.hidden_dim = hidden_dim
self.fc1 = nn.Linear(input_dim,hidden_dim) # fully connected layer: maps last hidden vector to model prediction
self.activation1 = nn.ReLU() # coz binary classification
self.drop=nn.Dropout(0.25)
self.fc2 = nn.Linear(hidden_dim,1)
self.activation2 = nn.Sigmoid()
self.device=device
def forward(self, x):
e = self.drop(self.activation1(self.fc1(x)))
out=self.activation2(self.fc2(e))
return out
class GATT(nn.Module):
def __init__(self, input_dim, hidden_dim, device):
super(GATT, self).__init__()
self.hidden_dim = hidden_dim
self.conv1 = GATConv(input_dim, hidden_dim, heads=1) # using one attention head for simplicity
self.activation1 = nn.ReLU()
self.drop = nn.Dropout(0.25)
# self.fc = nn.Linear(hidden_dim, 1) # Linear can also be used to map embedding from GATConv to preds
self.fc=GATConv(hidden_dim,1, heads=1)
self.activation2 = nn.Sigmoid()
self.device = device
# Move the entire model to the specified device
self.to(self.device)
def forward(self, edge_index, x):
# x, edge_index = data.x, data.edge_index
h = self.conv1(x, edge_index)
h = self.activation1(h)
h = self.drop(h)
out = self.fc(h,edge_index)
# Activation function
return self.activation2(out.squeeze(-1))