tf_agents.agents.data_converter.AsHalfTransition

Class that validates and converts other data types to HalfTransition.

HalfTransition is a special Transition whose next_time_step contains a dummy observation.

Note that validation and conversion allows values to contain dictionaries with extra keys as compared to the specs in the data context. These additional entries / observations are ignored and dropped during conversion.

This non-strict checking allows users to provide additional info and observation keys at input without having to manually prune them before converting.

data_context An instance of DataContext, typically accessed from the TFAgent.data_context property.
squeeze_time_dim Whether to emit a transition without time dimensions. If True, incoming trajectories are expected to have a time dimension of exactly 2, and emitted Transitions will have no time dimensions.

Methods

__call__

View source

Convert value to an N-step Transition; validate data & prune.

  • If value is already a Transition, only validation is performed.
  • If value is a Trajectory with tensors containing a time dimension having T != n + 1, a ValueError is raised.

Args
value A Trajectory or Transition object to convert.

Returns
A validated and pruned Transition. If squeeze_time_dim = True, the resulting Transition has tensors with shape [B, ...]. Otherwise, the tensors will have shape [B, T - 1, ...].

Raises
TypeError If value is not one of Trajectory or Transition.
ValueError If value has structure that doesn't match the converter's spec.
TypeError If value has a structure that doesn't match the converter's spec.
ValueError If n != None and value is a Trajectory with a time dimension having value other than T=n + 1.