in long_term/locomotion_utils.py [0:0]
def extract_translations_controls(positions_world, xy_orientation):
"""
Extract extra features for the long-term network:
- Translations: longitudinal speed along the spline; height of the root joint.
- Controls: walking phase as a [cos(theta), sin(theta)] signal; same for the facing direction and movement direction.
"""
phase = build_phase_track(positions_world)
xy = np.diff(positions_world[:, 0, [0, 2]], axis=0)
xy = np.concatenate((xy, xy[-1:]), axis=0)
z = positions_world[:, 0, 1] # We use a xzy coordinate system
speeds_abs = np.linalg.norm(xy, axis=1) # Instantaneous speed along the trajectory
amplitude = scipy.ndimage.filters.gaussian_filter1d(speeds_abs, 5) # Low-pass filter
speeds_abs -= amplitude # Extract high-frequency details
# Integrate the high-frequency speed component to recover an offset w.r.t. the trajectory
speeds_abs = np.cumsum(speeds_abs)
xy /= np.linalg.norm(xy, axis=1).reshape(-1, 1) + 1e-9 # Epsilon to avoid division by zero
return np.stack((speeds_abs, z, # Translations
np.cos(phase)*amplitude, np.sin(phase)*amplitude, # Controls
xy[:, 0]*amplitude, xy[:, 1]*amplitude, # Controls
np.sin(xy_orientation), np.cos(xy_orientation)), # Controls
axis=1)