-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrf_pendulum_gemma2
More file actions
75 lines (61 loc) · 2.29 KB
/
Copy pathrf_pendulum_gemma2
File metadata and controls
75 lines (61 loc) · 2.29 KB
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
Generation 0
import numpy as np
def reward(action, obs):
angle, angular_velocity = obs
deviation = np.abs(angle - np.pi)
# Reward based on both deviation and angular velocity
rew = -(deviation + 0.1 * abs(angular_velocity))
return rew
Generation 1
import numpy as np
def reward(action, obs):
angle, angular_velocity = obs
deviation = np.abs(angle - np.pi)
# Reward based on both deviation and angular velocity with scaling and sparsity
rew = -(deviation + 0.1 * abs(angular_velocity))
if deviation < 0.1: # Sparse reward for small deviations
rew += 1
return rew
Generation 2
import numpy as np
def reward(action, obs):
angle, angular_velocity = obs
deviation = np.abs(angle - np.pi)
# Reward based on both deviation and angular velocity with scaling and sparsity
rew = -(deviation + 0.1 * abs(angular_velocity))
if deviation < 0.05: # Sparse reward for smaller deviations, encouraging finer control
rew += 1
# Bonus for reaching upright position
if deviation < 0.01:
rew += 5
return rew
Generation 3
import numpy as np
def reward(action, obs):
angle, angular_velocity = obs
deviation = np.abs(angle - np.pi)
# Reward based on both deviation and angular velocity with scaling
rew = - (deviation + 0.1 * abs(angular_velocity))
if deviation < 0.05: # Sparse reward for smaller deviations, encouraging finer control
rew += 1
# Exponential bonus for reaching upright position to encourage faster convergence
if deviation < 0.01:
rew += np.exp(-deviation)
return rew
Generation 4
import numpy as np
def reward(action, obs):
angle, angular_velocity = obs
deviation = np.abs(angle - np.pi)
# Penalize high angular velocity more heavily when near upright position
if deviation < 0.1:
rew = -(deviation + 0.5 * abs(angular_velocity))
else:
rew = -(deviation + 0.1 * abs(angular_velocity))
# Sparse reward for smaller deviations, encouraging finer control
if deviation < 0.05:
rew += 1
# Exponential bonus scaled by angular velocity for reaching upright position to encourage smoother and faster convergence
if deviation < 0.01:
rew += np.exp(-deviation) * (1 - abs(angular_velocity)/(12*np.pi))
return rew