smarts.env.gymnasium.wrappers.metric.utils module
- class smarts.env.gymnasium.wrappers.metric.utils.SlidingWindow(size: int)[source]
A sliding window which moves to the right by accepting new elements. The maximum value within the sliding window can be queried at anytime by calling the max() method.
- smarts.env.gymnasium.wrappers.metric.utils.add_dataclass(first: T, second: T) T [source]
Sums the fields of two dataclass objects.
- Parameters:
first (T) – First dataclass object.
second (T) – Second dataclass object.
- Returns:
New summed dataclass object.
- Return type:
T
- smarts.env.gymnasium.wrappers.metric.utils.divide(value: int | float, divider: int | float) float [source]
Division operation.
- Parameters:
value (Union[int, float]) – Numerator
divider (Union[int, float]) – Denominator
- Returns:
Numerator / Denominator
- Return type:
float
- smarts.env.gymnasium.wrappers.metric.utils.multiply(value: int | float, multiplier: int | float) float [source]
Multiplication operation.
- Parameters:
value (Union[int, float]) – Value
multiplier (Union[int, float]) – Multiplier
- Returns:
Value x Multiplier
- Return type:
float
- smarts.env.gymnasium.wrappers.metric.utils.nearest_waypoint(matrix: MaskedArray, points: ndarray, radius: float = 1) Tuple[Tuple[int, int], int | None] [source]
- Returns
the matrix index of the nearest waypoint to the ego, which has a nearby point.
the points index which is nearby the nearest waypoint to the ego.
Nearby is defined as a point within radius of a waypoint.
- Parameters:
matrix (np.ma.MaskedArray) – Waypoints matrix.
points (np.ndarray) – Points matrix.
radius (float, optional) – Nearby radius. Defaults to 2.
- Returns:
matrix index of shape (a,b) and scalar point index.
- Return type:
Tuple[Tuple[int, int], Optional[int]]
- smarts.env.gymnasium.wrappers.metric.utils.op_dataclass(first: T, second: int | float, op: Callable[[int | float, int | float], float]) T [source]
Performs operation op on the fields of the source dataclass object.
- Parameters:
first (T) – The source dataclass object.
second (Union[int, float]) – Value input for the operator.
op (Callable[[Union[int, float], Union[int, float]], float]) – Operation to be performed.
- Returns:
A new dataclass object with operation performed on all of its fields.
- Return type:
T