colosseum.emission_maps.state_info

 1import dataclasses
 2from typing import TYPE_CHECKING
 3
 4import numpy as np
 5
 6from colosseum.emission_maps.base import EmissionMap
 7
 8if TYPE_CHECKING:
 9    from colosseum.mdp import NODE_TYPE
10
11
12class StateInfo(EmissionMap):
13    """
14    The `StateInfo` emission map creates a non-tabular vector containing uniquely identifying information about the
15    state.
16    """
17
18    @property
19    def is_tabular(self) -> bool:
20        return False
21
22    def node_to_observation(
23        self, node: "NODE_TYPE", in_episode_time: int = None
24    ) -> np.ndarray:
25        if self._mdp.is_episodic():
26            in_episode_time = 0 if in_episode_time is None else in_episode_time
27            return np.array((in_episode_time, *dataclasses.astuple(node))).astype(
28                np.float32
29            )
30        return np.array(dataclasses.astuple(node)).astype(np.float32)
class StateInfo(colosseum.emission_maps.base.EmissionMap):
13class StateInfo(EmissionMap):
14    """
15    The `StateInfo` emission map creates a non-tabular vector containing uniquely identifying information about the
16    state.
17    """
18
19    @property
20    def is_tabular(self) -> bool:
21        return False
22
23    def node_to_observation(
24        self, node: "NODE_TYPE", in_episode_time: int = None
25    ) -> np.ndarray:
26        if self._mdp.is_episodic():
27            in_episode_time = 0 if in_episode_time is None else in_episode_time
28            return np.array((in_episode_time, *dataclasses.astuple(node))).astype(
29                np.float32
30            )
31        return np.array(dataclasses.astuple(node)).astype(np.float32)

The StateInfo emission map creates a non-tabular vector containing uniquely identifying information about the state.

is_tabular: bool
Returns
  • bool: The boolean for whether the emission map is tabular.
23    def node_to_observation(
24        self, node: "NODE_TYPE", in_episode_time: int = None
25    ) -> np.ndarray:
26        if self._mdp.is_episodic():
27            in_episode_time = 0 if in_episode_time is None else in_episode_time
28            return np.array((in_episode_time, *dataclasses.astuple(node))).astype(
29                np.float32
30            )
31        return np.array(dataclasses.astuple(node)).astype(np.float32)
Returns
  • np.ndarray: The non-tabular representation corresponding to the state given in input. Episodic MDPs also requires the current in-episode time step.