-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpendulum_symbolic2.py
205 lines (147 loc) · 6.22 KB
/
pendulum_symbolic2.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# flake8: noqa: E501
import torch
import numpy as np
from torch import nn
import torch.nn.functional as F
def replaceX(s):
s = s.replace("x[:,2]", "x2")
s = s.replace("x[:,1]", "x1")
s = s.replace("x[:,0]", "x0")
s = s.replace("self.p[0]", "p0")
s = s.replace("self.p[1]", "p1")
s = s.replace("self.p[2]", "p2")
s = s.replace("self.p[3]", "p3")
s = s.replace("self.p[4]", "p4")
s = s.replace("self.p[5]", "p5")
return s
class Symbolic7Orig(nn.Module):
name = "symbolic_complex7Orig"
def __init__(self):
super().__init__()
def forward(self, x):
r = ((x[:, 2] * x[:, 0]) + x[:, 1]) / -2.3512144
return r
def to_str(self):
return "(((x2 * x0) + x1) / -2.3512144)"
def to_str_raw(self):
return replaceX("(((x[:,2] * x[:,0]) + x[:,1]) / -2.3512144)")
def unscale_action(self, scaled_action):
return scaled_action
class Symbolic7A(nn.Module):
name = "symbolic_complex7A"
def __init__(self):
super().__init__()
self.p = nn.Parameter(torch.FloatTensor([-2.3512144, 1.0, 1.0]))
def forward(self, x):
r = (self.p[1] * (x[:, 2] * x[:, 0]) + self.p[2] * x[:, 1]) / self.p[0]
return r
def to_str(self):
return replaceX(f"(({self.p[1]}*(x[:,2] * x[:,0]) + {self.p[2]}*x[:,1] ) / {self.p[0]})")
def to_str_raw(self):
return replaceX("((self.p[1] * (x[:,2] * x[:,0]) + self.p[2] * x[:,1]) / self.p[0])")
def unscale_action(self, scaled_action):
return scaled_action
class Symbolic7B(nn.Module):
name = "symbolic_complex7B"
def __init__(self):
super().__init__()
self.p = nn.Parameter(torch.FloatTensor([1.0 / -2.3512144, 1.0, 1.0]))
def forward(self, x):
r = (self.p[1] * (x[:, 2] * x[:, 0]) + self.p[2] * x[:, 1]) * self.p[0]
return r
def to_str(self):
return replaceX(f"(({self.p[1]}*(x[:,2] * x[:,0]) + {self.p[2]}*x[:,1] ) / {self.p[0]})")
def to_str_raw(self):
return replaceX("((self.p[1] * (x[:,2] * x[:,0]) + self.p[2] * x[:,1]) / self.p[0])")
def unscale_action(self, scaled_action):
return scaled_action
class Symbolic9A(nn.Module):
name = "symbolic_complex9A"
def __init__(self):
super().__init__()
self.p = nn.Parameter(torch.FloatTensor([-2.326582, 1.0, 1.0, 1.0]))
def forward(self, x):
r = (((self.p[1] * x[:, 2] + self.p[2] * x[:, 1]) * x[:, 0]) + self.p[3] * x[:, 1]) / self.p[0]
return r
def to_str(self):
return replaceX(f"(((({self.p[1]}*x[:,2] + {self.p[2]}*x[:,1]) * x[:,0]) + {self.p[3]}*x[:,1]) / {self.p[0]})")
def to_str_raw(self):
return replaceX("((((self.p[1]*x[:,2] + self.p[2]*x[:,1]) * x[:,0]) + self.p[3]*x[:,1]) / self.p[0])")
def unscale_action(self, scaled_action):
return scaled_action
class Symbolic9B(nn.Module):
name = "symbolic_complex9B"
def __init__(self):
super().__init__()
self.p = nn.Parameter(torch.FloatTensor([1.0 / -2.326582, 1.0, 1.0, 1.0, 1.0]))
def forward(self, x):
r = (((self.p[1] * x[:, 2] + self.p[2] * x[:, 1]) * x[:, 0]) + self.p[3] * x[:, 1] + self.p[4]) * self.p[0]
return r
def to_str(self):
return replaceX(
f"(((({self.p[1]}*x[:,2] + {self.p[2]}*x[:,1]) * x[:,0]) + {self.p[3]}*x[:,1] + {self.p[4]}) / {self.p[0]})"
)
def to_str_raw(self):
return replaceX(
"((((self.p[1]*x[:,2] + self.p[2]*x[:,1]) * x[:,0]) + self.p[3]*x[:,1] + self.p[4]) / self.p[0])"
)
def unscale_action(self, scaled_action):
return scaled_action
class Symbolic17A(nn.Module):
name = "symbolic_complex17A"
def __init__(self):
super().__init__()
self.p = nn.Parameter(torch.FloatTensor([-0.07611064, -0.7107913, 1.0, 1.0, 1.0]))
def forward(self, x):
r = ((self.p[2] * x[:, 2] + self.p[3] * x[:, 1]) * x[:, 0] * self.p[4]) / (
(x[:, 2] * ((x[:, 2] * (x[:, 0] * x[:, 0])) * self.p[0])) + self.p[1]
)
return r
def to_str(self):
return replaceX(
f"((({self.p[2]}*x[:,2] + {self.p[3]}*x[:,1]) * x[:,0] * {self.p[4]}) / ((x[:,2] * ((x[:,2] * (x[:,0] * x[:,0])) * {self.p[0]})) + {self.p[1]}))"
)
def to_str_raw(self):
return replaceX(
"(((self.p[2]*x[:,2] + self.p[3]*x[:,1]) * x[:,0] * self.p[4]) / ((x[:,2] * ((x[:,2] * (x[:,0] * x[:,0])) * self.p[0])) + self.p[1]))"
)
def unscale_action(self, scaled_action):
return scaled_action
class Symbolic13A(nn.Module):
name = "symbolic_complex13A"
def __init__(self):
super().__init__()
self.p = nn.Parameter(torch.FloatTensor([-0.060752857, -0.64416397, 1.0, 1.0]))
def forward(self, x):
r = ((x[:, 2] * self.p[2] + x[:, 1] * self.p[3]) * x[:, 0]) / ((x[:, 2] * (x[:, 2] * self.p[0])) + self.p[1])
return r
def to_str_raw(self):
return replaceX(
"(((x[:,2]*self.p[2] + x[:,1]*self.p[3]) * x[:,0]) / ((x[:,2] * (x[:,2] * self.p[0])) + self.p[1]))"
)
def to_str(self):
return replaceX(
f"(((x[:,2]*{self.p[2]} + x[:,1]*{self.p[3]}) * x[:,0]) / ((x[:,2] * (x[:,2] * {self.p[0]})) + {self.p[1]}))"
)
def unscale_action(self, scaled_action):
return scaled_action
class Symbolic19A(nn.Module):
name = "symbolic_complex19A"
def __init__(self):
super().__init__()
self.p = nn.Parameter(torch.FloatTensor([0.2807797, 0.14147963, -0.061397437, -0.8070769, 1.0, 1.0]))
def forward(self, x):
r = ((self.p[4] * x[:, 2] + (x[:, 1] / self.p[0])) * x[:, 0]) / (
(((x[:, 1] / self.p[1]) + self.p[5] * x[:, 2]) * (x[:, 2] * self.p[2])) + self.p[3]
)
return r
def to_str_raw(self):
return replaceX(
"(((self.p[4]*x[:,2] + (x[:,1] / self.p[0])) * x[:,0]) / ((((x[:,1] / self.p[1]) + self.p[5]*x[:,2]) * (x[:,2] * self.p[2])) + self.p[3]))"
)
def to_str(self):
return replaceX(
f"((({self.p[4]}*x[:,2] + (x[:,1] / {self.p[0]})) * x[:,0]) / ((((x[:,1] / {self.p[1]}) + {self.p[5]}*x[:,2]) * (x[:,2] * {self.p[2]})) + {self.p[3]}))"
)
def unscale_action(self, scaled_action):
return scaled_action