-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlp_model.py
56 lines (47 loc) · 1.42 KB
/
mlp_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
#%%
'''
with help from https://github.com/christianversloot/machine-learning-articles/blob/main/how-to-create-a-neural-network-for-regression-with-pytorch.md
'''
import torch
from torch import nn
import pandas as pd
from sklearn.preprocessing import StandardScaler
from torch.utils.data import DataLoader
from sklearn.metrics import mean_squared_error
import config
#%%
class MLP_model(nn.Module):
## init the superclass
def __init__(self):
super().__init__()
# input first flows through the first layer, followed by the second, followed by..
self.layers = nn.Sequential(
nn.Linear(config.l0, config.l1),
nn.ReLU(),
nn.Linear(config.l1, config.l2),
nn.ReLU(),
nn.Linear(config.l2, 1)
).cuda()
def forward(self, x):
'''
Forward pass: feed the input data through the model (self.layers) and return the result
'''
return self.layers(x)
#%%
class MLP_model_mp(nn.Module):
## init the superclass
def __init__(self):
super().__init__()
# input first flows through the first layer, followed by the second, followed by..
self.layers = nn.Sequential(
nn.Linear(config.l0, config.l1),
nn.ReLU(),
nn.Linear(config.l1, config.l2),
nn.ReLU(),
nn.Linear(config.l2, 1)
).cuda()
def forward(self, x):
'''
Forward pass: feed the input data through the model (self.layers) and return the result
'''
return self.layers(x)