Rewards
Reward functions: the scalar reward for one transition.
An Environment's reward_fn has the signature shared with
navix.terminations and navix.events:
fn(prev_state: State, action: Array, state: State) -> Array
prev_stateis $s_t$,actionis $a_t$,stateis $s_{t+1}$. Some functions needprev_stateto reward a change this step; most only readstate.- The return is a scalar
f32[].Environment.reward_spacebounds it ([-1, 1]by default). Positive functions here return1.0on the rewarded event and0.0otherwise; the*_costfunctions return a small negative shaping term every step.
compose reduces several into one (summed by default). DEFAULT_TASK
is just on_goal_reached - +1 at the goal, no per-step shaping; add a
time_cost yourself if you want to reward faster solutions.
DEFAULT_TASK = on_goal_reached
module-attribute
The reward_fn an Environment uses unless overridden: +1.0 on
reaching the goal, 0.0 every other step - no per-step shaping. Compose
time_cost in yourself if you want to reward faster solutions.
action_cost(prev_state, action, new_state, cost=0.01)
Deprecated alias of time_cost.
It used to exempt the action at index 6 (done in
MINIGRID_ACTION_SET), but a reward function has no way to know
which action set an environment uses, so the exemption was
action-set-dependent and wrong for any non-default set. Every action
now costs cost - identical to time_cost - so use that instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
$s_t$ (unused). |
required |
action
|
Array
|
the integer action taken (unused). |
required |
new_state
|
State
|
$s_{t+1}$ (unused). |
required |
cost
|
float
|
the per-step penalty magnitude. Default |
0.01
|
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
|
compose(*reward_functions, operator=jnp.sum)
Combines several reward functions into one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*reward_functions
|
Callable
|
reward functions to combine, each
|
()
|
operator
|
Callable
|
reduces the stacked |
sum
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
a single |
Callable
|
function. |
free(prev_state, action, state)
Always 0.0 - the reward-free setting, for unsupervised or
exploration-driven training where only the transition dynamics
matter.
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
|
on_box_pickup(prev_state, action, state)
A reward function that returns 1 when any box is picked up this step, and 0 otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
Array
|
up, and 0 otherwise. |
on_door_done(prev_state, action, state)
A reward function that returns a positive value when the agent uses the action done in front of a door.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
on_door_open(prev_state, action, state)
A reward function that returns 1 when any door is opened this
step, and 0 otherwise - unlike on_door_done, no state.mission
target is needed; any door opening counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
Array
|
and 0 otherwise. |
on_goal_reached(prev_state, action, state)
A reward function that returns 1 when the goal is reached, and 0 otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
on_memory_success(prev_state, action, state)
Memory's reward: 1 if the player reached the target position,
0 otherwise (including on failure). Deliberately flat, not
MiniGrid's step-count-shaped 1 - 0.9 * (step_count / max_steps) -
matches navix's existing on_goal_reached convention, itself
already the same simplification versus real MiniGrid's Goal
reward, kept here for consistency rather than a one-off shaped
reward unique to this environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
on_ordered_doors_success(prev_state, action, state)
RedBlueDoors' reward: 1 if the blue door was opened this step
while red was already open, 0 otherwise (including the failure case
of opening blue first).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
on_put_near_success(prev_state, action, state)
PutNear's reward: 1 if the carried object was dropped within
Chebyshev distance 1 of the second mission target, 0 otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
on_target_done(prev_state, action, state)
GoToObject's reward: 1.0 if the done action was taken while
the player is orthogonally adjacent to the mission's target object
(facing it is not required; see events.on_target_done), else
0.0.
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
|
on_target_fetched(prev_state, action, state)
Fetch's reward: 1 if the mission's target object was the one
picked up this step, 0 otherwise (including picking up the wrong
one, which still ends the episode via terminations.
on_any_target_pickup).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A scalar array |
time_cost(prev_state, action, new_state, cost=0.01)
A flat -cost on every step. Compose it with a goal reward
(compose(on_goal_reached, time_cost)) to make shorter successful
episodes score higher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
$s_t$ (unused). |
required |
action
|
Array
|
the integer action taken (unused). |
required |
new_state
|
State
|
$s_{t+1}$ (unused). |
required |
cost
|
float
|
the per-step penalty magnitude. Default |
0.01
|
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
|
wall_hit_cost(prev_state, action, state, cost=0.01)
-cost on any step where the player moved into a wall this step
(detected via events.on_wall_hit), 0.0 otherwise. Opt-in shaping
for tasks that want to discourage bumping walls; same sign convention
as time_cost.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
$s_t$ (unused). |
required |
action
|
Array
|
the integer action taken (unused). |
required |
state
|
State
|
$s_{t+1}$ - read for the wall-hit event. |
required |
cost
|
float
|
the penalty magnitude on a wall hit. Default
|
0.01
|
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
|