Utils#
- exception drama.utils.IntervalsOutOfBoundException(*args)[source]#
Thrown when the number of intervals exceeds the specified maximum representation length
- exception drama.utils.RestrictionViolationException(*args)[source]#
Thrown when a restriction is violated
- utils.random_replacement_violation_fn(action, restriction: Restriction)#
Random replacement of restriction violations.
- Parameters:
env – The environment after the agent step was taken
action – The action which violated the restriction
restriction – The restriction object corresponding to the action
- Returns:
Randomly sampled action from the allowed action space
- utils.projection_violation_fn(action, restriction: IntervalUnionRestriction)#
Euclidean projection of restriction violations.
- Parameters:
env – The environment after the agent step was taken
action – The action which violated the restriction
restriction – The restriction object corresponding to the action
- Returns:
Closest allowed action minimizing the euclidean distance
- utils.flatten(x: T, **kwargs) ndarray[Any, dtype[Any]] | Dict[str, Any] | Tuple[Any, ...] | GraphInstance#
Flatten a data point from a space.
- Parameters:
space – The space that
xis flattened byx – The value to flatten
**kwargs – Additional flattening parameters passed to subsequent flatten operations
- Returns:
The flattened datapoint
- utils.flatdim() int#
Return the number of dimensions a flattened equivalent of this space would have.
- Parameters:
space – The space to return the number of dimensions of the flattened spaces
- Returns:
The number of dimensions for the flattened spaces
- Raises:
NotImplementedError – if the space is not defined in
gym.spaces.ValueError – if the space cannot be flattened into a
gymnasium.spaces.Box
- utils.unflatten(x: ndarray[Any, dtype[Any]] | Dict[str, Any] | Tuple[Any, ...] | GraphInstance) T#
Unflatten a data point from a space.
- Parameters:
space – The space used to unflatten
xx – The array to unflatten
- Returns:
A point with a structure that matches the space.
- Raises:
NotImplementedError – if the space is not defined in
gymnasium.spaces.