BetaZero
AlphaZero moved into belief space. BetaZero is PFT-DPW with two of its parts replaced by a network: action selection uses PUCT with a learned policy prior instead of UCB1, and a leaf’s value comes from a learned value head instead of a random rollout. The network reads a fixed-size summary of the belief, so the same weights serve every belief the search reaches.
Offline policy iteration — play episodes with the current network, train on the
search’s visit counts and returns, repeat — is orchestrated by
PolicyTrainer. An untrained planner still runs:
with no network argument the constructor builds a default network with
random initial weights, so its priors and values carry no information until
training.
Notes
Original paper: Moss, R. J., Corso, A., Caers, J., & Kochenderfer, M. J. (2024). BetaZero: Belief-State Planning for Long-Horizon POMDPs using Learned Approximations. Reinforcement Learning Conference (RLC).
Needs PyTorch.
state_dimmust match the environment’s state vector, and the action sampler is aBetaZeroActionSamplerwrapping anotherActionSamplerthat it falls back to when no network is set.With no
belief_representation, the network reads the particles’ mean and standard deviation. That needs numeric states. For states it cannot turn into numbers, such as Tiger’s"tiger_left"strings, it feeds the network all zeros, so the network learns nothing about the belief. Pass your ownbelief_representationfor such an environment.The safety-constrained extension is ConstrainedZero.
Can I use?
Discrete |
Continuous |
|
|---|---|---|
State |
✔️ |
✔️ |
Action |
✔️ |
✔️ |
Observation |
✔️ |
✔️ |
Also supports |
|
|---|---|
Cost constraints |
❌ |
GPU |
✔️ |
Example
from POMDPPlanners.core.belief import get_initial_belief
from POMDPPlanners.environments.tiger_pomdp import TigerPOMDP
from POMDPPlanners.planners.mcts_planners.beta_zero.beta_zero import BetaZero
from POMDPPlanners.planners.mcts_planners.beta_zero.beta_zero_action_sampler import (
BetaZeroActionSampler,
)
from POMDPPlanners.utils.action_samplers import DiscreteActionSampler
tiger = TigerPOMDP(discount_factor=0.95)
actions = tiger.get_actions()
action_sampler = BetaZeroActionSampler(
fallback_sampler=DiscreteActionSampler(actions),
actions=actions,
)
planner = BetaZero(
environment=tiger,
discount_factor=0.95,
depth=10,
name="BetaZero_Example",
action_sampler=action_sampler,
time_out_in_seconds=2.0,
state_dim=1, # one state variable; see the note on states above
k_a=1.0,
alpha_a=0.5,
k_o=1.0,
alpha_o=0.5,
exploration_constant=1.0,
)
belief = get_initial_belief(tiger, n_particles=50)
actions, run_data = planner.action(belief)
Parameters
- class POMDPPlanners.planners.mcts_planners.beta_zero.beta_zero.BetaZero(environment, discount_factor, depth, name, action_sampler, k_a=1.0, alpha_a=0.5, k_o=1.0, alpha_o=0.5, exploration_constant=1.0, time_out_in_seconds=None, n_simulations=None, min_visit_count_per_action=1, network=None, belief_representation=None, state_dim=None, z_q=1.0, z_n=1.0, temperature=1.0, n_buffer=1, training_batch_size=256, training_epochs=10, learning_rate=0.001, weight_decay=0.0001, hidden_sizes=(128, 128), track_gradients=False, normalize_inputs=True, normalize_values=True, log_path=None, debug=False, use_queue_logger=False)[source]
Bases:
ArenaDoubleProgressiveWideningMCTSPolicy,TrainablePolicyBetaZero: Neural MCTS for POMDPs.
Extends
DoubleProgressiveWideningMCTSPolicywith three key innovations from the BetaZero paper:PUCT selection: Replaces UCB1 using learned policy priors.
Neural value estimation: Replaces random rollouts at leaf nodes.
Policy iteration via ``fit()``: Collects episodes, computes Q-weighted policy targets, and trains the network.
The planner has two modes:
Online planning via
action(belief): builds an MCTS tree with PUCT and network value estimates.Offline training via
fit(): alternates data collection and network training.
- Parameters:
environment (Environment)
discount_factor (float)
depth (int)
name (str)
action_sampler (ActionSampler)
k_a (float)
alpha_a (float)
k_o (float)
alpha_o (float)
exploration_constant (float)
time_out_in_seconds (int | None)
n_simulations (int | None)
min_visit_count_per_action (int)
network (AbstractBetaZeroNetwork | None)
belief_representation (BeliefRepresentation | None)
state_dim (int | None)
z_q (float)
z_n (float)
temperature (float)
n_buffer (int)
training_batch_size (int)
training_epochs (int)
learning_rate (float)
weight_decay (float)
track_gradients (bool)
normalize_inputs (bool)
normalize_values (bool)
log_path (Path | None)
debug (bool)
use_queue_logger (bool)
- network
Dual-head neural network for policy and value prediction.
- belief_representation
Belief → feature-vector mapping φ(b).
- z_q
Exponent for Q-value term in policy target.
- z_n
Exponent for visit-count term in policy target.
- temperature
Temperature τ for sharpening/smoothing policy target.
Example
>>> import numpy as np >>> np.random.seed(42) >>> from POMDPPlanners.environments.tiger_pomdp import TigerPOMDP >>> from POMDPPlanners.core.belief import get_initial_belief >>> from POMDPPlanners.utils.action_samplers import DiscreteActionSampler >>> from POMDPPlanners.planners.mcts_planners.beta_zero.beta_zero import BetaZero >>> >>> env = TigerPOMDP(discount_factor=0.95) >>> sampler = DiscreteActionSampler(env.get_actions()) >>> planner = BetaZero( ... environment=env, ... discount_factor=0.95, ... depth=3, ... name="BetaZero_Tiger", ... action_sampler=sampler, ... n_simulations=20, ... state_dim=1, ... ) >>> belief = get_initial_belief(env, n_particles=10) >>> actions, run_data = planner.action(belief) >>> actions[0] in env.get_actions() True
- action(belief)[source]
Select an action via MCTS with PUCT and network value estimates.
If data collection is active (during
fit()), also stores a pending training example from the tree root.- Return type:
- Parameters:
belief (Belief)
- collect_episodes_batched(initial_belief_fn, n_episodes, episode_length)[source]
Collect training data using fast batched (network-only) rollouts.
- finalize_episode(history)[source]
Process a completed episode into the replay buffer.
- Parameters:
history – The
Historyreturned by the episode runner.- Return type:
- get_metric_keys()[source]
Return the loss-metric key names produced by
train_step().
- get_network()[source]
Return the underlying trainable network, or
Noneif not applicable.Override in concrete policies to enable weight-histogram logging in
TensorBoardCallback.- Return type:
AbstractBetaZeroNetwork
- classmethod get_space_info()[source]
Get space type requirements for this policy class.
This class method specifies what types of action and observation spaces this policy implementation can handle, enabling compatibility checking with environments.
- Return type:
- Returns:
PolicySpaceInfo specifying required action and observation space types
Note
Subclasses must implement this method to declare their space compatibility. This is used for validation when pairing policies with environments.
- load_normalization_stats(filepath)[source]
Restore normalization statistics from a saved directory.
Should be called after
network.load_weights()when loading a checkpoint that was saved with normalisation enabled.