- class Trajectory(keys, low, high, joint_pos_idx, interpolate_map, interpolate_remap, traj_path=None, traj_files=None, interpolate_map_params=None, interpolate_remap_params=None, traj_dt=0.002, control_dt=0.01, ignore_keys=None, clip_trajectory_to_joint_ranges=False, traj_info=None, warn=True)[source]
Bases:
objectGeneral class to handle trajectory data. It builds a general trajectory from a numpy bin file(.npy), and automatically interpolates the trajectory to the desired control frequency. This class is used to generate datasets and to sample from the dataset to initialize the simulation.
All trajectories are required to be of equal length.
- check_if_trajectory_is_in_range(low, high, keys, j_idx, warn, clip_trajectory_to_joint_ranges)[source]
- create_dataset(ignore_keys=None, state_callback=None, state_callback_params=None)[source]
Creates a dataset used by imitation learning algorithms.
- Args:
ignore_keys (list): List of keys to ignore in the dataset. state_callback (func): Function that should be called on each state. state_callback_params (dict): Dictionary of parameters needed to make
the state transformation.
- Returns:
Dictionary containing states, next_states, absorbing and last flags. For the states the shape is (N_traj x N_samples_per_traj-1, dim_state), while the flags have the shape (N_traj x N_samples_per_traj-1). If traj_info was specified, it will also include that.
- flattened_trajectories()[source]
Returns the trajectories flattened in the N_traj dimension. Also expands dim if obs has dimension 1.
- get_from_sample(sample, key)[source]
Returns the part of the sample whose key is specified. In contrast to the function _get_from_obs from the base environment, this function also allows to access information that is in the trajectory, but not in the simulation such as goal definitions.
Note: This function is not suited for getting an observation from environment samples!
- Args:
sample (list or np.array): Current sample to extract an observation from. key (string): Name of the observation to extract from sample
- Returns:
np.array consisting of the observation specified by the key.
- get_idx(key)[source]
Returns the index of the key.
Note: This function is not suited for getting the index for an observation of the environment!
- Args:
key (string): Name of the observation to extract from sample
- Returns:
int containing the desired index.
- reset_trajectory(substep_no=None, traj_no=None)[source]
Resets the trajectory to a certain trajectory and a substep within that trajectory. If one of them is None, they are set randomly.
- Args:
- substep_no (int, None): Starting point of the trajectory.
If None, the trajectory starts from a random point.
- traj_no (int, None): Number of the trajectory to start from.
If None, it starts from a random trajectory
- Returns:
The chosen (or randomly sampled) sample from a trajectory.
- property number_obs_trajectory
Returns the number of observations in the trajectory.
- property number_of_trajectories
Returns the number of trajectories.
- property trajectory_length
Returns the length of a trajectory. Note that all trajectories have to be equal in length.