The Supplementary Information provides a detailed discussion. a, Compass-neuron calcium transients measured during closed-loop tethered flight in an artificial scene, arrangement A (A). The conventions are the same as in Fig. 1h. b, Calcium transients from the same fly as in a, but with a different artificial scene, arrangement B (B). c, Distribution of the mean offset of each trial, pooled across all flies (Methods). Distributions of offsets relative to scenes A and B were not significantly different from uniform (n = 40 trials from 10 flies, unimodality test by randomization, P = 0.0819 for A, P = 0.1525 for B). Compare with Fig. 1j. d, Distribution of offset shifts between two trials. The distribution of offset shifts between two artificial scenes, measured across flies, was significantly different from uniform distribution (unimodality test by randomization, from A to B, n = 10 flies, P < 0.0001; from B to A, n = 10 flies, P < 0.0001). The shift in offset was similar across different encounters with same scene, indicating that the offset was stable (unimodality test by randomization, from A to A, n = 10 flies, P = 0.0001; from B to B, n = 10 flies, P = 0.0004). Compare with Extended Data Fig. 6e. e, Parameter sweep to explore how two-dimensional Gaussian filters of different s.d., applied to the artificial scenes in a (arrangement A) and b (arrangement B), would affect shifts in offset between the two scenes. Filters represent the simplified effect of ring-neuron filtering of scenes. Shifts in offset should approximately match azimuthal shifts that would produce the best match (that is, maximum two-dimensional cross-correlation) between the filtered scenes. Each axis represents increasing s.d. of the applied two-dimensional Gaussian filter (g). The point marked with a red X is shown in f. f, Two-dimensional cross-correlation between two scenes in a and b after applying two-dimensional Gaussian filtering with 15° s.d. (red X in e). This filter size corresponds to a 30° full-width at half-maximum receptive field, which matches the average size of the minor axis of ellipses that fit ring-neuron receptive fields13,39. Higher filter sizes up to 60° full-width at half-maximum (the average size of the major axis of elliptical fits of ring-neuron receptive fields13,39) require similar azimuthal shifts to obtain a best match between the scenes (not shown in e). The azimuthal shift for the best match for this range of filters is 165°, a half rotation of the scene on the visual arena (as observed in d). g, Scenes in a and b after applying Gaussian filtering with 15° s.d. h, i, Simulation of pre- and post-synaptically gated plasticity rules applied when the model network is exposed to the two different filtered scenes shown in g. h, Evolution of the synaptic weight matrix with a pre-synaptically gated plasticity rule. Top left, initial random synaptic weight matrix from 8 × 32 ring neurons to 1 of 32 compass neurons. Top right, after exposure to scene A. Each compass neuron responds most to a snapshot of the scene at a particular orientation. Second row, after exposure to scene B, a new snapshot is mapped to the compass-neuron heading representation. The locations of the top two horizontal bars in arrangements A and B overlap (red rectangles), which corresponds to a 165° shift in the two-dimensional cross-correlation in e and f (or a 180° shift in the 360° arena in simulations). This deterministic offset shift results in the same pinning offset and a retrieval of the same heading representation as before when the scene is repeated later (bottom two rows). The third and fourth rows show repeated exposure to scenes A and B. Bottom two rows, retrieval of the original offset. i, Evolution of the synaptic weight matrix with post-synaptically gated plasticity rule. The result is almost identical to h, given that all ring neurons and compass neurons are activated during simulation. j, k, Simulated offset shifts with pre-synaptically (j) and post-synaptically (k) gated plasticity rules. For each rule, 100 simulations were performed. Both the pre-synaptic and the post-synaptic rules reproduced the population data in d.