spaces
base
- class Space[source]
Bases:
ABC
Base class of all state, action, and init spaces in Pyrado
- property bound_abs_up: ndarray
Get the upper bound in terms of absolute values.
- bound_lo: ndarray
- bound_up: ndarray
- property bounds: Tuple[ndarray, ndarray]
Get the lower (first element) and upper bound (second element) of the space.
- static cat(spaces: Union[list, tuple])[source]
Concatenate a sequence of spaces in the given order. This creates a new Space object.
- Parameters:
spaces – spaces to concatenate
- Returns:
concatenated space
- abstract contains(cand: ndarray, verbose: bool = False) bool [source]
Check if a candidate element is in the state.
- Parameters:
cand – candidate to check if it is an element of the space
verbose – if True details are be printed in case the candidate is not an element of the space
- Returns:
bool value
- create_mask(*idcs) ndarray [source]
Create a mask selecting the given indices from this space. Every index should be a number or a name in the space’s labels.
- Parameters:
idcs – index list, which can either be varargs or a single iterable
- Returns:
boolean mask array with 1 at each index specified by the indices or labels
- property ele_dim: int
Get the dimension of an element of the space.
- property flat_dim: int
Get the dimension of the flattened space.
- property labels: Optional[ndarray]
Get the labels for space entries, or None if not supported.
- abstract project_to(ele: ndarray) ndarray [source]
Project an into the box space by clipping, or do nothing of it already is.
- Parameters:
ele – element from outside or inside of the box space
- Returns:
element within the box space (at the border if it has been outside of the space before the projection).
- abstract sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space
- abstract property shape: tuple
Get the shape of the full space.
box
- class BoxSpace(bound_lo: Union[float, List[Union[int, float]], ndarray], bound_up: Union[float, List[Union[int, float]], ndarray], shape: Optional[Union[tuple, int]] = None, labels: Optional[Sequence[str]] = None)[source]
Bases:
Space
Multidimensional box space. This class can also be used to describe a sphere.
Constructor
- Parameters:
bound_lo – array_like containing the minimal values for each dimension of the space
bound_up – array_like containing the maximal values for each dimension of the space
shape – tuple specifying the shape, useful if all lower and upper bounds are identical
labels – label for each dimension of the space (e.g. list of strings)
- bound_lo: ndarray
- bound_up: ndarray
- static cat(spaces: Union[list, tuple])[source]
Concatenate BoxSpaces.
- Parameters:
spaces – list or tuple of spaces
Note
This function does not check if the dimensions of the BoxSpaces are correct!
- contains(cand: ndarray, verbose: bool = False) bool [source]
Check if a candidate element is in the state.
- Parameters:
cand – candidate to check if it is an element of the space
verbose – if True details are be printed in case the candidate is not an element of the space
- Returns:
bool value
- property labels: ndarray
Get the labels for space entries, or None if not supported.
- project_to(ele: ndarray) ndarray [source]
Project an into the box space by clipping, or do nothing of it already is.
- Parameters:
ele – element from outside or inside of the box space
- Returns:
element within the box space (at the border if it has been outside of the space before the projection).
- sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space
- property shape: tuple
Get the shape of the full space.
- class InfBoxSpace(shape: Union[tuple, int], labels: Optional[Sequence[str]] = None)[source]
Bases:
BoxSpace
Multidimensional box space where all limits are \(\pm \inf\).
Constructor
- Parameters:
shape – tuple specifying the shape, useful if all lower and upper bounds are identical
labels – label for each dimension of the space (e.g. list of strings)
- bound_lo: ndarray
- bound_up: ndarray
compound
- class CompoundSpace(spaces: Sequence[Space])[source]
Bases:
Space
Space consisting of other spaces
Constructor
- Parameters:
spaces – list or tuple of spaces to sample from randomly
- bound_lo: ndarray
- bound_up: ndarray
- static cat(spaces: Union[list, tuple])[source]
Concatenate a sequence of spaces in the given order. This creates a new Space object.
- Parameters:
spaces – spaces to concatenate
- Returns:
concatenated space
- contains(cand: ndarray, verbose: bool = False) bool [source]
Check if a candidate element is in the state.
- Parameters:
cand – candidate to check if it is an element of the space
verbose – if True details are be printed in case the candidate is not an element of the space
- Returns:
bool value
- property flat_dim: int
Get the dimension of the flattened space.
- project_to(ele: ndarray)[source]
Project an into the box space by clipping, or do nothing of it already is.
- Parameters:
ele – element from outside or inside of the box space
- Returns:
element within the box space (at the border if it has been outside of the space before the projection).
- sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space
- property shape
Get the shape of the full space.
discrete
- class DiscreteSpace(eles: Union[ndarray, list], labels: Optional[Sequence[str]] = None)[source]
Bases:
Space
Discrete space implemented as a ndarray containing all possible integer-valued elements (unsorted)
Constructor
- Parameters:
eles – N x D array of all actions, where N is the number of actions and D is the dimension of each action
labels – label element of the space. This is useful for giving the states and actions names to later identify them (e.g. for plotting).
- property bound_abs_up: ndarray
Get the upper bound in terms of absolute values.
- bound_lo: ndarray
- bound_up: ndarray
- static cat(spaces: Union[list, tuple])[source]
Concatenate multiple instances of DiscreteSpace.
Note
This function does not check if the dimensions of the BoxSpaces are correct!
- Parameters:
spaces – list or tuple of spaces
- contains(cand: ndarray, verbose: bool = False) bool_ [source]
Check if a candidate element is in the state.
- Parameters:
cand – candidate to check if it is an element of the space
verbose – if True details are be printed in case the candidate is not an element of the space
- Returns:
bool value
- property flat_dim: int
Get the dimension of the flattened space.
- property labels: ndarray
Get the labels for space entries, or None if not supported.
- property num_ele: int
- project_to(ele: ndarray) ndarray [source]
Project an into the box space by clipping, or do nothing of it already is.
- Parameters:
ele – element from outside or inside of the box space
- Returns:
element within the box space (at the border if it has been outside of the space before the projection).
- sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space
- property shape: tuple
Get the shape of the full space.
empty
- class EmptySpace[source]
Bases:
Space
A space with no content
- bound_lo: ndarray
- bound_up: ndarray
- property bounds: tuple
Get the lower (first element) and upper bound (second element) of the space.
- static cat(spaces: Union[list, tuple])[source]
Concatenate a sequence of spaces in the given order. This creates a new Space object.
- Parameters:
spaces – spaces to concatenate
- Returns:
concatenated space
- contains(cand: ndarray, verbose: bool = False) bool [source]
Check if a candidate element is in the state.
- Parameters:
cand – candidate to check if it is an element of the space
verbose – if True details are be printed in case the candidate is not an element of the space
- Returns:
bool value
- property labels: (<class 'numpy.ndarray'>, None)
Get the labels for space entries, or None if not supported.
- project_to(ele: ndarray) ndarray [source]
Project an into the box space by clipping, or do nothing of it already is.
- Parameters:
ele – element from outside or inside of the box space
- Returns:
element within the box space (at the border if it has been outside of the space before the projection).
- sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space
- property shape: tuple
Get the shape of the full space.
polar
- class Polar2DPosSpace(bound_lo: Union[List[Union[int, float]], ndarray], bound_up: Union[List[Union[int, float]], ndarray], shape: Optional[Union[tuple, int]] = None, labels: Optional[Sequence[str]] = None)[source]
Bases:
BoxSpace
Samples positions on a 2-dim torus, i.e. the area between two concentric circles. Can also be a section of a 2-dim torus, i.e. not a full circle.
Constructor
- Parameters:
bound_lo – minimal distance and the minimal angle (polar coordinates)
bound_up – maximal distance and the maximal angle (polar coordinates)
shape – tuple specifying the shape, useful if all lower and upper bounds are identical
labels – label for each dimension of the space
- bound_lo: ndarray
- bound_up: ndarray
- contains(cand: ndarray, verbose: bool = False) bool [source]
Check if a candidate element is in the state.
- Parameters:
cand – candidate to check if it is an element of the space
verbose – if True details are be printed in case the candidate is not an element of the space
- Returns:
bool value
- sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space
- class Polar2DPosVelSpace(bound_lo: Union[float, List[Union[int, float]], ndarray], bound_up: Union[float, List[Union[int, float]], ndarray], shape: Optional[Union[tuple, int]] = None, labels: Optional[Sequence[str]] = None)[source]
Bases:
BoxSpace
Samples positions on a 2-dim torus, i.e. the area between 2 circles augmented with cartesian velocities. Can also be a section of a 2-dim torus, i.e. not a full circle.
Constructor
- Parameters:
bound_lo – minimal distance, the minimal angle, and the 2D minimal cartesian initial velocity
bound_up – maximal distance, the maximal angle, and the 2D minimal cartesian initial velocity
shape – tuple specifying the shape, useful if all lower and upper bounds are identical
labels – label for each dimension of the space
- bound_lo: ndarray
- bound_up: ndarray
- contains(cand: ndarray, verbose: bool = False) bool [source]
Check if a candidate element is in the state.
- Parameters:
cand – candidate to check if it is an element of the space
verbose – if True details are be printed in case the candidate is not an element of the space
- Returns:
bool value
- sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space
singular
- class SingularStateSpace(fixed_state: ndarray, labels: Optional[Sequence[str]] = None)[source]
Bases:
BoxSpace
Space which always returns the same initial state (trivial space)
Constructor
- Parameters:
fixed_state – the initial state
labels – label for each dimension of the space
- bound_lo: ndarray
- bound_up: ndarray
- sample_uniform(concrete_inf: float = 1000000.0) ndarray [source]
Sample an element of this space using a uniform distribution.
- Parameters:
concrete_inf – It’s impossible to sample uniform from infinite bounds. As a workaround, infinite bounds are replaced with this value.
- Returns:
element within the space