Skip to content
  1. Projects

3D spatial cells

A model trained only on flat 2D movement develops 3D spatial tuning on its own.

3D spatial cells
  • TensorFlow
  • NumPy
  • MATLAB
  • FastAPI
  • Streamlit
  • Docker
2,655
paper accesses
5
mazes tested
50
model neurons

What you are seeing

  1. The agentMoves like a rat, using real rat movement statistics
  2. Its pathA short trail behind the agent
  3. One neuron firingEach dot is a spike from unit 13
  4. A column formsIt stretches along gravity, not across the floor

Timeline

  1. 2021Research startsIIT Madras, funded by SERB (now ANRF)
  2. 2024Paper publishedScientific Reports
  3. 2026Live demoAnyone can try it

We trained a small autoencoder only on flat 2D movement, and its units became place and grid cells that stretch along gravity in 3D mazes, as in real rats. I then took the research code to a public app and hardened it.

Research

The problem

Rats in 3D climbing mazes have place fields that stretch along the vertical axis, unlike the compact fields of flying bats. Grieves and colleagues (2020) saw this in an upright lattice but not in a tilted one. Hayman and colleagues (2011) saw it on a helix and a pegboard.

When we started, almost no model covered 3D. Our question: can one model, trained only on a flat floor with no position labels, reproduce all four results?

Training on a flat arena, then testing on four 3D mazes: aligned lattice, tilted lattice, helix and pegboard TRAIN · 2D ONLY TEST · 3D, NEVER SEEN Flat arena Aligned lattice Tilted lattice Helix Pegboard
Training on a flat arena, then testing on four 3D mazes: aligned lattice, tilted lattice, helix and pegboard TRAIN · 2D ONLY Flat arena TEST · 3D, NEVER SEEN Aligned lattice Tilted lattice Helix Pegboard
Figure 1. Train on the flat arena, test on four 3D mazes.

Research

Key decisions

One simple model for 2D and 3D. Our earlier 2D models used a lateral anti Hebbian network. We replaced it with a single linear autoencoder, 80 → 50 → 80, so the same model and training serve every maze and only the input angles change.

Encode movement, not position. 80 head direction cells feed path integration, PIᵢ = cos(β · z·uᵢ), where z is the distance from the start. The model only learns to rebuild its input; the 50 bottleneck units are what we read as neurons.

Copy how the real rats moved. We built trajectories by sampling from the movement statistics the original studies report. In the lattice, for example, the agent climbs 20% of the time.

How the model turns movement into place cells Five steps: the rat's movement, distance along 80 directions, a wave for each direction, an autoencoder that squeezes 80 signals into 50 and rebuilds them, and the 50 middle units, which each fire in one spot like place cells. 1 · MOVEMENT Where the rat is, from its start. position z 2 · 80 DIRECTIONS How far it went in each direction. uᵢ: 20 × 4 angles 3 · A WAVE EACH Each distance becomes a wave. cos(β · z·uᵢ) 4 · SQUEEZE 80 signals into 50, then rebuilt. 80 → 50 → 80 5 · 50 NEURONS Each fires in one spot: a place cell. trained on 2D only
How the model turns movement into place cells Five steps: the rat's movement, distance along 80 directions, a wave for each direction, an autoencoder that squeezes 80 signals into 50 and rebuilds them, and the 50 middle units, which each fire in one spot like place cells. 1 · MOVEMENT Where the rat is, from its start. position z 2 · 80 DIRECTIONS How far it went in each direction. uᵢ: 20 × 4 angles 3 · A WAVE EACH Each distance becomes a wave. cos(β · z·uᵢ) 4 · SQUEEZE 80 signals into 50, then rebuilt. 80 → 50 → 80 5 · 50 NEURONS Each fires in one spot: a place cell. trained on 2D only
Figure 2. Only movement goes in; the bottleneck learns the spatial code.

Research

What we found

In 3D, erosion analysis showed fields stretching along the vertical axis in the upright lattice and no preferred axis in the tilted one, as in rats. On the helix and pegboard, fields ran across coils and layers, with less information about height than about horizontal position.

Where it disagrees: helix fields came out far longer than in the experiment (aspect ratio 11.28 against 1.99 on the floor), because field width depends on β.

Left: an upright lattice maze where one unit's firing forms a vertical column. Right: a tilted lattice maze where a unit's firing stays in compact blobs. An arrow beside each shows gravity.
  • Where one unit fires
  • Gravity
Figure 3. Unit 13 in the upright lattice fires in a vertical column. Unit 25 in the tilted lattice keeps compact fields.
Eight small heat maps: four with a single bright spot, four with repeating spots.
One spot: place cellsRepeating spots: grid like

One spot: place cells

Four small heat maps, each with a single bright spot.

Repeating spots: grid like

Four small heat maps, each with repeating spots.
Figure 4. Eight of the 50 units on the flat floor.

Product

From paper to product

How I shipped it

I turned the offline Python and MATLAB pipeline into a public app: pick a maze, run the model, flip through all 50 neurons, or retrain with your own settings. I picked the Docker SDK on Hugging Face Spaces over the Streamlit SDK to control the serving layer, and FastAPI for Pydantic validation and generated API docs. Model weights broke plain Git pushes, so I moved them off it. A scheduled ping keeps the Space awake.

How I hardened it

A later review of the live demo found five problems, listed below. I fixed each one and checked the result with 13 API tests and a scripted click through of the interface. Retraining is now bounded by the API, not just the sliders, with a 240 s wait limit.

How the live demo is built A visitor's browser talks to a Hugging Face Space. Inside one Docker container, a Streamlit interface calls a FastAPI model server on the same machine. The server has three endpoints, preview, compare and retrain, and loads the trained weights, precomputed maps and maze paths once at startup. Custom models are kept per visitor. Visitor Any browser HTTPS HUGGING FACE SPACE · ONE DOCKER CONTAINER · PYTHON 3.11 INTERFACE Streamlit public port 7860 Pick mazes, run the model, flip through neurons, set a spike threshold, retrain with your own settings. Each visitor gets a session id, so custom models never mix between people. local MODEL SERVER FastAPI internal port 8000 /preview maze paths, thinned 10× /compare runs the model, compact binary response /retrain trains a model, one at a time LOADED ONCE Trained weights 2D maps, computed ahead of time 6 maze paths, 430k points Custom models, kept in memory per visitor Startup: the interface only starts once the model server answers /health.
How the live demo is built A visitor's browser talks to a Hugging Face Space. Inside one Docker container, a Streamlit interface calls a FastAPI model server on the same machine. The server has three endpoints, preview, compare and retrain, and loads the trained weights, precomputed maps and maze paths once at startup. Custom models are kept per visitor. Visitor Any browser HTTPS HUGGING FACE SPACE ONE DOCKER CONTAINER · PYTHON 3.11 INTERFACE Streamlit public port 7860 Pick mazes, run the model, flip through neurons, set a spike threshold, retrain with your own settings. Each visitor gets a session id, so custom models never mix between people. local MODEL SERVER FastAPI internal port 8000 /preview maze paths, thinned 10× /compare runs the model, compact binary response /retrain trains a model, one at a time LOADED ONCE Trained weights 2D maps, computed ahead of time 6 maze paths, 430k points Custom models, kept in memory per visitor Startup: the interface only starts once the model server answers /health.
Figure 5. One container: interface, model server, data loaded once.
ProblemWhat I changedResult
Wrong layer shownRebuilt the encoder from the trained model’s first layer, so the 50 units show instead of the 80 value output.r = 1.0000 against stored results
Huge responsesPer neuron uint8 activity sent as base64 instead of float lists.177 MB → 3.7 MB per maze
Slow maze runsPath integration as one matrix product instead of a Python loop.21.6 s → 4.8 s
Shared modelModels stored per session (16 most recent), training behind a lock.One model per visitor
Unchecked inputsEvery limit enforced in the API; maze names from a fixed list.No path traversal

Honest limits

Limits and next steps

  • Movement onlyNo vision or landmarks, so no drift correction. My next project adds it. See it →
  • No timingTheta rhythm and spike timing are left out.
  • Rats, not batsHeadings are mostly horizontal; free flight needs full 3D tuning.
  • Free serverThe Space sleeps when idle; waking takes about a minute.