aprel.basics package

aprel.basics.environment module

Environment-related modules.

class aprel.basics.environment.Environment(env: gym.core.Env, feature_func: Callable)

Bases: object

This is a wrapper around an OpenAI Gym environment, so that we can store the features function along with the environment itself.

Parameters
  • env (gym.Env) – An OpenAi Gym environment.

  • features (Callable) – Given a Trajectory, this function must return a numpy.array of features.

env

The wrapped environment.

Type

gym.Env

features

Features function.

Type

Callable

action_space

Inherits from env.

observation_space

Inherits from env.

reset

Inherits from env.

Type

Callable

step

Inherits from env.

Type

Callable

render

Inherits from env, if it exists; None otherwise.

Type

Callable

render_exists

True if render exists.

Type

bool

close

Inherits from env, if it exists; None otherwise.

Type

Callable

close_exists

True if close exists.

Type

bool

aprel.basics.trajectory module

Modules that are related to environment trajectories.

class aprel.basics.trajectory.Trajectory(env: aprel.basics.environment.Environment, trajectory: List[Tuple[numpy.array, numpy.array]], clip_path: Optional[str] = None)

Bases: object

A class for keeping trajectories that consist of a sequence of state-action pairs, the features and a clip path that keeps a video visualization of the trajectory.

This class supports indexing, such that t^th index returns the state-action pair at time step t. However, indices cannot be assigned, i.e., a specific state-action pair cannot be changed, because that would enable infeasible trajectories.

Parameters
  • env (Environment) – The environment object that generated this trajectory.

  • trajectory (List[Tuple[numpy.array, numpy.array]]) – The sequence of state-action pairs.

  • clip_path (str) – The path to the video clip that keeps the visualization of the trajectory.

trajectory

The sequence of state-action pairs.

Type

List[Tuple[numpy.array, numpy.array]]

features

Features of the trajectory.

Type

numpy.array

clip_path

The path to the video clip that keeps the visualization of the trajectory.

Type

str

property length: int

The length of the trajectory, i.e., the number of time steps in the trajectory.

visualize()

Visualizes the trajectory with a video if the clip exists. Otherwise, prints the trajectory information.

Note

FPS is fixed at 25 for video visualizations.

class aprel.basics.trajectory.TrajectorySet(trajectories: List[aprel.basics.trajectory.Trajectory])

Bases: object

A class for keeping a set of trajectories, i.e. Trajectory objects.

This class supports indexing, such that t^th index returns the t^th trajectory in the set. Similarly, t^th trajectory in the set can be replaced with a new trajectory using indexing. Only for reading trajectories with indexing, list indices are also allowed.

Parameters

trajectories (List[Trajectory]) – The list of trajectories to be stored in the set.

trajectories

The list of trajectories in the set.

Type

List[Trajectory]

features_matrix

n x d array of features where each row consists of the d features of the corresponding trajectory.

Type

numpy.array

append(new_trajectory: aprel.basics.trajectory.Trajectory)

Appends a new trajectory to the set.

property size: int

The number of trajectories in the set.