Skip to content

Observations

Observation functions: how a State is turned into what the agent sees.

Pick one and pass it as observation_fn to navix.make / Environment.create. Two families:

  • Fully observable (categorical, symbolic, rgb) - the whole height x width grid, always the same orientation.
  • First person / POMDP (categorical_first_person, symbolic_first_person, rgb_first_person) - cropped to a (2 * RADIUS + 1) square with the player at the bottom-centre facing up, so the observation is egocentric and rotation-invariant. Cells the player cannot see (behind a wall, outside the view cone) are masked to a "not seen" fill.

Three encodings, shared by both families:

  • categorical - one integer per cell, the entity's tag (see entities.EntityIds); shape (H, W).
  • symbolic - three integers per cell (tag, colour, state) as in MiniGrid; shape (H, W, 3), uint8.
  • rgb - a rendered image, uint8, each cell a TILE_SIZE x TILE_SIZE sprite; shape (H * TILE_SIZE, W * TILE_SIZE, 3).

Environment infers the matching observation_space for these built-in functions; a custom observation_fn needs observation_space passed explicitly.

Half-size of the first-person view: those observations are (2 * RADIUS + 1) cells on a side (default 3 -> a 7x7 window). Change it with set_radius before building an environment - Environment reads it when it computes observation_space.

The whole grid as one integer per cell: the tag of whatever entity occupies it (0 for empty floor, -1-marked walls become their tag via entities.EntityIds), fully observable.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
Array Array

i32[H, W] (H = env.height, W = env.width). Entities

Array

that have been picked up (off-grid) do not appear.

The egocentric version of categorical: one tag per cell, cropped to a (2 * RADIUS + 1) square around the player and rotated so the player sits at the bottom-centre facing up. Cells outside the view cone or occluded by a wall are set to 0 (not seen).

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
Array Array

i32[2 * RADIUS + 1, 2 * RADIUS + 1].

The empty observation - shape f32[0]. Use it when the agent should learn from state/reward directly (e.g. debugging, or a hand-coded policy) and never looks at observation.

Parameters:

Name Type Description Default
state State

the current state (ignored).

required

Returns:

Name Type Description
Array Array

an empty f32[0] array.

The whole grid rendered as an RGB image, fully observable. Each cell is a TILE_SIZE x TILE_SIZE sprite (walls, floor grid lines, entities) drawn from state.cache.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
Array Array

u8[H * TILE_SIZE, W * TILE_SIZE, 3] (H = env.height,

Array

W = env.width).

The egocentric version of rgb: the rendered image cropped to a (2 * RADIUS + 1)-tile square around the player and rotated so the player faces up. Out-of-view / occluded tiles are filled with the dimmed "unseen" grey.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
Array Array

u8[(2 * RADIUS + 1) * TILE_SIZE, (2 * RADIUS + 1) * TILE_SIZE, 3].

Sets the module-global RADIUS used by every *_first_person observation. Call it before navix.make so the environment's observation_space picks up the new size.

Parameters:

Name Type Description Default
radius int

the new half-window size; the view becomes (2 * radius + 1) cells square.

required

MiniGrid's symbolic encoding: three integers per cell, (object_tag, colour_index, state), fully observable. object_tag is the entity id (empty floor and walls have their own tags); colour_index indexes the palette (0 when the entity has no colour); the third channel is the entity's own discrete state - a door's open/closed/locked, or the player's facing direction.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
Array Array

u8[H, W, 3] (H = env.height, W = env.width).

The egocentric version of symbolic: the (tag, colour, state) triple per cell, cropped to a (2 * RADIUS + 1) square around the player and rotated so the player faces up. Out-of-view / occluded cells are filled with the wall symbol; the player's own cell shows what it is carrying.

Parameters:

Name Type Description Default
state State

the current state.

required

Returns:

Name Type Description
Array Array

u8[2 * RADIUS + 1, 2 * RADIUS + 1, 3].