-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_shared_component.py
More file actions
33 lines (22 loc) · 927 Bytes
/
model_shared_component.py
File metadata and controls
33 lines (22 loc) · 927 Bytes
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
import torch
import torch.nn as nn
device = 'cpu'
class ParetoSetModel(torch.nn.Module):
def __init__(self, n_dim, n_obj):
super(ParetoSetModel, self).__init__()
self.n_dim = n_dim
self.n_obj = n_obj
self.n_node = 1024
self.fc1 = nn.Linear(self.n_obj, self.n_node)
self.fc2 = nn.Linear(self.n_node, self.n_node)
self.fc3 = nn.Linear(self.n_node, self.n_dim)
self.constant = nn.Parameter(data=torch.rand((1, n_dim), dtype=torch.float), requires_grad=True)
def forward(self, pref):
x = torch.relu(self.fc1(pref))
x = torch.relu(self.fc2(x))
x = self.fc3(x)
alpha = torch.ones(self.n_dim).to(device)
alpha[3] = 0
x = self.constant + alpha * x
x = torch.sigmoid(x)
return x.to(torch.float64)