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 wholeheight x widthgrid, 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 aTILE_SIZE x TILE_SIZEsprite; 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.
RADIUS = 3
module-attribute
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.
categorical(state)
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
|
|
Array
|
that have been picked up (off-grid) do not appear. |
categorical_first_person(state)
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
|
|
none(state)
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 |
rgb(state)
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
|
|
Array
|
|
rgb_first_person(state)
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
|
|
set_radius(radius)
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
|
required |
symbolic(state)
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
|
|
symbolic_first_person(state)
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
|
|