data.transformation#
The transformation module allows the transformation of SoulsGym envs observations.
- class soulsai.data.transformation.GameStateTransformer(game_id: str = 'DarkSoulsIII', boss_id: str = 'iudex')#
Transform
SoulsGymobservations into a numerical representation.The transformer allows the consistent binning of animations and encodes pose data into a more suitable representation.
- transform(obs: Dict) ndarray#
Transform a game observation with a stateful conversion.
Warning
This function is assumed to be called with successive
SoulsGymobservations. If the next observation is not part of the same trajectory,GameStateTransformer.reset()has to be called.- Parameters:
obs – The input observation.
- Returns:
A transformed observation as a numerical array.
- stateless_transform(obs: Dict) ndarray#
Transform a game observation with a stateless conversion.
Boss and player animations are filtered and binned, but not accumulated correctly.
- Parameters:
obs – The input observation.
- Returns:
A transformed observation as a numerical array.
- reset()#
Reset the stateful attributed of the transformer.
- boss_animation_transform(obs: Dict) Tuple[ndarray, float]#
Transform the observation’s boss animation into a one-hot encoding and a duration.
Since we are binning the boss animations, we have to sum the durations of binned animations. This requires the transformer to be stateful to keep track of previous animations.
Note
To correctly transform animations after an episode has finished, users have to call
GameStateTransformer.reset()in between.- Parameters:
obs – The input observation.
- Returns:
A tuple of the current animation as one-hot encoding and the animation duration.
- static filter_player_animation(animation: int) int#
Bin common player animations.
Player animations that essentially constitute the same state are binned into a single category to reduce the state space. The new labels are in the range of 1xx to avoid collisions with other animation labels.
- Parameters:
animation – Player animation ID.
- Returns:
The binned player animation.
- filter_boss_animation(animation: int) Tuple[int, bool]#
Bin boss movement animations into a single animation.
Boss animations that essentially constitute the same state are binned into a single category to reduce the state space. The new labels are in the range of 1xx to avoid collisions with other animation labels.
- Parameters:
animation – Boss animation ID.
- Returns:
The animation name and a flag set to True if it was binned (else False).
- soulsai.data.transformation.unique(seq: Iterable) List#
Create a list of unique elements from an iterable.
- Parameters:
seq – Iterable sequence.
- Returns:
The list of unique items.
- soulsai.data.transformation.wrap2pi(x: float) float#
Project an angle in radians to the interval of [-pi, pi].
- Parameters:
x – The angle in radians.
- Returns:
The angle restricted to the interval of [-pi, pi].
- soulsai.data.transformation.rad2vec(x: float) ndarray#
Convert an angle in radians to a [sin, cos] vector.
- Parameters:
x – The angle in radians.
- Returns:
The encoded orientation as [sin, cos] vector.