flippercy
/
Locally-Interpretable-One-Class-Anomaly-Detection-for-Credit-Card-Fraud-Detection
Public
forked from tony10101105/Locally-Interpretable-One-Class-Anomaly-Detection-for-Credit-Card-Fraud-Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
executable file
·66 lines (52 loc) · 2.03 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
import torch
import torch.nn as nn
torch.manual_seed(0)#for reproducibility
def weights_init_normal(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1:
nn.init.xavier_uniform_(m.weight.data)
elif classname.find('Linear') != -1:
nn.init.normal_(m.weight.data)
nn.init.constant_(m.bias.data, 0.0)
elif classname.find('BatchNorm1d') != -1:
nn.init.normal_(m.weight.data)
nn.init.constant_(m.bias.data, 0.0)
def init_weights(net_layer):
try:
net_layer.apply(weights_init_normal)
except:
raise NotImplementedError('weights initialization error')
class FCNN(nn.Module):#discriminator
def __init__(self):
super(FCNN, self).__init__()
self.layer = nn.Sequential(nn.Linear(28, 10),
nn.BatchNorm1d(10),
nn.ReLU(True),
nn.Linear(10, 1))
init_weights(self.layer)
#self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.layer(x)
#x = self.sigmoid(x)
return x
class autoencoder(nn.Module):#generator
def __init__(self):
super(autoencoder, self).__init__()
self.encoder = nn.Sequential(nn.Linear(28, 15),
nn.BatchNorm1d(15),
nn.ReLU(True),
nn.Linear(15, 8),
nn.BatchNorm1d(8),
nn.ReLU(True))
init_weights(self.encoder)
self.decoder = nn.Sequential(nn.Linear(8, 15),
nn.BatchNorm1d(15),
nn.ReLU(True),
nn.Linear(15, 28))
init_weights(self.decoder)
#self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
#x = self.sigmoid(x)
return x