Skip to content

Deep reinforcement learning and decision models · Method reference · DRL014 · Algorithm

MuZero

Learn a latent dynamics model sufficient for reward, value, and policy prediction, then use tree search to improve decisions without requiring an explicit observed-state simulator.

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Learn a latent dynamics model sufficient for reward, value, and policy prediction, then use tree search to improve decisions without requiring an explicit observed-state simulator. The model is trained for planning-relevant predictions rather than necessarily reconstructing every pixel.

Question / hypotheses

Can learned latent rollouts and search produce useful decisions when true transition dynamics are unknown? Search-enhanced policy targets improve the model iteratively, but planning success depends on model accuracy in action sequences explored by search.

Architecture / computational structure

A representation network maps observation history to a latent state. A dynamics network takes latent state and action to predict next latent state and reward. A prediction network outputs policy logits and value. Monte Carlo tree search uses these components, and replayed unrolls train them jointly.

Assumptions

Rewards, action semantics, and terminal conditions must be consistent, and search must explore a manageable action branching structure. Learned latent states need preserve information important to planning. Model errors can accumulate under actions unlike those in collected trajectories.

Formula / computational definition

s0=hθ(o≤t)s^0=h_\theta(o_{\le t}), (rk,sk)=gθ(sk−1,at+k−1)(r^k,s^k)=g_\theta(s^{k-1},a_{t+k-1}), (pk,vk)=fθ(sk)(p^k,v^k)=f_\theta(s^k). A training loss sums reward loss, value-target loss, and search-policy cross-entropy over unroll steps, plus regularization.

Parameters and notation

Learned weights belong to representation, dynamics, reward, policy, and value networks. Hyperparameters include latent size, unroll length, search simulations, selection constants, root exploration noise, discount, replay sampling, target reanalysis policy, learning rate, and loss weights.

Fitting, fine-tuning, and adaptation

Transfer the representation when observations remain compatible, but refit reward/dynamics/value components for changed tasks. Freeze selected representation layers initially, then unfreeze under joint unroll losses. Refresh search targets with the current model and evaluate latent rollout reliability before increasing search depth.

How to use and calibrate

Report both interaction and search-compute budgets, return/win-rate distributions, and the evaluation search setting. Monitor multi-step reward/value errors and policy-target entropy. Compare model-only and search-enhanced decisions to separate representation gains from additional planning compute.

Example application

Plan actions in a board-game or visual-control simulator using learned reward and value predictions. The paired code evaluates an illustrative reward/value/policy unroll loss using scalar targets; the full tree search and network training are not included.

Interpretation / pitfalls

Watch out

More search can exploit rather than fix an inaccurate model. Original implementations may use transformed/distributional reward and value targets, so scalar MSE is only an explanatory variant. Latent dynamics need not correspond to a human-readable physical state or reconstruct observations faithfully.

Python and R code examples

Scope: computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. Dependencies/validation: Python with NumPy executed successfully; base R not executed. Targets and supplied network outputs are ordinary arrays here, so this does not validate automatic-differentiation boundaries.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. · needs numpy

import numpy as np
reward_prediction=np.array([.2,1.1]); reward_target=np.array([0.,1.])
value_prediction=np.array([2.,1.5]); value_target=np.array([2.2,1.])
policy=np.array([[.6,.4],[.3,.7]]); search_policy=np.array([[.8,.2],[.1,.9]])
reward_loss=np.mean((reward_prediction-reward_target)**2)
value_loss=np.mean((value_prediction-value_target)**2)
policy_loss=-np.mean(np.sum(search_policy*np.log(policy),axis=1))
print(reward_loss,value_loss,policy_loss,reward_loss+value_loss+policy_loss)
R

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop.

reward_prediction <- c(.2,1.1); reward_target <- c(0,1)
value_prediction <- c(2,1.5); value_target <- c(2.2,1)
policy <- matrix(c(.6,.4,.3,.7),2,byrow=TRUE); search_policy <- matrix(c(.8,.2,.1,.9),2,byrow=TRUE)
reward_loss <- mean((reward_prediction-reward_target)^2)
value_loss <- mean((value_prediction-value_target)^2)
policy_loss <- -mean(rowSums(search_policy*log(policy)))
print(c(reward_loss,value_loss,policy_loss,reward_loss+value_loss+policy_loss))

Sources

From the CodeSplash reference, entry DRL014.