View source on GitHub |
Class that validates and converts other data types to HalfTransition.
tf_agents.agents.data_converter.AsHalfTransition(
data_context: tf_agents.agents.data_converter.DataContext
,
squeeze_time_dim=False
)
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.
Args | |
---|---|
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__
__call__(
value: typing.Any
) -> tf_agents.trajectories.Transition
Convert value
to an N-step Transition; validate data & prune.
- If
value
is already aTransition
, only validation is performed. - If
value
is aTrajectory
with tensors containing a time dimension havingT != n + 1
, aValueError
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 .
|