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).
Action space
\(\textsf{listen}\) hears which side the tiger is on, with noise; \(\textsf{open\_left}\) and \(\textsf{open\_right}\) open that door.
Observation space
\(\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.
Observation model. Conditioned on the successor state, as everywhere in this codebase.
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'\).
giving \(R \in [-100, 10]\).
Initial belief
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?
|
Discrete |
Continuous |
|---|---|---|
State |
✔️ |
❌ |
Action |
✔️ |
❌ |
Observation |
✔️ |
❌ |
Also supports |
|
|---|---|
Native C++ backend |
❌ |
Vectorized (torch) model |
✔️ |
In the |
✔️ |
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:
DiscreteActionsEnvironmentTiger 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.0in that case, so the declared names are filled rather than dropped.- Parameters:
- Return type:
- Returns:
One MetricValue per declared metric name, in declaration order.
- Raises:
ValueError – If
historiesis empty, or if an episode ran without being measured. Seecompute_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.
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:
- Returns:
Specs for
task_completion_rate(the last step’s door choice) andaverage_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 thenp.array_equalsemantics used by the linear-scan fallback).
- initial_observation_dist()[source]
Get the initial observation distribution.
- Return type:
- 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:
- 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:
- Return type:
- 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:
- 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.ndarrayof shape(N,)where N is the number of candidate observations. Subclasses must implement.
- 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 exposesbatch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.- Parameters:
- Return type:
- 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_stateis the realised post-transition state when known (e.g. threaded bysample_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 whenNone.- Parameters:
- Return type:
- 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:
- Return type:
- 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.
- 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 exposesbatch_sample(states_array)) should override to avoid the loop.- Parameters:
- Returns:
np.ndarrayof shape(N, *dim). For structured envs (Tiger strings, Pacman tuples): a list of length N.- Return type:
- 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.
See also
Base Environment Class — the full catalog and the environment interface.