d3rlpy.dataset.FrameStackTrajectorySlicer

class d3rlpy.dataset.FrameStackTrajectorySlicer(n_frames)[source]

Frame-stacking trajectory slicer.

This class implements the frame-stacking logic. The observations are stacked with the last n_frames-1 frames. When index specifies timestep below n_frames, those frames are padded by zeros.

episode = Episode(
    observations=np.random.random((100, 1, 84, 84)),
    actions=np.random.random((100, 2)),
    rewards=np.random.random((100, 1)),
    terminated=False,
)

frame_stacking_slicer = FrameStackTrajectorySlicer(n_frames=4)
trajectory = frame_stacking_slicer(episode, 0, 10)

trajectory.observations.shape == (10, 4, 84, 84)
Parameters:

n_frames – Number of frames to stack.

Methods

__call__(episode, end_index, size)[source]

Slice trajectory.

This method returns a partial trajectory from t=end_index-size to t=end_index. If end_index-size is smaller than 0, those parts will be padded by zeros.

Parameters:
  • episode (EpisodeBase) – Episode.

  • end_index (int) – Index at the end of the sliced trajectory.

  • size (int) – Length of the sliced trajectory.

Returns:

Sliced trajectory.

Return type:

PartialTrajectory