ethicalgardeners.observation.PartialObservation

class ethicalgardeners.observation.PartialObservation(obs_range=1)[source]

Bases: ObservationStrategy

Strategy that provides agents with a limited view around their position.

This strategy simulates limited perception by only showing agents a square area centered on their current position.

Each cell in the visible area is represented as a vector of features:

  • Cell type (normalized): Value between 0 and 1 representing the type of cell (CellType) divided by the number of cell types.

  • Pollution level (normalized): Value between 0 and 1 representing the pollution level in the cell, normalized between the minimum and maximum pollution levels in the grid.

  • Flower presence and type (normalized): 0 if no flower is present, otherwise a value between 0 and 1 representing the flower type + 1 divided by the number of flower types.

  • Flower growth stage (normalized): 0 if no flower is present, otherwise a value between 0 and 1 representing the current growth stage of the flower + 1 divided by the total number of growth stages + 1.

  • Agent presence (normalized): 0 if no agent is present, otherwise a value between 0 and 1 representing the index of the agent in the grid world + 1 divided by the total number of agents.

  • Agent’s X position (normalized): Value between 0 and 1 representing the agent’s X position normalized by the grid width minus 1.

  • Agent’s Y position (normalized): Value between 0 and 1 representing the agent’s Y position normalized by the grid height minus 1.

obs_range

The visibility range in cells around the agent’s position.

Type:

int

observation_shape

The dimensions of the observation (2*obs_range+1, 2*obs_range+1, FEATURES_PER_CELL).

Type:

tuple

__init__(obs_range=1)[source]

Create the partial observation strategy.

Parameters:

obs_range (int, optional) – The number of cells visible in each direction from the agent.

Methods

__init__([obs_range])

Create the partial observation strategy.

get_observation(grid_world, agent)

Generate a partial observation centered on the agent's position.

observation_space(agent)

Define the observation space as a Box with dimensions based on the range.

get_observation(grid_world, agent: Agent)[source]

Generate a partial observation centered on the agent’s position.

Each cell in the visible area is represented with multiple features. Areas outside the grid boundaries appear as zeros in the observation.

Parameters:
  • grid_world (GridWorld) – The current state of the grid.

  • agent (Agent) – The agent for which to generate the observation.

Returns:

A 3D array containing the visible portion of the grid with all features.

Return type:

numpy.ndarray

observation_space(agent: Agent)[source]

Define the observation space as a Box with dimensions based on the range.

Parameters:

agent (Agent) – The agent for which to define the observation space.

Returns:

A box space with dimensions based on the visibility range and features per cell.

Return type:

gymnasium.spaces.Box