Fig. 5: Decoding of the animal’s movement vectors from grid cell activity.

a, Schematic explaining the transformation of Cartesian position data to a toroidal coordinate system. A detailed explanation is presented in Supplementary Video 1. b, Transforming grid cells in Cartesian space onto the toroidal manifold. Left, Stack of grid cell firing rate maps from random foraging. Grid orientation and period were estimated to define the two main grid axes (v0 and v1). Right, Firing rate maps of the same grid cells in toroidal space. c, Left, A RNN was trained to decode the animal’s position in toroidal space (v0 (blue) and v1 (red)) from the instantaneous firing rate of simultaneously recorded grid cells. The data from the first random foraging trial were used for training. Right, The trained RNN decoded the animal’s position in toroidal space. Toroidal movement vectors were calculated from the change in toroidal position over time. The toroidal vectors were transformed into Cartesian vectors and were summed to reconstruct movement paths. d, Example of real (blue) and decoded (orange) paths during the second random foraging trial. 25 s are shown. The light-gray dashed line represents the arena border. Movement vectors decoded by the model were added to the real position of the mouse at the start of the decoding period for reconstruction. e, Two measures derived from the distribution of decoded directional error. The data from two sessions are shown (light blue and pink). The MVL of these distributions reflects the directional precision of the model (left), whereas their circular means represent the rotation of the grid representation relative to the first random foraging trial (right). The data from two sessions are shown (light blue representing a session with high MVL and low rotation and pink representing an example session with low MVL and significant rotation. Acc, accurate directional precision; Inacc, inaccurate directional precision; NR, no rotation; R, rotation). Shuffled distribution is shown in gray. f, Distribution of decoded directional error for 49 recording sessions with at least five grid cells during the second random foraging trial (RF2). g, Directional precision as a function of the number of grid cells in the model (Pearson correlation, two-sided, N = 49 sessions, r = 0.736, P = 1.67 × 10−9). The data were fitted with a logarithmic equation of the second degree (red curve). h, Examples of real (blue) and decoded (orange) paths during the AutoPI task. i, Directional precision during RF2 and light (L) and dark (D) trials on the AutoPI task compared to shuffled data (N = 24 sessions from seven mice, two-sided Wilcoxon signed-rank test, RF2-L: statistic = 35.0, P = 0.00049, L-D: statistic = 3.0, P = 5.96 × 10−7). Box plots show the median (center line), first and third quartiles (box bounds) and 1.5 times the interquartile range (whiskers). j, Rotation of the grid representation during RF2 and L and D trials on the AutoPI task. k, Cumulative error in position decoding as a function of time from finding the lever during dark trials. ****P < 0.0001, ***P < 0.001.