Deqian Kong

understanding how networks represent, reason, and learn

Cognitive maps for path planning

II. Learning the map from experience

Co-authored with Guangyan Sun

Nov. 29 2026 · note · Part I · Part II

In a classic experiment from 1930, rats explored a complex maze for ten days with no food at the goal (Tolman and Honzik, 1930). They did not seem to learn much. Then food was introduced, and on the following trials these rats took nearly as few wrong turns as rats that had been rewarded from the start. Exploration had taught them far more than their behaviour had revealed.

day 1

Figure 1. A simulated rat. Food appears on day 11.

Tolman's explanation was that the rats had built a cognitive map of the maze while they wandered (Tolman, 1948). Decades later, place cells were found in the hippocampus (O'Keefe and Dostrovsky, 1971). A place cell fires when the animal is at one particular place, so these cells look like the cells of such a map.

Part I of this series built such a map from a random walk that was known exactly: we knew the maze, so we knew its walls. An animal does not know them, and neither does a robot. This note asks whether the map can be learned from experience alone, from a stream of observations that may be images (Kong et al., 2026).

We will see that wandering is enough. A random walk, with no goal and no reward, already contains the map, and a network can learn it from samples of the walk. As in Part I, the search for a route is then done in advance, when the map is learned, and the same map serves every goal.

The map, in brief

This section repeats what we need from Part I. As there, picture an agent wandering in a maze: at every step it moves to one of the eight neighbouring cells, or stays.

If the agent starts at x and wanders for t steps, how likely is it to be at y? Call this probability p(y | x, t). It is the transition kernel of the walk, and we call t the horizon. A short horizon tells how far apart two nearby places are. A long horizon tells which regions connect.

In Part I, every place x has a vector h(x, t) at every horizon, the firing rates of a population of cells, and two places have similar vectors if the walk can easily get from one to the other:

\langle\, h(x,t),\; h(y,t) \,\rangle \;=\; q(y \mid x,\, t) (1)

Here q is the kernel, rescaled so that every place is perfectly similar to itself. Firing rates cannot be negative, and with this each cell ends up active in one part of the maze, its place field. Places that the walk connects easily have vectors that are close together, so each horizon gives a map of its own.

To reach a goal y, the agent looks at its neighbours z and at all horizons t, and takes the step with the largest gain q(y | z, t) − q(y | x, t) (Zhao et al., 2025). Far from the goal the long horizons decide, and close to the goal the short ones.

Learning the map from experience alone

In Part I, we computed the kernel from the one-step matrix of the walk, which means we already knew where the walls are. Now the agent has only its own stream of observations as it wanders. Is that enough?

Take pairs from the walk: the observation now, and the observation t steps later, (xs, xs+t). The real pairs tell us what is reachable in t steps. We model the kernel with an energy-based model (EBM), which is a simple choice:

p(y \mid x,\, t) \;\approx\; p_0(y)\; \exp G(x, y, t) (2)

Here p0 is a reference distribution over observations. The energy is −G, and G is a score for every pair,

G(x, y, t) \;=\; \beta_0(t)\, \langle\, h(x,t),\; g(y,t) \,\rangle + \beta_1(t) (3)

where h and g are unit vectors produced by a neural network that reads the observation and the horizon, and β0 and β1 are two numbers learned for each horizon. So apart from these two numbers, the score is just an inner product of two vectors. The score should be high for pairs that really occur t steps apart, and low for random pairs. The training is contrastive: the model must tell a real pair from a pair whose second member is drawn from p0.

The agent needs no reward and no goal for this. It does not even need to know which actions it took.

The training does not ask for a random walk either. The pairs can come from any behaviour, and the model then learns the kernel of that behaviour. We study the random walk because Part I tells us what its kernel contains.

Figure 2. Learning from one random walk as the walk gets longer. Top row: the learned exp G(x, y, t) for one goal y (star), at three horizons. Cells not yet visited are blank. Bottom row: the exact ratio p(y | x, t) / p0(y). After four million steps the correlation between the two, over all pairs of places, is 0.97, 0.99 and 0.96 at these horizons. (The two encoders are tied, g = h. The maze has 873 cells, so the average over the pairs of the walk is taken exactly, from counts.)

Figure 2 trains this model in the six-room maze of Part I, with a small network that reads the position. The model starts knowing nothing. As the walk gets longer, its picture of the maze approaches the true kernel.

Now compare equations (1) and (3). They say nearly the same thing: the inner product of two position vectors at horizon t tells how reachable one place is from the other. There are two differences. In (1) the kernel is given, and the non-negative vectors become place fields. In (3) the kernel is learned from samples, and the vectors come from a network, so the observation can be an image and not only a position.

The geometry is the same too. With tied encoders,

G(y, y, t) - G(x, y, t) \;=\; \dfrac{\beta_0(t)}{2}\; \Vert\, h(x,t) - h(y,t) \,\Vert^2 (4)

so the score toward a goal is again a distance on the map, just as in Part I.

Planning with one-step predictions

Planning works as in Part I, with one addition. The agent no longer knows where a move will take it. So a separate model, learned from single steps, predicts where each action a would lead, \hat{x}^{a}. The progress of an action at horizon t is \exp G(\hat{x}^{a},\, y,\, t) \;-\; \exp G(x,\, y,\, t).

The horizons can be combined in two ways. The first uses one horizon at a time, as in Part I: take the action with the largest progress at any one horizon. With this rule the agent selects shorter horizons as it approaches the goal. The second uses all horizons together: add the progress over the horizons. The current position then drops out, so the actions are ranked by one potential,

\Phi(x, y) \;=\; \sum_{t}\;\, \exp G(x, y, t) (5)

and the agent takes the action whose predicted outcome has the largest Φ. With exact predictions and progress at every step, Φ rises along the route, so no place is visited twice. In the paper the two rules are called greedy planning and potential-ascent planning.

Either way, the agent takes one action, sees where it really lands, and plans again. The step model is never rolled out over many steps, so its errors do not add up along the route. Everything far away comes from the map.

Does it work at scale? In the paper, models trained on four million steps of this walk plan in the Large and Giant mazes of OGBench (Kong et al., 2026). The Large maze is solved almost every time, by our planner and by offline reinforcement learning trained on the same walk. The Giant maze tells them apart (Figure 3). Our planner still reaches the goal in most trials. Offline reinforcement learning reaches it in about half of them, or fewer.

random start and goal pairs

offline RL, best method53%
our planner88 to 90%

the five official tasks

offline RL, best method27%
our planner, one horizon80%
our planner, all horizons92%

Figure 3. How often the goal is reached in the Giant maze of OGBench. Every method is trained on the same four million steps of random walk. Grey: the best of the offline reinforcement learning methods. Blue: our planner; the pale end of a bar marks a range. Numbers from Kong et al. (2026).

The observations need not be positions. From overhead images, the planner still solves Large (95%) and most of Giant (70 to 78%).

Try it with our trained models in Figure 4.

planner horizons up to colour

loading the trained model…

Click anywhere for a start, then a goal. Hover the strip, or drag along it, to scrub.

Figure 4. Our trained models, planning live. Colour: exp G(x, y, t) at the current horizon (exact: the true p(y | x, t)). As in the paper, each decision scores 36 headings 3 units out and walks 15 steps along the best; a point sliding along walls stands in for the simulator.

The cognitive map still emerges

The cognitive map is there, although nobody asked for it. No distance and no route was given as supervision. Still, the learned vectors behave like the maps of Part I. In the Large maze, the rank correlation between embedding distance and shortest-path distance is 0.95 for near pairs and −0.01 for far pairs at horizon 1, and 0.58 and 0.97 at horizon 256. Figure 5 shows them: short horizons keep the floor plan, long horizons keep only how the corridors connect.

horizon

maze

learned map, drag to turn

Figure 5. The learned vectors h(x, t) in 3D (t-SNE, one fit per horizon). Hover or tap to match cells; drag to turn.

The recipe is not tied to positions, or to a random walk. From first-person images in a simulated apartment, the agent reaches the goal in 71% of the corner tasks (random actions: 38%). On a robot-arm task (OGBench cube-single) the data are expert and noisy trajectories, not a random walk. There it reaches 92%, and noisy data alone (91%) teach it as well as expert data (88%).

Takeaway

Wandering is enough to learn a map. A random walk contains the geometry of the environment at every horizon.

A map makes planning easy. On the map, moving toward the goal means reducing a distance, so planning becomes a sequence of local steps, and the agent picks the horizon that has a signal where it stands.

The map can be learned from experience alone, without a given kernel, without rewards, and without policy optimization. What is still open is transfer: each map here is learned within one environment.

Previous in this series: I. Place cells as a multi-scale map.

References

  1. D. Kong, G. Sun, S. Cheng, S. Xie, B. Pang, J. Xie, T. Geng, C. Ding, Y. N. Wu. Learning to Plan from Random Exploration. Preprint, 2026.
  2. M. Zhao, D. Xu, D. Kong, W.-H. Zhang, Y. N. Wu. Place Cells as Multi-Scale Position Embeddings: Random Walk Transition Kernels for Path Planning. NeurIPS 2025.
  3. E. C. Tolman, C. H. Honzik. Introduction and removal of reward, and maze performance in rats. University of California Publications in Psychology, 1930.
  4. E. C. Tolman. Cognitive maps in rats and men. Psychological Review 55, 1948.
  5. J. O'Keefe, J. Dostrovsky. The hippocampus as a spatial map. Brain Research 34, 1971.