POMDPPlanners.environments.environment_utils package
Cross-environment utilities reusable across POMDP environments.
Submodules
POMDPPlanners.environments.environment_utils.dangerous_areas_kernels module
Generic Numba kernels for dangerous-area reward contributions.
Each kernel maps a 2-D point (and a batch of points) to the dangerous- area reward contribution under a specific stochastic model. The kernels are env-agnostic so they can be reused by light-dark, pacman, laser-tag, and any future grid / continuous environment that needs circular hazard zones with a reward penalty.
Three reward-model variants are provided, each as a scalar / batch pair:
constant_prob: penalty applied with a fixed probability whenever the point lies inside any zone. Matches the light-dark Standard reward model and the laser-tag / pacman dangerous-area contract (degenerate case
hit_probability=1.0).high_variance:
±penaltywith 50/50 split whenever the point lies inside any zone. Zero expected contribution, high variance. Matches the light-dark ZERO_MEAN_HAZARD_SHOCK reward model.decaying_prob: penalty applied with probability
exp(-min_dist / penalty_decay)based on the closest zone centre (no radius cutoff). Matches the light-dark Decaying-Hit-Probability model.
Conventions (matching POMDPPlanners.utils.numba_kernels):
All inputs are plain numeric arrays / scalars; no Python objects.
Points are passed as
np.ndarrayof shape(2,)(scalar kernel) or(N, 2)(batch kernel).Zone centres are passed as a contiguous
float64array of shape(2, D)—xcoordinates on row 0,yon row 1. Matches the_convert_*_to_arrayhelpers already used by light-dark.Radii are passed pre-squared (
radius_sq) so the kernel never sqrts on the hot path and callers cache the squaring once at construction.RNG stays in Python. The caller draws
uniform ~ U[0, 1)(oruniformsfor the batch path) and passes them in. This preserves seed semantics and keeps outputs bit-identical under fixed seeds.Each kernel returns only the dangerous-area contribution. The caller composes this with whatever env-specific geometry (fuel, goal, grid bounds, …) it needs.
- POMDPPlanners.environments.environment_utils.dangerous_areas_kernels.constant_prob_penalty_batch_kernel(points, centers, radius_sq, penalty, hit_probability, uniforms)[source]
Batched form of
constant_prob_penalty_kernel().pointsis shape(N, 2),uniformsis shape(N,). Returns a length-Narray of contributions.uniforms[i]is consulted only whenpoints[i]lies inside some zone, so callers can either pre-drawNuniforms or pre-draw only enough for the in-zone subset and pass that subset’s rows.
- POMDPPlanners.environments.environment_utils.dangerous_areas_kernels.constant_prob_penalty_kernel(point, centers, radius_sq, penalty, hit_probability, uniform)[source]
Constant-probability dangerous-area penalty.
Returns
penaltyiff the point lies inside any of theDzones (squared-distance check againstradius_sq) anduniform < hit_probability. Otherwise returns0.0.
- POMDPPlanners.environments.environment_utils.dangerous_areas_kernels.decaying_prob_penalty_batch_kernel(points, centers, penalty, penalty_decay, uniforms)[source]
Batched form of
decaying_prob_penalty_kernel().
- POMDPPlanners.environments.environment_utils.dangerous_areas_kernels.decaying_prob_penalty_kernel(point, centers, penalty, penalty_decay, uniform)[source]
Distance-decaying dangerous-area penalty.
Computes the minimum Euclidean distance from the point to any zone centre, then applies
penaltywith probabilityexp(-min_dist / penalty_decay). No radius cutoff — every point feels the (vanishingly small at large distance) penalty risk.
- POMDPPlanners.environments.environment_utils.dangerous_areas_kernels.high_variance_penalty_batch_kernel(points, centers, radius_sq, penalty, uniforms)[source]
Batched form of
high_variance_penalty_kernel().
- POMDPPlanners.environments.environment_utils.dangerous_areas_kernels.high_variance_penalty_kernel(point, centers, radius_sq, penalty, uniform)[source]
High-variance dangerous-area contribution.
Returns
penalty(withuniform < 0.5) or-penalty(otherwise) iff the point lies inside any of theDzones, else0.0. Expected contribution is zero; the variance ispenalty**2. Pass the signedpenaltyvalue the caller wants on theuniform < 0.5branch (e.g.obstacle_reward = -10.0); the kernel emits+10.0on the other branch.
- POMDPPlanners.environments.environment_utils.dangerous_areas_kernels.membership_within_radius_batch_kernel(points, centers, radius_sq)[source]
Batched dangerous-area membership test.
Returns a length-
Nboolean array; entryiisTrueiffpoints[i]lies withinsqrt(radius_sq)of any centre incenters.pointsis shape(N, 2),centersis shape(2, D)(x on row 0, y on row 1, matching the convention of the other kernels in this module).Use this when the caller wants the in-zone mask separately from the reward contribution (e.g. so it can keep RNG handling in Python and preserve bit-identical seeded behaviour with a non-batched reference implementation).