Restrictors#
- class drama.restrictors.Restrictor(observation_space, action_space)[source]#
An agent whose actions are restrictions.
- act(observation: Space) Restriction[source]#
Compute the restriction for a observation.
- Parameters:
observation – The observation used to compute the restriction
- Returns:
The computed restriction
- class drama.restrictors.RestrictorActionSpace(base_space: Space, seed: int | Generator | None = None)[source]#
Action space representing sets of restrictions for a given base space.
- contains(x: Restriction) bool[source]#
Check if a restriction was created with the same base space.
- Parameters:
x – The restriction
- Returns:
True if the restriction is compatible with the restrictor action space. False otherwise
- is_compatible_with(action_space: Space)[source]#
Check if a action space is compatible with the restrictor action space.
- Parameters:
action_space – The action space which is checked for compatibility
- Returns:
True if the action space is compatible with the restrictor action space. False otherwise
- sample(mask: Any | None = None) Restriction[source]#
Randomly sample a restriction from the restrictor action space.
- Parameters:
mask – The mask used for sampling
- Returns:
A sampled restriction
- class drama.restrictors.DiscreteSetActionSpace(base_space: Discrete)[source]#
Action space representing valid restrictions for a discrete action space as a set of allowed actions.
- property is_np_flattenable: bool#
Checks whether this space can be flattened to a
gymnasium.spaces.Box.- Returns:
True
- sample(mask: Any | None = None) DiscreteSetRestriction[source]#
Randomly sample an instance of
DiscreteSetRestrictionfrom theDiscreteSetActionSpace.- Parameters:
mask – The mask used for sampling (currently no effect)
- Returns:
A sampled
DiscreteSetRestriction
- class drama.restrictors.DiscreteVectorActionSpace(base_space: Discrete)[source]#
Action space representing valid restrictions for a discrete action space as a binary vector.
- property is_np_flattenable: bool#
Checks whether this space can be flattened to a
gymnasium.spaces.Box.- Returns:
True
- sample(mask: Any | None = None) DiscreteVectorRestriction[source]#
Randomly sample an instance of
DiscreteVectorRestrictionfrom theDiscreteVectorActionSpace.- Parameters:
mask – The mask used for sampling (currently no effect)
- Returns:
A sampled
DiscreteVectorRestriction
- class drama.restrictors.IntervalUnionActionSpace(base_space: Box)[source]#
Action space representing valid restrictions for a
gymnasium.spaces.Boxaction space as a union of intervals.- property is_np_flattenable: bool#
Checks whether this space can be flattened to a
gymnasium.spaces.Box.- Returns:
True
- sample(mask: Any | None = None) IntervalUnionRestriction[source]#
Randomly sample an instance of
IntervalUnionRestrictionfrom theIntervalUnionActionSpace.- Parameters:
mask – The mask used for sampling (currently no effect)
- Returns:
A sampled
IntervalUnionRestriction
- class drama.restrictors.BucketSpaceActionSpace(base_space: Box, bucket_width=1.0, epsilon=0.01)[source]#
Action space representing valid restrictions for a
gymnasium.spaces.Boxaction space as a binary indicator vector for evenly split buckets.- property is_np_flattenable: bool#
Checks whether this space can be flattened to a
gymnasium.spaces.Box.- Returns:
True
- sample(mask: Any | None = None) BucketSpaceRestriction[source]#
Randomly sample an instance of
BucketSpaceRestrictionfrom theBucketSpaceActionSpace.- Parameters:
mask – The mask used for sampling (currently no effect)
- Returns:
A sampled
BucketSpaceRestriction