Cognitive maps for path planning
I. Place cells as a multi-scale map
In a maze, straight-line distance is a poor guide. Two places can be close in a straight line and far apart on foot, because a wall stands between them. In the maze of this note, there are two places only 7 cells apart, and the shortest route between them takes 63 steps and passes through all six rooms.
An animal that lives in such a maze needs to know which places are really close. And it needs to know this before it has a goal, so that it is ready for any goal that comes later. How could it?
Tolman proposed that animals carry a cognitive map of their environment (Tolman, 1948). In 1971, cells were found in the hippocampus that look like the pieces of such a map (O'Keefe and Dostrovsky, 1971). A place cell fires when the animal is at one particular place. That place is called its place field.
Figure 1 shows what a recording of such cells looks like in the simplest setting, a loop track with no walls. A rat runs around the loop, and every time a cell fires we mark the spot where the rat was. The marks of each cell gather in one stretch of the track.
Figure 1. A simulated recording, for illustration. Each colour is one cell, and each dot marks where the rat was when that cell fired. The other panel shows the firing rate of each cell along the track, estimated from the spikes so far. Each cell is given one preferred place, and its spikes are random with a rate that peaks there. For a real recording of a rat running along a track, see this movie from the Wilson lab at MIT, made by Fabian Kloosterman.
Different cells have different place fields. So together these cells look like a map of the environment.
What makes a map good? A good map untangles the maze. It gives every place a position in a new space, and in that space two places are close when one is easily reached from the other. So on the map, straight-line distance can be trusted again. We say that the maze has been Euclideanized.
How can an animal build such a map before it has a goal? By moving around. The simplest way to move around without a goal is a random walk: at every step, go to a neighbouring place at random. An animal that wanders like this finds out how likely it is to get from one place to another in a given number of steps. We will see that this is all the map needs.
This note builds the map from such a walk, following our paper (Zhao et al., 2025). We will see that one random walk knows the maze at every scale. Cells that record it with non-negative firing rates become place cells on their own, with fields of many sizes. And on the maps they form, planning is just a sequence of local steps toward the goal.
The search for a route does not disappear. It is done in advance, when the map is built, and the same map then serves every goal.
In this note we know the walk exactly, because we know the maze. Part II removes this assumption and learns the map from experience.
To keep things concrete, everything below happens in one small maze with six rooms. Most figures are interactive and computed in your browser.
What does wandering teach?
Let an agent wander in the maze. At every step it picks one of nine options at random: move to one of the eight neighbouring cells, or stay. If the move hits a wall, it stays.
Now ask a simple question. 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 it is the only thing we will need. We call t the horizon.
Click the maze to move the circle.
Figure 2. A random walk in the maze. Many walkers start at the circle, and at every step each of them moves to a random neighbouring cell or stays. Colour: p(y | x, t), the probability that a walker is at y after t steps. Time runs on a log scale.
Watch what the kernel knows as t grows.
When t is small, the walkers are still close to where they started, and they cannot pass through walls. So the kernel measures how far apart two places are along paths one can actually walk. It is like reading a map at street level.
When t is large, the walkers have spread evenly inside a room, and they leak only slowly through the doors. Now the kernel no longer tells two cells of the same room apart. It tells which rooms connect, and in which order. It is like reading the map at district level.
So one random walk carries the geometry of the maze at every horizon, from streets to districts. Our two papers make this precise (Zhao et al., 2025; Kong et al., 2026). At short horizons, in the diffusion limit, the kernel recovers the geodesic distance, the length of the shortest path inside the maze (Varadhan, 1967). At long horizons, a spectral argument applies: only the slowest eigenmodes of the walk remain, and they separate regions joined by narrow passages.
One more fact will matter. The horizons are not independent. A walk of 2t steps is a walk of t steps followed by another walk of t steps, so
where Pt is the matrix whose entries are p(y | x, t). Start from one step, square, and square again, and we get t = 1, 2, 4, 8 and so on. What happens far away is computed from what happens next door. No long trajectory needs to be remembered.
From the kernel to place cells
The kernel is a big table, with one number for every pair of places. The brain does not store tables. It has cells that fire. So we ask how a population of cells could carry the same information.
Think of all the place cells together. At position x, cell i fires at some rate hi(x, t). Collect these rates into one vector h(x, t). This vector is how the population represents the place x at horizon t.
We ask only one thing of these vectors. Two places should have similar vectors if the walk can easily get from one to the other:
The left side is the inner product, which measures how similar two vectors are. The right side is the kernel, rescaled so that every place is perfectly similar to itself:
With this choice q(x | x, t) = 1, and every vector h(x, t) has length one.
Now comes the nice part. Firing rates cannot be negative, so hi(x, t) ≥ 0. Take two places that the walk cannot connect in t steps. Then q = 0, and their two vectors must be orthogonal. But two non-negative vectors can be orthogonal only if they never have the same cell active. So each cell can be active only in a small part of the maze, and it must be silent everywhere else. That part is its place field.
We did not ask for place fields. We asked for equation (2) and for non-negative rates, and place fields came out.
Learning is simple too. Start from random vectors, and reduce the squared difference between the two sides of equation (2), summed over all pairs of places:
After each step, set the negative entries to zero and rescale every vector to length one. Figure 3 shows single cells during this learning.
Figure 3. Learning at horizon t = 64. Each panel shows where one cell fires in the maze (eight cells out of 300). They start from noise and settle into place fields.
Many horizons, many maps
So far we fixed one horizon. But the walk has many horizons, and each horizon gets its own population of cells. What do they look like?
Figure 4 shows them at six horizons, and at two levels. One cell alone is a place cell. The whole population tiles the maze and forms a map.
one cell: a place field
all cells: a tiling
the population: a map
Hover or tap a place to mark it in all panels.
Figure 4. The same maze at six horizons. One cell: the firing rate of the cell that fires most at the marked place, from dark (silent) to yellow (its peak). All cells: the maze divided among the cells. Each place goes to the cell that fires most there, and cells with nearly the same field (cosine similarity of 0.7 or more) count as one. The population: every place of the maze in the embedding space, with the distances of equation (6) below flattened to the plane by multidimensional scaling. In these two panels, colour is the position along the maze. Each horizon has its own cells.
One cell is a place cell. At t = 4 its field covers a few places. At t = 256 it covers one room, and at t = 4096 almost half of the maze. Nobody told the model about rooms. The rooms are in the walk.
How fast do the fields grow? Take an open field with no walls. One step of the walk has variance 2/3 along each axis, so after t steps the kernel is close to a Gaussian, . Gaussian fields then satisfy equation (2):
Here ci is the centre of the field of cell i, and the centres cover the open field evenly. At half of its peak, such a field has area . So the area grows in proportion to t, and the width like
(Figure 5). The hippocampus shows the same pattern: place fields get larger along its dorsoventral axis (Kjelstrup et al., 2008). In the model, moving along that axis is changing t.
the field of the marked cell
Figure 5. Field area against horizon, 500 cells per horizon in a 40 × 40 open field. Dots: cells away from the border. Black: median and quartiles. Dashed: , the area of the Gaussian field of equation (5). Hover or tap a dot to see its field.
Now take all cells at one horizon. In the maze, their place fields tile the space: together they cover every place. In the tiling of Figure 4 the pieces grow with the horizon. There are about two hundred of them at t = 4. At t = 256 they are the six rooms, and at t = 4096 only a few large pieces are left.
In the embedding space, the same population is a map. To see it, note that equation (2) fixes how far apart any two places are in the embedding:
Places that the walk connects easily are close. Places that it cannot connect are far. This is what the opening promised: in the embedding space, straight-line distance says how easily one place is reached from the other. The map of Figure 4 draws these distances on the plane, for every place of the maze.
On the map, at t = 4 the picture still spreads out the inside of every room, and the six rooms stand apart from each other. At t = 256 each room has shrunk almost to a point. The map is now a chain of six nodes, in the order in which the doors connect them. At t = 4096 the map is just a line: how far along the maze we are.
Which map is the right one? None of them alone. The short-horizon maps get nearby places right, but they put all distant places at the same distance, so they know nothing about them. The long-horizon maps get distant places right and blur the nearby ones. A street map and a district map answer different questions. We need both.
Why a map makes planning easy
Now give the agent a goal y. How should it move?
Equation (6) has the answer. Getting closer to the goal on the map is the same as making q(y | x, t) larger. So the agent looks at its neighbours, and it steps to the one that is closest to the goal on the map.
There is one catch: which map? Far from the goal, a street-level map says nothing, because every far place looks equally far. Close to the goal, a district-level map says nothing, because the whole room looks like one point. So we let the agent choose. Among all neighbours z and all horizons t, take the step with the largest gain:
The agent steps to z*, and asks again from there. Write for the distance on the map at horizon t. By equation (6), the gain of a step is half of what it takes off the squared distance to the goal:
So planning becomes gradient descent in the embedding space. At every step the agent takes the move that most reduces its distance to the goal, on the map where a move reduces it most.
Click a start, then a goal. Hover the strip, or drag along it, to scrub.
Figure 6. Planning from the circle to the star. Colour: q(y | x, t) at the horizon in use; the strip shows that horizon at each step.
The starting example of Figure 6 is the pair of places from the opening. The start and the goal are only 7 cells apart, but there is no door between their rooms. The agent goes the long way round, through all six rooms, in 63 steps. That is the shortest possible route.
Look at the strip below the maze. The agent starts with the coarsest map, t = 4096, and switches to finer and finer maps as it gets closer. It uses a coarse map to cross between rooms and a fine map for the last steps. We did not program this schedule. It follows from always taking the largest gain.
Figure 7. The route of Figure 6, in the maze and on the map at t = 512 (drawn as the map of Figure 4).
Figure 7 shows why this is easy. In the maze, start and goal look like neighbours, and the route between them winds through six rooms. On the map at t = 512, start and goal are at the two ends, as far apart as two places can be, and the route simply runs along the map from one end to the other. This is what it means to Euclideanize the maze: a hard problem in the maze is an easy problem on the map.
We tried 1,999 random pairs of start and goal in this maze. The rule reached the goal every time, and the routes were within 0.2% of the shortest on average.
Remark. No successful trajectory and no reward is used anywhere. Planning needs only the kernel of a random walk.
Takeaway
The map is a set of position vectors whose inner products say how reachable one place is from another. There is one set for each horizon: short horizons hold the local geometry, and long horizons hold how regions connect.
With non-negative rates, these vectors are place cells. Each cell fires in one part of the maze, and its field grows with the 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.
For readers who want to try it, the whole model fits in a few lines:
# A[x, y] = 1 when cells x and y are neighbours (eight directions)
P = A / 9 + np.diag(1 - A.sum(1) / 9) # one step: move to a neighbour, or stay
def q(Pt): # rescale so every place matches itself: eq. (3)
d = np.sqrt(np.diag(Pt))
return Pt / np.outer(d, d)
scales, Pt = [], P.copy()
for k in range(15): # t = 1, 2, 4, ..., 16384
scales.append(q(Pt))
Pt = Pt @ Pt # 2t steps = t steps, twice: eq. (1)
def plan(x, y): # walk from x to the goal y
path = [x]
while x != y:
nbrs = np.nonzero(A[x])[0] # where we can step
gain = np.array([Q[nbrs, y] - Q[x, y] for Q in scales])
x = nbrs[gain.max(0).argmax()] # the step with the largest gain, at any scale
path.append(x)
return path
There is still a gap. Above, we computed the kernel from the one-step matrix of the walk, which means we already knew where the walls are. An animal does not know that, and neither does a robot. All it has is its own stream of observations as it wanders. Is that enough? This is the question of Part II.
Next in this series: II. Learning the map from experience.
References
- 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.
- 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.
- E. C. Tolman. Cognitive maps in rats and men. Psychological Review 55, 1948.
- J. O'Keefe, J. Dostrovsky. The hippocampus as a spatial map. Brain Research 34, 1971.
- K. B. Kjelstrup, T. Solstad, V. H. Brun, T. Hafting, S. Leutgeb, M. P. Witter, E. I. Moser, M.-B. Moser. Finite scale of spatial representation in the hippocampus. Science 321, 2008.
- S. R. S. Varadhan. On the behavior of the fundamental solution of the heat equation with variable coefficients. Communications on Pure and Applied Mathematics 20, 1967.