-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanomaly_detection.py
41 lines (31 loc) · 1.09 KB
/
anomaly_detection.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
#! /usr/bin/env python
"""
Anomaly detection and the input are graph embeddings
Author: Alston
Date: 2020.11.9
"""
import torch.nn as nn
import torch.nn.functional as F
class Autoencoder(nn.Module):
def __init__(self):
super(Autoencoder, self).__init__()
# encoder
self.enc1 = nn.Linear(in_features=20, out_features=16)
self.enc2 = nn.Linear(in_features=16, out_features=8)
self.enc3 = nn.Linear(in_features=8, out_features=4)
self.enc4 = nn.Linear(in_features=4, out_features=2)
# decoder
self.dec1 = nn.Linear(in_features=2, out_features=4)
self.dec2 = nn.Linear(in_features=4, out_features=8)
self.dec3 = nn.Linear(in_features=8, out_features=16)
self.dec4 = nn.Linear(in_features=16, out_features=20)
def forward(self, x):
x = F.relu(self.enc1(x))
x = F.relu(self.enc2(x))
x = F.relu(self.enc3(x))
x = F.relu(self.enc4(x))
x = F.relu(self.dec1(x))
x = F.relu(self.dec2(x))
x = F.relu(self.dec3(x))
x = F.relu(self.dec4(x))
return x