Planning, imitation, and offline reinforcement learning A Stochastic Blog tutorial built a Monte Carlo Tree Search self-play loop on tic-tac-toe and trained a learned world model to predict the next board, then moved to offline reinforcement learning on the Farama Foundation's Minari mujoco/hopper/medium-v0 dataset. Behavior cloning on 15,015 training transitions cut validation MSE by 61 percent against a mean-action baseline, and a conservative Q-learning agent kept its value estimate honest on unseen data, with the cached sample holding 18,513 transitions across 24 episodes in 2.07 MB. A random policy in the same environment terminates after a mean of 24.63 steps with a mean return of 24.15, establishing the floor the offline methods are measured against. Stochastic Blog https://stochastic.blog/tag/stochastic-blog/ Planning, imitation, and offline reinforcement learning In post 36 we built the machinery of deep reinforcement learning and watched an actor-critic agent learn from its own experience. That agent had a luxury most real problems do not grant: a simulator it could poke as often as it liked. This post takes that luxury away. We build a tiny Monte Carlo Tree Search self-play loop on tic-tac-toe, train a learned world model to predict the next board, then move to the harder setting where the only thing we have is a fixed pile of logged transitions from Minari, a public library of logged environment transitions. Behavior cloning on 15,015 training transitions cuts validation MSE by 61 percent against a mean-action baseline, and a conservative Q-learning agent keeps its value estimate honest on data it never saw. The through-line for the whole post is the difference between acting and imagining : every method here is a different answer to the question of how much you are allowed to trust a model of the world you did not get to explore. We work with mujoco/hopper/medium-v0 from the Farama Foundation's Minari collection, a standard continuous-control offline task. Hopper has an 11-dimensional state and a 3-dimensional continuous action, and "medium" means the transitions come from a mediocre policy, not an expert one. The dataset gives us enough transitions to show both imitation and offline RL on a laptop, and the notebook caches a 24-episode sample so reruns are fast. The data on the table Before any modeling we look at what we actually downloaded. The cache holds 18,513 transitions across 24 episodes, 11 observation fields and 3 action fields, and the whole thing fits in 2.07 MB of memory. Every numeric array is finite, so there is nothing to impute. We check for exact duplicate transitions and find zero, which is the good outcome: no replay bias to correct. We also flag 24 self-transitions, where the next observation equals the current one, and keep them because they are genuine environment dynamics rather than leakage. The reward histogram tells us the shape of the problem. Rewards are all positive, ranging from 0.745 to 7.037, so the agent is being paid for staying upright and moving forward. Every reward in the sample is positive, so the base rate is 1.0 and there is no negative-reward class to stratify against. To know whether the dataset is any good, we need a floor, so we run a random policy in the same environment. It terminates after a mean of 24.63 steps, with a standard deviation of 17.95 and a maximum of 113, and its mean return is 24.15. That is the floor. The offline dataset is the only source of useful behavior we have, which is exactly the constraint this post is about. Planning and search The first answer to "how much can we trust a model" is: build one and plan inside it. Model-based RL means we are given, or we learn, a model of the world and plan inside it. The cheap version is Dyna, which leans on the model to squeeze extra updates out of each real transition. The strong version is AlphaZero, which turns search visit counts into policy targets and generates its own games through self-play, and MuZero, which does the same planning inside a learned latent model instead of the raw state. We start with tic-tac-toe because the game is small enough that we can watch the search work. The MCTS loop expands an untried action, rolls out randomly to a terminal state, and backs the result up the tree. The AlphaZero move is to read the visit counts off the root as a policy target. python def alphazero policy target root : target = np.zeros 9, dtype=np.float32 for ch in root.children: target ch.action = ch.visits if target.sum 0: target /= target.sum visit counts become a probability distribution return target Five self-play games at 120 simulations each produce 40 policy targets, and the sample target sums to 1.0 with its top three entries at 0.192, 0.158, and 0.142. The five games end in two draws, two wins for X and one for O, coded 1 for X, -1 for O, 0 for a draw, which is what a shallow search on a solved game should give. Tic-tac-toe hands us a perfect model, which is the one thing a real agent never gets. Dyna is the cheapest test of what happens when the model is learned from a handful of real steps instead. We run Q-learning on a 5x5 grid with a goal worth 10 and a step cost of -1, then run it again with five planning steps per real step. The last-10 mean return for plain Q-learning is 1.20 and for Dyna-Q it is 0.00. Five planning steps on a tiny model did not help here. The Dyna-Q return fell 1.20 below plain Q-learning, which says the model has to be worth trusting before planning pays.