POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils package
Submodules
POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.base_light_dark_pomdp module
- class POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.base_light_dark_pomdp.BaseLightDarkPOMDP(discount_factor, name, space_info, reward_range=None, beacons=[(0, 0), (0, 5), (0, 10), (5, 0), (5, 5), (5, 10), (10, 0), (10, 5), (10, 10)], goal_state=array([10, 5]), start_state=array([0, 5]), obstacles=[(3, 7), (5, 5)], obstacle_hit_probability=0.2, obstacle_reward=-10.0, obstacle_radius=1.0, goal_reward=10.0, beacon_radius=1.0, fuel_cost=2.0, grid_size=11)[source]
Bases:
Environment,ABC- Parameters:
- cache_visualization(history, cache_path)[source]
Cache visualization of agent’s path and belief.
- Parameters:
- Raises:
TypeError – If history is not a List or contains non-StepData objects, or if cache_path is not a Path object.
ValueError – If history is empty or contains invalid data.
- Return type:
- abstractmethod compute_metrics(histories)[source]
Compute environment-specific metrics from episode histories.
This method can be overridden by subclasses to provide custom metric calculations beyond standard return and episode length.
- property config_id: str
Generate a deterministic identifier based on environment configuration. This implementation ensures that the config_id is invariant to the order of beacons and obstacles.
- hash_observation(observation)[source]
Return a hashable key consistent with
is_equal_observation().Used by tree-search planners to index belief children by observation in O(1). The returned key MUST satisfy the contract:
is_equal_observation(a, b) implies hash_observation(a) == hash_observation(b)
- Parameters:
observation (
Any) – Observation to hash.- Returns:
the observation itself when it is already hashable).
- Return type:
- Raises:
NotImplementedError – If the observation is not hashable and the subclass has not provided an override. Subclasses with non-hashable observations (e.g.
np.ndarray) MUST override.
- 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_state_near_beacon(state)[source]
Return True if
statelies withinbeacon_radiusof any beacon.Used by tests and observation-model selection logic. Replaces the previous wrapper-attribute access pattern (
model.near_beacon) with an env-level method that does not require the wrapper class.
- abstractmethod is_terminal(state)[source]
Check if a state is terminal.
- Parameters:
state (
ndarray) – 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.
- abstractmethod 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.
- visualize_path(path, agent_belief_path, actions, cache_path)[source]
Create and save an animated visualization of the agent’s path.
- Parameters:
path (
List[ndarray]) – List of state positions (2D numpy arrays) along the agent’s trajectory.agent_belief_path (
List[DiscreteDistribution]) – List of belief distributions at each step.cache_path (
Path) – Path where to save the visualization (must end with .gif).
- Raises:
TypeError – If cache_path is not a Path object.
ValueError – If cache_path doesn’t end with .gif.
- Return type:
- class POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.base_light_dark_pomdp.BaseLightDarkPOMDPDiscreteActions(discount_factor, name, is_discrete_observations, reward_range=None, beacons=[(0, 0), (0, 5), (0, 10), (5, 0), (5, 5), (5, 10), (10, 0), (10, 5), (10, 10)], goal_state=array([10, 5]), start_state=array([0, 5]), obstacles=[(3, 7), (5, 5)], obstacle_hit_probability=0.2, obstacle_reward=-10.0, goal_reward=10.0, beacon_radius=1.0, fuel_cost=2.0, grid_size=11)[source]
Bases:
BaseLightDarkPOMDP
POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.light_dark_reward_models module
- class POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.light_dark_reward_models.BaseLightDarkRewardModel[source]
Bases:
ABC
- class POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.light_dark_reward_models.ContinuousLDZeroMeanHazardShockRewardModel(goal_state, obstacles, goal_state_radius, obstacle_radius, grid_size, obstacle_hit_probability, obstacle_reward, goal_reward, fuel_cost)[source]
- class POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.light_dark_reward_models.ContinuousLightDarkDistanceDecayedHazardPenaltyRewardModel(goal_state, obstacles, goal_state_radius, obstacle_radius, grid_size, obstacle_hit_probability, obstacle_reward, goal_reward, fuel_cost, penalty_decay)[source]
Bases:
BaseLightDarkRewardModel- Parameters:
- class POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.light_dark_reward_models.ContinuousLightDarkRewardModel(goal_state, obstacles, goal_state_radius, obstacle_radius, grid_size, obstacle_hit_probability, obstacle_reward, goal_reward, fuel_cost)[source]
Bases:
BaseLightDarkRewardModel- Parameters:
POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.light_dark_visualizer module
- class POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.light_dark_visualizer.LightDarkPOMDPVisualizer(environment)[source]
Bases:
objectVisualizer for Light-Dark POMDP environments.
Handles all visualization and animation logic for Light-Dark POMDP environments, including path visualization, belief particle rendering, and animation generation.
- Parameters:
environment (Any)
- environment
The Light-Dark POMDP environment instance to visualize.
- cache_visualization(history, cache_path)[source]
Cache visualization of agent’s path and belief.
- Parameters:
- Raises:
TypeError – If history is not a List or contains non-StepData objects, or if cache_path is not a Path object.
ValueError – If history is empty or contains invalid data.
- Return type:
- visualize_path(path, agent_belief_path, actions, cache_path)[source]
Create and save an animated visualization of the agent’s path.
- Parameters:
path (
List[ndarray]) – List of state positions (2D numpy arrays) along the agent’s trajectory.agent_belief_path (
List[DiscreteDistribution]) – List of belief distributions at each step.cache_path (
Path) – Path where to save the visualization (must end with .gif).
- Raises:
TypeError – If cache_path is not a Path object.
ValueError – If cache_path doesn’t end with .gif.
POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.numba_kernels module
Light-Dark-specific Numba-JIT kernels.
Holds kernels whose signatures or logic hardcode light-dark concepts
(goal+obstacles+out-of-grid shape, standard / high-variance-states / decaying-
hit-probability reward formulas). Generic geometric / numerical primitives
used here also by other envs live in
POMDPPlanners.utils.numba_kernels instead.
Conventions match the shared module: contiguous float64 arrays, scalar
floats/ints/bools, no Python objects, all RNG draws happen in the caller and
are passed in as parameters.
Public kernels
is_terminal_kernel()— replacesContinuousLightDarkPOMDP.is_terminal.compute_reward_base_kernel()— deterministic part of the Standard / ZeroMeanHazardShock reward model plus anis_obstacle_hit_regionflag so the Python caller can decide whether to draw a uniform.compute_reward_base_batch_kernel()— batched version ofcompute_reward_base_kernel(). Returns(rewards, obstacle_mask)so the Python caller can apply the stochastic obstacle-hit contribution where the mask isTrue, preserving the seeded RNG call pattern.compute_reward_decaying_hit_prob_kernel()— full reward for the Decaying-Hit-Probability model (uniform drawn in Python and passed in).
- POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.numba_kernels.compute_reward_base_batch_kernel(next_states, goal_state, obstacles, goal_state_radius, obstacle_radius, grid_size, fuel_cost, goal_reward, obstacle_reward)[source]
Batched form of
compute_reward_base_kernel().next_statesis shape(N, 2)and contains the realised post-transition positions threaded by the Python caller (or the deterministicstates + actionfallback when no realised batch is available). Returns(rewards, obstacle_mask)both of lengthN.rewardsalready includes fuel, goal-distance, goal bonus, and the out-of-grid penalty. The Python caller must add the stochastic obstacle-hit contribution at indices whereobstacle_maskisTrue, drawing its own RNG so seeded tests stay bit-identical to the per-state path.
- POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.numba_kernels.compute_reward_base_kernel(next_state, goal_state, obstacles, goal_state_radius, obstacle_radius, grid_size, fuel_cost, goal_reward, obstacle_reward)[source]
Return
(base_reward, is_obstacle_hit_region).base_rewardalready includes fuel, goal-distance, and the out-of-grid penalty. The caller (Python) must add the stochastic obstacle-hit contribution whenis_obstacle_hit_regionisTrue, using its ownnp.random.rand()draw so seeded tests stay bit-identical. Used by Standard and ZeroMeanHazardShock reward models.next_stateis the realised post-transition position. The Python caller threads either the draw fromEnvironment.sample_next_step()or the deterministicstate + actionfallback when no realised draw is available.
- POMDPPlanners.environments.light_dark_pomdp.light_dark_pomdp_utils.numba_kernels.compute_reward_decaying_hit_prob_kernel(next_state, goal_state, obstacles, goal_state_radius, grid_size, fuel_cost, goal_reward, obstacle_reward, penalty_decay, uniform)[source]
Full reward for the Decaying-Hit-Probability model.
next_stateis the realised post-transition position threaded by the Python caller. The caller draws a singleuniform ~ U[0,1)(vianp.random.rand()) and passes it in — this matches the pre-refactor RNG call pattern, which unconditionally drew one uniform in_obstacle_reward.