-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeepECG.py
143 lines (130 loc) · 4.04 KB
/
DeepECG.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
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.functional import *
class DeepECG(nn.Module):
def __init__(self, input_dim):
super().__init__()
neural_num = 200
d_prob = 0.1
self.linears = nn.Sequential(
nn.Linear(input_dim, 200),
nn.ReLU(inplace=True),
nn.Dropout(d_prob),
nn.Linear(200, 200),
nn.ReLU(inplace=True),
nn.Dropout(d_prob),
nn.Linear(200, 100),
nn.ReLU(inplace=True),
#nn.Dropout(d_prob),
nn.Linear(100, 1),
)
self.linears2 = nn.Sequential(
nn.Linear(50, 100),#63175
nn.ReLU(inplace=True),
nn.Dropout(d_prob),
nn.Linear(100, 50),
nn.ReLU(inplace=True),
#nn.Dropout(d_prob),
nn.Linear(50, 10),
nn.ReLU(inplace=True),
nn.Linear(10, 1)
)
def forward(self,x):
x1 = self.linears(x)
return x1
class DeepECG_addcov2(nn.Module):
def __init__(self, input_dim):
super().__init__()
d_prob = 0.1
self.linears1 = nn.Sequential(
nn.Linear(input_dim, 500),#63175 89222
nn.ReLU(inplace=True),
nn.Dropout(d_prob),
nn.Linear(500, 200),
nn.ReLU(inplace=True),
nn.Dropout(d_prob),
nn.Linear(200, 100),
nn.ReLU(inplace=True),
nn.Linear(100, 50),
#nn.ReLU(inplace=True),
#nn.Dropout(d_prob),
#nn.Linear(100, 1),
)
self.linears2 = nn.Sequential(
nn.Linear(52, 20),
nn.ReLU(inplace=True),
#nn.Dropout(d_prob),
nn.Linear(20, 10),
nn.ReLU(inplace=True),
nn.Linear(10, 1)
)
self.linears3 = nn.Sequential(
nn.Linear(2, 10),
nn.ReLU(inplace=True),
#nn.Dropout(d_prob),
nn.Linear(10, 10),
nn.ReLU(inplace=True),
nn.Linear(10, 1)
)
self.linears4 = nn.Sequential(
nn.Linear(2, 10),#63175
nn.ReLU(inplace=True),
#nn.Dropout(d_prob),
nn.Linear(10, 10),
nn.ReLU(inplace=True),
nn.Linear(10, 1)
)
self.linear1 = nn.Linear(10, 1)
self.linear2 = nn.Linear(10, 1)
self.linear3 = nn.Linear(20, 1)
def forward(self,snp_x, cov2_x):
#x1 = self.linears1(snp_x)
#y1 = self.linear1(x1)
# x2 = torch.cat([x1, cov2_x], dim=1)
# y3 = self.linears2(x2)
# x2 = self.linears2(cov2_x)
# y2 = self.linear2(x2)
# x3 = torch.cat([x1, x2], dim=1)
# y3 = self.linear3(x3)
y1 = self.linears1(snp_x)
#y3 = self.linears3(cov2_x)
x2 = torch.cat([y1, cov2_x], dim=1)
y4 = self.linears2(x2)
return y4
class CNN(nn.Module):
def __init__(self):
super().__init__()
self.layers = nn.Sequential(
nn.Conv1d(1, 16, kernel_size=3, stride=3),
nn.Conv1d(16, 16, kernel_size=3),
nn.BatchNorm1d(16),
nn.ReLU(inplace=True),
nn.Conv1d(16, 64, kernel_size=3, stride=3),
nn.Conv1d(64, 64, kernel_size=3),
nn.BatchNorm1d(64),
nn.ReLU(inplace=True),
nn.MaxPool1d(3),
nn.Flatten(),
nn.Linear(211392, 128),
nn.BatchNorm1d(128),
nn.ReLU(inplace=True),
nn.Dropout(0.2),
nn.Linear(128, 64),
nn.BatchNorm1d(64),
nn.ReLU(inplace=True),
nn.Dropout(0.2),
nn.Linear(64, 1)
# nn.Dropout(0.2),
# nn.MaxPool1d(3),
# nn.Flatten(),
# nn.Linear(158592, 64),
# nn.ReLU(inplace=True),
# nn.Linear(64, 32),
# nn.ReLU(inplace=True),
# nn.Linear(32, 1)
)
def forward(self,x):
x1 = self.layers(x)
return x1