Tiger

One recorded episode planned by PFT-DPW, replayed in 3D. Drag to orbit, scroll to zoom, and use the bar to play, scrub and switch camera.

The two-door POMDP: one door hides a tiger, the other hides a prize. Listening costs 1 but is only 85 % accurate, so the whole problem is deciding how much evidence to buy before committing.

Use it as the first check on any new planner. A planner that opens a door immediately, or that listens forever, is broken in a way you can see in three episodes.

What the agent sees and does

  • State — one of the strings "tiger_left", "tiger_right".

  • Actions (discrete) — "listen", "open_left", "open_right".

  • Observations (discrete) — "hear_left", "hear_right", "hear_nothing". Listening returns the correct side with probability 0.85. Opening a door always returns "hear_nothing"; conversely "hear_nothing" never follows a listen.

Formal definition

The environment is the POMDP \(\langle S, A, Z, T, O, R, b_0, \gamma \rangle\).

State space. Two doors, with the tiger behind one: \(\ell\) = tiger_left (behind the left door), \(r\) = tiger_right (behind the right door).

\[S = \{\ell,\; r\}\]

Action space

\[A = \{\textsf{listen},\; \textsf{open\_left},\; \textsf{open\_right}\}\]

\(\textsf{listen}\) hears which side the tiger is on, with noise; \(\textsf{open\_left}\) and \(\textsf{open\_right}\) open that door.

Observation space

\[Z = \{\textsf{hear\_left},\; \textsf{hear\_right},\; \textsf{hear\_nothing}\}\]

\(\textsf{hear\_left}\) and \(\textsf{hear\_right}\) say which side the tiger was heard on; \(\textsf{hear\_nothing}\) follows opening a door.

Transition model. Listening leaves the tiger where it is; opening either door places it behind the left or right door with probability 1/2 each, independent of where it was.

\[\begin{split}T(s' \mid s, \textsf{listen}) &= \mathbb{1}[s' = s] \\ T(s' \mid s, \textsf{open\_left}) = T(s' \mid s, \textsf{open\_right}) &= \tfrac{1}{2}, \quad s' \in S\end{split}\]

Observation model. Conditioned on the successor state, as everywhere in this codebase.

\[\begin{split}O(\textsf{hear\_left} \mid \ell, \textsf{listen}) = O(\textsf{hear\_right} \mid r, \textsf{listen}) &= 0.85 \\ O(\textsf{hear\_right} \mid \ell, \textsf{listen}) = O(\textsf{hear\_left} \mid r, \textsf{listen}) &= 0.15 \\ O(\textsf{hear\_nothing} \mid s', a) &= 1, \quad a \neq \textsf{listen}\end{split}\]

Note the two halves do not overlap: \(\textsf{hear\_nothing}\) has probability zero under \(\textsf{listen}\), and the directional observations have probability zero under either open action.

Reward function. Paid on the state the action is taken from, so \(R\) does not depend on \(s'\).

\[\begin{split}R(s, \textsf{listen}) &= -1 \\ R(s, \textsf{open\_left}) &= \begin{cases} -100 & s = \ell \\ +10 & s = r \end{cases} \\ R(s, \textsf{open\_right}) &= \begin{cases} -100 & s = r \\ +10 & s = \ell \end{cases}\end{split}\]

giving \(R \in [-100, 10]\).

Initial belief

\[b_0(\ell) = b_0(r) = \tfrac{1}{2}\]

with the initial observation fixed at \(\textsf{hear\_nothing}\).

Discount. \(\gamma \in [0, 1]\) — the required discount_factor argument; the class has no default.

Terminal set. \(S_T = \emptyset\). No state ends an episode, so the horizon is whatever the caller sets.

Rewards

Event

Reward

Listen

-1.0

Open the correct door

+10.0

Open the wrong door

-100.0

reward_range is (-100.0, 10.0). The asymmetry is the point: at a discount factor near 1 the optimal policy listens several times before acting.

Key settings

discount_factor is the only constructor argument that changes the problem, and it is required — there is no default. The 0.85 listening accuracy and the three rewards are constants in the class, not arguments.

An episode never ends on its own: is_terminal always returns False, and opening a door places the tiger behind either door with probability 1/2, independent of where it was. Episode length comes from the horizon the caller sets.

Can I use?

TigerPOMDP

Discrete

Continuous

State

✔️

❌

Action

✔️

❌

Observation

✔️

❌

Also supports

Native C++ backend

❌

Vectorized (torch) model

✔️ TigerVectorizedModel

In the get_environment registry

✔️

Optional dependencies

None

Example

from POMDPPlanners.environments.tiger_pomdp import TigerPOMDP

env = TigerPOMDP(discount_factor=0.95)

state = env.initial_state_dist().sample(1)[0]
# With n_samples=1 these return the value itself, not a list of one.
observation = env.sample_observation(state, "listen")
print(state, observation, env.reward(state, "listen"))

There is also a batched torch model, POMDPPlanners.environments.tiger_pomdp.tiger_pomdp_vectorized_model.TigerVectorizedModel, for the vectorized planners.

Parameters

class POMDPPlanners.environments.tiger_pomdp.TigerPOMDP(discount_factor, name='TigerPOMDP', output_dir=None, debug=False, use_queue_logger=False)[source]

Bases: DiscreteActionsEnvironment

Tiger POMDP environment implementation.

This is the classic Tiger problem where an agent must decide which door to open to find treasure while avoiding the tiger. The agent can listen for acoustic cues but receives noisy observations.

Problem Structure: - States: tiger_left, tiger_right (tiger’s location) - Actions: listen, open_left, open_right - Observations: hear_left, hear_right, hear_nothing - Rewards: listen(-1), correct_door(+10), wrong_door(-100)

Parameters:
states

List of possible states

actions

List of possible actions

observations

List of possible observations

Example

>>> import numpy as np
>>> np.random.seed(42)  # For reproducible results
>>>
>>> # Initialize environment
>>> tiger = TigerPOMDP(discount_factor=0.95)
>>>
>>> # Get initial state and actions
>>> initial_state = tiger.initial_state_dist().sample()[0]
>>> actions = tiger.get_actions()
>>>
>>> # Sample complete step using convenience method
>>> action = actions[0]
>>> next_state, observation, reward = tiger.sample_next_step(initial_state, action)
>>>
>>> # Check terminal condition
>>> tiger.is_terminal(initial_state)
False
compute_metrics(histories)[source]

Compute the Tiger metrics, always reporting every declared name.

The shared aggregator omits a metric no episode reported, which happens for an episode with no recorded steps. Tiger has always reported both metrics as 0.0 in that case, so the declared names are filled rather than dropped.

Parameters:

histories (List[History]) – List of simulation histories.

Return type:

List[MetricValue]

Returns:

One MetricValue per declared metric name, in declaration order.

Raises:

ValueError – If histories is empty, or if an episode ran without being measured. See compute_metrics().

episode_visualizer()[source]

Return the visualizer that writes this environment’s traces.

Return type:

TigerVisualizer

get_actions()[source]

Get all possible actions in the discrete action space.

Return type:

List[Any]

Returns:

List containing all valid actions that can be executed

Note

Subclasses must implement this method to enumerate all possible actions. This is used by planning algorithms that need to iterate over actions.

get_metric_specs()[source]

Declare the Tiger metrics derived from the per-step channels.

Return type:

List[StepInfoMetric]

Returns:

Specs for task_completion_rate (the last step’s door choice) and average_listens (how often the agent listened per episode).

hash_action(action)[source]

Return a hashable key consistent with action equality.

Used by tree-search planners to index action children of a belief node in O(1). The returned key MUST satisfy:

action_a == action_b   (per env's notion of equality)
==> hash_action(action_a) == hash_action(action_b)

Subclasses with non-hashable actions (e.g. np.ndarray) must override to return a hashable surrogate (tobytes() is the standard choice for ndarray actions, which mirrors the np.array_equal semantics used by the linear-scan fallback).

Parameters:

action (Any) – Action to hash.

Return type:

Hashable

Returns:

A hashable key derived from action.

initial_observation_dist()[source]

Get the initial observation distribution.

Return type:

Distribution

Returns:

Distribution over initial observations

Note

Subclasses must implement this method to define initial observations.

initial_state_dist()[source]

Get the initial state distribution.

Return type:

Distribution

Returns:

Distribution over initial states

Note

Subclasses must implement this method to define the starting distribution.

is_equal_observation(observation1, observation2)[source]

Check if two observations are equal.

Parameters:
  • observation1 (Any) – First observation to compare

  • observation2 (Any) – Second observation to compare

Return type:

bool

Returns:

True if observations are considered equal, False otherwise

Note

Subclasses must implement this method to define observation equality. This is particularly important for discrete observation spaces.

is_terminal(state)[source]

Check if a state is terminal.

Parameters:

state (str) – State to check for terminal condition

Return type:

bool

Returns:

True if the state is terminal, False otherwise

Note

Subclasses must implement this method to define terminal conditions.

observation_log_probability(next_state, action, observations)[source]

Log-probability of each candidate observation under (next_state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate observations. Subclasses must implement.

Return type:

ndarray

Parameters:
  • next_state (str)

  • action (str)

observation_log_probability_per_state(next_states, action, observation)[source]

Log-probability of one observation under each candidate next-state.

Used by particle filters: given N candidate next-states and ONE observation, return N log-likelihoods.

The default implementation falls back to a per-state Python loop delegating to observation_log_probability(). Native-backed envs (those whose observation kernel exposes batch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.

Parameters:
  • next_states (Union[ndarray, Sequence[Any]]) – A sequence (length N) or ndarray of shape (N, *dim) of candidate next-states.

  • action (str) – The action that was executed.

  • observation (str) – A single observation.

Return type:

ndarray

Returns:

ndarray of shape (N,) with log-probabilities or log-PDFs.

reward(state, action, next_state=None)[source]

Calculate the immediate reward for a state-action(-next_state) tuple.

next_state is the realised post-transition state when known (e.g. threaded by sample_next_step()), allowing rewards that depend on stochastic transition outcomes to use the same draw as the trajectory instead of resampling. Subclasses whose reward is a pure function of (state, action) may ignore it; subclasses whose reward depends on the realised next state (collision penalties, win bonuses) should consume it when provided and fall back to drawing/computing one when None.

Parameters:
  • state (str) – Current state.

  • action (str) – Action executed from state.

  • next_state (Any) – Realised next state, or None if the caller did not pre-sample one. Defaults to None.

Return type:

float

Returns:

Immediate reward value.

Note

Subclasses must implement this method to define reward structure.

reward_batch(states, action, next_states=None)[source]

Calculate rewards for a batch of states given a single action.

Provides a loop-based default that subclasses can override with vectorized numpy implementations for better performance.

Parameters:
  • states (Union[ndarray, Sequence[Any]]) – Sequence of states of length N.

  • action (str) – Action executed from each state.

  • next_states (Union[ndarray, Sequence[Any], None]) – Optional realised next states (length N) threaded through to reward(). Defaults to None.

Return type:

ndarray

Returns:

1-D array of reward values with shape (N,).

sample_next_state(state, action, n_samples=1)[source]

Sample one or more next states for (state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single next state of the env’s native type. When n_samples > 1: an array-like of length n_samples (numeric envs return np.ndarray of shape (n_samples, *dim); structured envs return List[T]).

Return type:

When n_samples == 1

Parameters:
sample_next_state_batch(states, action)[source]

Sample one next state per input state, all under the same action.

Used by particle filters: given N current particles and one action, draw N next states (one per particle) in a single vectorized call.

The default implementation falls back to a per-state Python loop delegating to sample_next_state(). Native-backed envs (those whose state-transition kernel exposes batch_sample(states_array)) should override to avoid the loop.

Parameters:
  • states (Union[ndarray, Sequence[Any]]) – A sequence (length N) or ndarray of shape (N, *dim) of input particles.

  • action (str) – A single action to apply to every particle.

Returns:

np.ndarray of shape (N, *dim). For structured envs (Tiger strings, Pacman tuples): a list of length N.

Return type:

List[str]

sample_observation(next_state, action, n_samples=1)[source]

Sample one or more observations for (next_state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single observation. When n_samples > 1: an array-like of length n_samples.

Return type:

When n_samples == 1

Parameters:
  • next_state (str)

  • action (str)

  • n_samples (int)

step_info(state, action, next_state)[source]

Report which door was opened and whether the agent listened.

Parameters:
  • state (Any) – The state the step was taken from, i.e. where the tiger is.

  • action (Any) – The action taken, or None on the terminal step.

  • next_state (Any) – Unused; the Tiger transition carries no extra signal.

Return type:

Dict[str, float]

Returns:

The correct_door_opened and listened indicators.

transition_log_probability(state, action, next_states)[source]

Log-probability of each candidate next state under (state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate next states. Subclasses must implement.

Return type:

ndarray

Parameters:

See also