forked from Joachm/evolving_hebbian_learning_rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicies.py
102 lines (66 loc) · 2.92 KB
/
policies.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
import torch
import torch.nn as nn
class MLP_heb(nn.Module):
"MLP, no bias"
def __init__(self, input_space, action_space):
super(MLP_heb, self).__init__()
self.fc1 = nn.Linear(input_space, 128, bias=False)
self.fc2 = nn.Linear(128, 64, bias=False)
self.fc3 = nn.Linear(64, action_space, bias=False)
def forward(self, ob):
state = torch.as_tensor(ob).float().detach()
x1 = torch.tanh(self.fc1(state))
x2 = torch.tanh(self.fc2(x1))
o = torch.tanh(self.fc3(x2))
return state, x1, x2, o
# return state, self.fc1(state), self.fc2(x1), self.fc3(x2)
def get_weights(self):
return nn.utils.parameters_to_vector(self.parameters()).detach()
class MLP_heb_med(nn.Module):
"MLP, no bias"
def __init__(self, input_space, action_space):
super(MLP_heb_med, self).__init__()
self.fc1 = nn.Linear(input_space, 64, bias=False)
self.fc2 = nn.Linear(64, 32, bias=False)
self.fc3 = nn.Linear(32, action_space, bias=False)
def forward(self, ob):
state = torch.as_tensor(ob).float().detach()
x1 = torch.tanh(self.fc1(state))
x2 = torch.tanh(self.fc2(x1))
o = torch.tanh(self.fc3(x2))
return state, x1, x2, o
# return state, self.fc1(state), self.fc2(x1), self.fc3(x2)
def get_weights(self):
return nn.utils.parameters_to_vector(self.parameters()).detach()
class MLP_heb_small(nn.Module):
"MLP, no bias"
def __init__(self, input_space, action_space):
super(MLP_heb_small, self).__init__()
self.fc1 = nn.Linear(input_space, 32, bias=False)
self.fc2 = nn.Linear(32, 16, bias=False)
self.fc3 = nn.Linear(16, action_space, bias=False)
def forward(self, ob):
state = torch.as_tensor(ob).float().detach()
x1 = torch.tanh(self.fc1(state))
x2 = torch.tanh(self.fc2(x1))
o = torch.tanh(self.fc3(x2))
return state, x1, x2, o
# return state, self.fc1(state), self.fc2(x1), self.fc3(x2)
def get_weights(self):
return nn.utils.parameters_to_vector(self.parameters()).detach()
class MLP_heb_tiny(nn.Module):
"MLP, no bias"
def __init__(self, input_space, action_space):
super(MLP_heb_tiny, self).__init__()
self.fc1 = nn.Linear(input_space, 8, bias=False)
self.fc2 = nn.Linear(8, 8, bias=False)
self.fc3 = nn.Linear(8, action_space, bias=False)
def forward(self, ob):
state = torch.as_tensor(ob).float().detach()
x1 = torch.tanh(self.fc1(state))
x2 = torch.tanh(self.fc2(x1))
o = torch.tanh(self.fc3(x2))
return state, x1, x2, o
# return state, self.fc1(state), self.fc2(x1), self.fc3(x2)
def get_weights(self):
return nn.utils.parameters_to_vector(self.parameters()).detach()