colosseum.emission_maps.one_hot_encoding

 1from typing import TYPE_CHECKING
 2
 3import numpy as np
 4
 5from colosseum.emission_maps.base import EmissionMap
 6
 7if TYPE_CHECKING:
 8    from colosseum.mdp import NODE_TYPE
 9
10
11class OneHotEncoding(EmissionMap):
12    """
13    The `OneHotEncoding` emission map creates a non-tabular vector filled with zero except the index corresponding to
14    the state.
15    """
16
17    @property
18    def is_tabular(self) -> bool:
19        return False
20
21    def node_to_observation(
22        self, node: "NODE_TYPE", in_episode_time: int = None
23    ) -> np.ndarray:
24        index = self._mdp.node_to_index[node]
25        obs = np.zeros(self._mdp.n_states, np.float32)
26        obs[index] = 1.0
27        return obs
class OneHotEncoding(colosseum.emission_maps.base.EmissionMap):
12class OneHotEncoding(EmissionMap):
13    """
14    The `OneHotEncoding` emission map creates a non-tabular vector filled with zero except the index corresponding to
15    the 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        index = self._mdp.node_to_index[node]
26        obs = np.zeros(self._mdp.n_states, np.float32)
27        obs[index] = 1.0
28        return obs

The OneHotEncoding emission map creates a non-tabular vector filled with zero except the index corresponding to the state.

is_tabular: bool
Returns
  • bool: The boolean for whether the emission map is tabular.
22    def node_to_observation(
23        self, node: "NODE_TYPE", in_episode_time: int = None
24    ) -> np.ndarray:
25        index = self._mdp.node_to_index[node]
26        obs = np.zeros(self._mdp.n_states, np.float32)
27        obs[index] = 1.0
28        return obs
Returns
  • np.ndarray: The non-tabular representation corresponding to the state given in input. Episodic MDPs also requires the current in-episode time step.