GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix policy_sample_mode, speedup linesearch, other cleanup/refactor · cbfinn/gps@5277c6a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • hyperparams.md
  • experiments/mjc_mdgps_example
    • hyperparams.py
    • off_classic
      • hyperparams.py
    • off_policy
      • hyperparams.py
    • on_classic
      • hyperparams.py
    • on_policy
      • hyperparams.py
  • python/gps
    • agent/mjc
      • agent_mjc.py
    • algorithm
      • algorithm.py
      • algorithm_badmm.py
      • algorithm_mdgps.py
      • algorithm_utils.py
      • config.py
      • dynamics
        • dynamics_lr.py
        • dynamics_lr_prior.py
      • policy
        • config.py
        • policy_prior.py
        • policy_prior_gmm.py
      • traj_opt
        • config.py
        • traj_opt_lqr_python.py
        • traj_opt_utils.py
    • gps_main.py
    • gui
      • gps_training_gui.py
    • utility
      • gmm.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/hyperparams.md‎

Copy file name to clipboardExpand all lines: docs/hyperparams.md
+4-2Lines changed: 4 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ This page contains all of the config settings that are exposed vi
2323
* fixed_lg_step
2424
* exp_step_decrease
2525
* init_pol_wt
26-
* max_policy_samples
2726
* policy_dual_rate
2827
* inner_iterations
2928
* exp_step_lower
@@ -34,6 +33,10 @@ This page contains all of the config settings that are exposed vi
3433
* policy_dual_rate_covar
3534
* ent_reg_schedule
3635

36+
**MDGPS Algorithm**
37+
* policy_sample_mode
38+
* step_rule
39+
3740
**LQR Traj Opt**
3841
* del0
3942
* eta_error_threshold
@@ -58,7 +61,6 @@ This page contains all of the config settings that are exposed vi
5861

5962
**Policy Prior & GMM**
6063
* strength
61-
* keep_samples
6264
* max_clusters
6365
* strength
6466
* min_samples_per_cluster
Collapse file

‎experiments/mjc_mdgps_example/hyperparams.py‎

Copy file name to clipboardExpand all lines: experiments/mjc_mdgps_example/hyperparams.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'substeps': 5,
5454
'conditions': common['conditions'],
5555
'pos_body_idx': np.array([1]),
56-
'pos_body_offset': [np.array([-0.08, -0.08, 0]), np.array([-0.08, -0.08, 0]),
56+
'pos_body_offset': [np.array([-0.08, -0.08, 0]), np.array([-0.08, 0.08, 0]),
5757
np.array([0.08, 0.08, 0]), np.array([0.08, -0.08, 0])],
5858
'T': 100,
5959
'sensor_dims': SENSOR_DIMS,
@@ -69,7 +69,7 @@
6969
'conditions': common['conditions'],
7070
'iterations': 12,
7171
'kl_step': 1.0,
72-
'min_step_mult': 0.05,
72+
'min_step_mult': 0.5,
7373
'max_step_mult': 3.0,
7474
'policy_sample_mode': 'replace',
7575
}
Collapse file

‎experiments/mjc_mdgps_example/off_classic/hyperparams.py‎

Copy file name to clipboardExpand all lines: experiments/mjc_mdgps_example/off_classic/hyperparams.py
-36Lines changed: 0 additions & 36 deletions
This file was deleted.
Collapse file

‎…_mdgps_example/off_global/hyperparams.py‎ ‎…_mdgps_example/off_policy/hyperparams.py‎experiments/mjc_mdgps_example/off_global/hyperparams.py renamed to experiments/mjc_mdgps_example/off_policy/hyperparams.py experiments/mjc_mdgps_example/off_global/hyperparams.py renamed to experiments/mjc_mdgps_example/off_policy/hyperparams.py

Copy file name to clipboardExpand all lines: experiments/mjc_mdgps_example/off_policy/hyperparams.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
algorithm = default.algorithm.copy()
2525
algorithm.update({
2626
'sample_on_policy': False,
27-
'step_rule': 'global',
2827
})
2928

3029
config = default.config.copy()
Collapse file

‎experiments/mjc_mdgps_example/on_classic/hyperparams.py‎

Copy file name to clipboardExpand all lines: experiments/mjc_mdgps_example/on_classic/hyperparams.py
-36Lines changed: 0 additions & 36 deletions
This file was deleted.
Collapse file

‎…c_mdgps_example/on_global/hyperparams.py‎ ‎…c_mdgps_example/on_policy/hyperparams.py‎experiments/mjc_mdgps_example/on_global/hyperparams.py renamed to experiments/mjc_mdgps_example/on_policy/hyperparams.py experiments/mjc_mdgps_example/on_global/hyperparams.py renamed to experiments/mjc_mdgps_example/on_policy/hyperparams.py

Copy file name to clipboardExpand all lines: experiments/mjc_mdgps_example/on_policy/hyperparams.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
algorithm = default.algorithm.copy()
2525
algorithm.update({
2626
'sample_on_policy': True,
27-
'step_rule': 'global',
2827
})
2928

3029
config = default.config.copy()
Collapse file

‎python/gps/agent/mjc/agent_mjc.py‎

Copy file name to clipboardExpand all lines: python/gps/agent/mjc/agent_mjc.py
+33-19Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def _setup_world(self, filename):
5050
# Initialize Mujoco worlds. If there's only one xml file, create a single world object,
5151
# otherwise create a different world for each condition.
5252
if not isinstance(filename, list):
53-
self._world = [mjcpy.MJCWorld(filename)
54-
for _ in range(self._hyperparams['conditions'])]
55-
self._model = [self._world[i].get_model()
53+
world = mjcpy.MJCWorld(filename)
54+
self._world = [world for _ in range(self._hyperparams['conditions'])]
55+
self._model = [self._world[i].get_model().copy()
5656
for i in range(self._hyperparams['conditions'])]
5757
else:
5858
for i in range(self._hyperparams['conditions']):
@@ -62,26 +62,22 @@ def _setup_world(self, filename):
6262
for i in range(self._hyperparams['conditions']):
6363
for j in range(len(self._hyperparams['pos_body_idx'][i])):
6464
idx = self._hyperparams['pos_body_idx'][i][j]
65+
# TODO: this should actually add [i][j], but that would break things
6566
self._model[i]['body_pos'][idx, :] += \
6667
self._hyperparams['pos_body_offset'][i]
67-
self._world[i].set_model(self._model[i])
68-
x0 = self._hyperparams['x0'][i]
69-
idx = len(x0) // 2
70-
data = {'qpos': x0[:idx], 'qvel': x0[idx:]}
71-
self._world[i].set_data(data)
72-
self._world[i].kinematics()
7368

7469
self._joint_idx = list(range(self._model[0]['nq']))
7570
self._vel_idx = [i + self._model[0]['nq'] for i in self._joint_idx]
7671

7772
# Initialize x0.
7873
self.x0 = []
79-
self.eepts0 = []
8074
for i in range(self._hyperparams['conditions']):
8175
if END_EFFECTOR_POINTS in self.x_data_types:
82-
self.eepts0.append(self._world[i].get_data()['site_xpos'].flatten())
76+
# TODO: this assumes END_EFFECTOR_VELOCITIES is also in datapoints right?
77+
self._init(i)
78+
eepts = self._world[i].get_data()['site_xpos'].flatten()
8379
self.x0.append(
84-
np.concatenate([self._hyperparams['x0'][i], self.eepts0[i], np.zeros_like(self.eepts0[i])])
80+
np.concatenate([self._hyperparams['x0'][i], eepts, np.zeros_like(eepts)])
8581
)
8682
else:
8783
self.x0.append(self._hyperparams['x0'][i])
@@ -123,7 +119,7 @@ def sample(self, policy, condition, verbose=True, save=True, noisy=True):
123119
var = self._hyperparams['noisy_body_var'][condition][i]
124120
self._model[condition]['body_pos'][idx, :] += \
125121
var * np.random.randn(1, 3)
126-
self._world[condition].set_model(self._model[condition])
122+
# Take the sample.
127123
for t in range(self.T):
128124
X_t = new_sample.get_X(t=t)
129125
obs_t = new_sample.get_obs(t=t)
@@ -142,19 +138,37 @@ def sample(self, policy, condition, verbose=True, save=True, noisy=True):
142138
self._samples[condition].append(new_sample)
143139
return new_sample
144140

141+
def _init(self, condition):
142+
"""
143+
Set the world to a given model, and run kinematics.
144+
Args:
145+
condition: Which condition to initialize.
146+
"""
147+
148+
# Initialize world/run kinematics
149+
self._world[condition].set_model(self._model[condition])
150+
x0 = self._hyperparams['x0'][condition]
151+
idx = len(x0) // 2
152+
data = {'qpos': x0[:idx], 'qvel': x0[idx:]}
153+
self._world[condition].set_data(data)
154+
self._world[condition].kinematics()
155+
145156
def _init_sample(self, condition):
146157
"""
147158
Construct a new sample and fill in the first time step.
148159
Args:
149160
condition: Which condition to initialize.
150161
"""
151162
sample = Sample(self)
152-
sample.set(JOINT_ANGLES,
153-
self._hyperparams['x0'][condition][self._joint_idx], t=0)
154-
sample.set(JOINT_VELOCITIES,
155-
self._hyperparams['x0'][condition][self._vel_idx], t=0)
156-
self._data = self._world[condition].get_data()
157-
eepts = self.eepts0[condition]
163+
164+
# Initialize world/run kinematics
165+
self._init(condition)
166+
167+
# Initialize sample with stuff from _data
168+
data = self._world[condition].get_data()
169+
sample.set(JOINT_ANGLES, data['qpos'].flatten(), t=0)
170+
sample.set(JOINT_VELOCITIES, data['qvel'].flatten(), t=0)
171+
eepts = data['site_xpos'].flatten()
158172
sample.set(END_EFFECTOR_POINTS, eepts, t=0)
159173
sample.set(END_EFFECTOR_POINT_VELOCITIES, np.zeros_like(eepts), t=0)
160174
jac = np.zeros([eepts.shape[0], self._model[condition]['nq']])
Collapse file

‎python/gps/algorithm/algorithm.py‎

Copy file name to clipboardExpand all lines: python/gps/algorithm/algorithm.py
+23-17Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def __init__(self, hyperparams):
2929
else:
3030
self.M = hyperparams['conditions']
3131
self._cond_idx = range(self.M)
32+
self._hyperparams['train_conditions'] = self._cond_idx
33+
self._hyperparams['test_conditions'] = self._cond_idx
3234
self.iteration_count = 0
3335

3436
# Grab a few values from the agent.
@@ -48,9 +50,9 @@ def __init__(self, hyperparams):
4850
self.cur = [IterationData() for _ in range(self.M)]
4951
self.prev = [IterationData() for _ in range(self.M)]
5052

53+
dynamics = self._hyperparams['dynamics']
5154
for m in range(self.M):
5255
self.cur[m].traj_info = TrajectoryInfo()
53-
dynamics = self._hyperparams['dynamics']
5456
self.cur[m].traj_info.dynamics = dynamics['type'](dynamics)
5557
init_traj_distr = extract_condition(
5658
self._hyperparams['init_traj_distr'], self._cond_idx[m]
@@ -76,28 +78,29 @@ def _update_dynamics(self):
7678
Instantiate dynamics objects and update prior. Fit dynamics to
7779
current samples.
7880
"""
79-
for cond in range(self.M):
80-
if self.iteration_count >= 1:
81-
self.prev[cond].traj_info.dynamics = \
82-
self.cur[cond].traj_info.dynamics.copy()
83-
cur_data = self.cur[cond].sample_list
84-
self.cur[cond].traj_info.dynamics.update_prior(cur_data)
85-
86-
self.cur[cond].traj_info.dynamics.fit(cur_data)
87-
88-
init_X = cur_data.get_X()[:, 0, :]
89-
x0mu = np.mean(init_X, axis=0)
90-
self.cur[cond].traj_info.x0mu = x0mu
91-
self.cur[cond].traj_info.x0sigma = np.diag(
92-
np.maximum(np.var(init_X, axis=0),
81+
for m in range(self.M):
82+
cur_data = self.cur[m].sample_list
83+
X = cur_data.get_X()
84+
U = cur_data.get_U()
85+
86+
# Update prior and fit dynamics.
87+
self.cur[m].traj_info.dynamics.update_prior(cur_data)
88+
self.cur[m].traj_info.dynamics.fit(X, U)
89+
90+
# Fit x0mu/x0sigma.
91+
x0 = X[:, 0, :]
92+
x0mu = np.mean(x0, axis=0)
93+
self.cur[m].traj_info.x0mu = x0mu
94+
self.cur[m].traj_info.x0sigma = np.diag(
95+
np.maximum(np.var(x0, axis=0),
9396
self._hyperparams['initial_state_var'])
9497
)
9598

96-
prior = self.cur[cond].traj_info.dynamics.get_prior()
99+
prior = self.cur[m].traj_info.dynamics.get_prior()
97100
if prior:
98101
mu0, Phi, priorm, n0 = prior.initial_state()
99102
N = len(cur_data)
100-
self.cur[cond].traj_info.x0sigma += \
103+
self.cur[m].traj_info.x0sigma += \
101104
Phi + (N*priorm) / (N+priorm) * \
102105
np.outer(x0mu-mu0, x0mu-mu0) / (N+n0)
103106

@@ -167,6 +170,9 @@ def _advance_iteration_variables(self):
167170
"""
168171
self.iteration_count += 1
169172
self.prev = copy.deepcopy(self.cur)
173+
# TODO: change IterationData to reflect new stuff better
174+
for m in range(self.M):
175+
self.prev[m].new_traj_distr = self.new_traj_distr[m]
170176
self.cur = [IterationData() for _ in range(self.M)]
171177
for m in range(self.M):
172178
self.cur[m].traj_info = TrajectoryInfo()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.