smartgrid.observation.base_observation.Observation

class smartgrid.observation.base_observation.Observation[source]

Bases: BaseObservation, ABC

Represents a merged observation of both global and local metrics.

This class is only used for typing purposes; please see the ObservationManager for the actual, dynamically-created, class.

__init__() None

Methods

__init__()

asdict()

Return the Observation as a dictionary.

create(global_obs, local_obs)

fields()

Returns the names of fields that compose an Observation.

get_global_observation()

get_local_observation()

space(world, agent)

Describe the space in which Observations take their values.

asdict() Dict[str, Any]

Return the Observation as a dictionary.

Fields can be excluded by setting the metadata include custom property to False, such as: my_field: Any = field(metadata={'include': False}).

Parameters:

self – An instance of observation.

Returns:

The observation represented as a dictionary, with the fields’ names as keys and the fields’ values as values, in the order of definition.

classmethod fields() Tuple[str]

Returns the names of fields that compose an Observation.

Fields can be excluded by setting the metadata include custom property to False, such as: my_field: Any = field(metadata={'include': False}).

Parameters:

cls – Either the class itself, or an instance of the class; this method supports both. In other words, it can be used as Observation.fields(), or obs = Observation(...); obs.fields().

Returns:

The fields’ names as a tuple, in their order of definition.

classmethod space(world: World, agent: Agent) Space

Describe the space in which Observations take their values.

This method is useful if an algorithm has assumptions or requirements on the observation space. For example, values can be interpolated, by knowing their original domain.

We currently use ratios in [0, 1] for each metric of observations. This makes it easier for learning algorithms (avoids perceiving a given dimension as more important than another because of an extended range). It also means that the world and agent parameters do not influe on the space (they could be None).

In the future, we could use the true ranges from the agent’s AgentProfile and let users convert these observations to [0, 1] when necessary. This would provide more useful information, e.g., the actual battery storage in [0, capacity], rather than a ratio, or the actual hour in [0, 23] rather than a value (h % 24) / 24, which is hard to interpret for human users.

Parameters:
  • world – The World instance in which observations will be computed. Currently unused.

  • agent – The Agent instance of the agent for which we compute observations. Currently unused.

Return type:

gymnasium.spaces.Box

Returns:

A gym Box, whose low field indicates the minimum value of each element of the observation vector. Similarly, the high field indicates the maximum value of each element, such that each element i of the vector is contained between low[i] and high[i]. The Box’s shape is the number of fields.