{'fraction_non_alphanumeric': 0.0358794361802886, 'fraction_numerical': 0.017354727282856985, 'mean_word_length': 4.793899289864429, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Decision and navigation in mouse parietal cortex

Posterior parietal cortex (PPC) has been implicated in navigation, in the control of movement, and in visually-guided decisions. To relate these views, we measured activity in PPC while mice performed a virtual navigation task driven by visual decisions. PPC neurons were selective for specific combinations of the animal's spatial position and heading angle. This selectivity closely predicted both the activity of individual PPC neurons, and the arrangement of their collective firing patterns in choice-selective sequences. These sequences reflected PPC encoding of the animal’s navigation trajectory. Using decision as a predictor instead of heading yielded worse fits, and using it in addition to heading only slightly improved the fits. Alternative models based on visual or motor variables were inferior. We conclude that when mice use vision to choose their trajectories, a large fraction of parietal cortex activity can be predicted from simple attributes such as spatial position and heading.


Introduction
Posterior parietal cortex (PPC) is recognized as a key nexus of sensorimotor integration (Milner and Goodale, 2006), and the large literature concerning its functions has led to disparate views as to its role. These views originate from a broad variety of experiments, some performed in primates and others in rodents.
A number of studies have related PPC activity to the control of body movement (Andersen and Buneo, 2002;Andersen and Cui, 2009;Andersen and Mountcastle, 1983;Bisley and Goldberg, 2010;Cohen and Andersen, 2002;Park et al., 2014). For instance, neurons in monkey PPC can be influenced by movements of eyes, head, limbs, and body (Cohen and Andersen, 2002), by the intention to execute such movements (Andersen and Buneo, 2002), or by the attention devoted to the resulting position (Bisley and Goldberg, 2010). Neurons in rat PPC, moreover, can encode attributes of body posture (Mimica et al., 2018).
Another set of experiments indicates a role of PPC in decision making, especially for decisions based on vision (Andersen and Cui, 2009;Erlich et al., 2015;Goard et al., 2016;Gold and Shadlen, 2007;Katz et al., 2016;Latimer et al., 2015;Licata et al., 2017;Platt and Glimcher, 1999;Raposo et al., 2014;Sugrue et al., 2004). Studies in rodents found decision signals to be widespread in PPC populations, where they are mixed with other signals (Goard et al., 2016;Pho et al., 2018;Raposo et al., 2014). One study, in particular, probed memory-based decision signals and found them to be remarkably common, with each PPC neuron firing only for a particular decision and only at a particular moment in a stereotyped sequence (Harvey et al., 2012).
In principle, all of these views may be correct. Neuronal populations may benefit from a strategy of 'mixed selectivity', where neurons are tuned to mixtures of task-related variables (Rigotti et al., 2013). Mixed selectivity has been observed in PPC neurons of both monkeys (Freedman and Assad, 2009;Park et al., 2014;Rishel et al., 2013) and rats (Raposo et al., 2014) To investigate how spatial navigation, body movement, and decision-making are reflected in PPC activity, we took advantage of the capabilities allowed by virtual reality (Harvey et al., 2009). We trained mice in a virtual navigation task that relies on visual decision-making, and recorded from populations of PPC neurons. The results closely replicated the apparent selectivity of PPC activity on choice, including the arrangement of neurons in choice-dependent activation sequences (Harvey et al., 2012). However, we could predict the activity of PPC neurons based on simple spatial signals: the position of the mouse in the virtual environment and its heading angle. Given the trajectories taken by the mouse, the preferences of the neurons for these attributes predicted the activation of individual neurons and explained their arrangement in sequences. Selectivity for choice, in particular, was fully explained by preferred heading. The predictions improved only slightly when we explicitly added decision as a predictor, and they worsened when we used alternative models based on vision or body movement.

Results
We trained mice in a virtual navigation task driven by perceptual decisions (Figure 1a-c). Head-fixed mice performed a visual two-alternative forced-choice (2AFC) contrast-detection task by walking on an air-suspended ball (Dombeck et al., 2010) through a virtual corridor (Figure 1a, Video 1). One of the corridor's side walls, chosen randomly, contained a vertical grating, and mice indicated that side by turning into the left or right arms at the end of the corridor (Figure 1b). Successful trials were followed by a water reward, and unsuccessful ones by a brief white-noise sound. To control the task difficulty, we varied the grating's contrast randomly across trials. Accordingly, contrast exerted eLife digest When we step out of our homes in the morning, we scan our surroundings to decide which path we should take. It is still unclear whether we use different brain areas to examine the environment, decide on a route, and then set our trajectory, or if a single region can play a role in all three processes. An area in the top of our brain, named the posterior parietal cortex (PPC), may be an intriguing candidate: some studies find that this region is involved in vision, others highlight that it takes part in decision-making, and a third group of experiments shows that it is important for setting paths. Could the PPC be integrating all three types of information, or might the activity of the neurons in this area be better explained by just one of these processes?
Here, Krumin et al. trained mice to use visual clues to navigate a virtual reality maze, where they have to 'walk' down a corridor and then choose to 'go down' the right or the left arm. The rodents move on a ball suspended in mid-air, which acts as a treadmill. Meanwhile, the head of the animal is kept still, making it easier to image the activity of hundreds of neurons in the PPC.
The experiments show that when the mouse uses its vision to choose its trajectory, the PPC does not encode visual signals or abstract decisions. Instead, two navigational attributes -the position of the animal along the corridor and its heading angle -activate neurons in this area. Knowing these two features was enough for Krumin et al. to accurately predict the activity of the neurons in the PPC.
This means that we can forecast the activity of neurons deep in the brain by recording simple behavioral features. The results also suggest that the PPC may be more important for setting trajectories than for processing visual images or making abstract decisions. If these findings were to be confirmed in humans, where the parietal cortex is much more complex, they might help understand better the problems that arise when this area is damaged, for example after a stroke. a powerful influence on performance: mice frequently chose the correct side for high-contrast stimuli, and performed at chance when contrast was low or zero ( Figure 1c).
These visual decisions strongly influenced navigation throughout the corridor, as mice typically turned towards the intended side before reaching the end (Figure 1d-h). To describe the navigation trajectories, we considered two variables: position along the corridor (z) and heading angle (q). In these coordinates, the paths that ended in left and right choices progressively deviated from each  other: the animal started heading towards the chosen side before reaching the end of the corridor. This dependence of heading angle q on decision was particularly clear for trials with higher contrast, which were easier ( Figure 1f). The final choice could thus be predicted from the heading angle with increasing accuracy as the mouse reached the end of the corridor (Figure 1g,h). While mice performed this task, we measured PPC population activity using 2-photon calcium imaging (Figure 1i,j). To identify the borders of visual cortical areas we obtained retinotopic maps using widefield imaging (Figure 1i), and identified PPC as a region anterior to the V1 region, along a contour of pixels that represent a retinotopic azimuth of 60-80 degrees. The average stereotaxic coordinates of this region (Figure 1-figure supplement 1) were close to the coordinates used in previous studies of mouse PPC (2.0 mm posterior, 1.7 mm lateral, Goard et al., 2016;Harvey et al., 2012). We then targeted 2-photon imaging to this region while the mouse was performing the task (Figure 1j). To obtain calcium traces from well-identified cell bodies we applied Sui-te2p, an image-processing pipeline that provides image registration, cell detection, and neuropil correction, followed by manual curation (Pachitariu et al., 2016).
In agreement with previous observations made in a memory-based task (Harvey et al., 2012), all the recorded PPC cells could be divided into two groups forming distinct, choice-dependent sequences of activation (Figure 1k-n). One group of cells responded primarily during trials that ended in a leftward choice (Figure 1k,l), and the other during trials that ended in a rightward choice (Figure 1m,n). Moreover, cells could be ordered so that the responses of each group of cells could be arranged in a sequence of activations (Harvey et al., 2012). While some cells that responded during the initial part of the task tended to fire in both trials that ended with left and right choices, the rest of the cells unambiguously fired only in one or the other of those trials.
To investigate this apparent dependence of activity on choice, we plotted the firing of individual neurons as a function of the animal's position and heading (Figure 2a,b). Consider an example neuron, which fired mostly during trajectories that ended with rightward choices. Plotting the neuron's activity on top of the individual trajectories reveals that the neuron tended to respond in precise combinations of position z (~60 cm into the corridor) and heading angle q (~20 deg to the right). This combination occurred most frequently in trajectories that ended with rightward choices ( Figure 2b) but also occasionally in trajectories that ended with leftward choices (Figure 2a). The neuron was active whenever a trajectory brought the mouse to the appropriate combinations of position and heading, regardless of final choice.
Indeed, a simple 'position-heading field' was sufficient to accurately predict the calcium activity of the neuron (Figure 2c For instance, the position-heading field correctly predicted the occasional trials when the neuron responded during leftward choices (above the black bar in Figure 2c,d).
Position-heading fields provided a good account of the activity across the population (Figure 2hj). High correlation between data and predictions was not associated with a particular preference for position or heading: cells whose responses were accurately predicted could have a variety of position-heading fields (Figure 2h  choice-dependent sequences of activation, replicating the essential features of those seen in the data (Figure 1k-n). These choice-dependent sequences of activation emerge from a combination of two factors: the fact that mice take different trajectories in trials that end with leftward vs. rightward choices (Figure 1d-f), and the fact that different cells prefer different combinations of position and heading (Figure 3c,d).
The preferred heading of these PPC cells was thus sufficient to explain their selectivity for choice: cells with preferred leftward heading were more likely to fire when the animal headed leftward, which occurred most often when the animal ultimately chose the left arm. Indeed, cells that responded preferentially in trials ending in leftward choices almost invariably preferred negative (leftward) heading values (Figure 3c), and the same was true for rightward choices and positive (rightward) heading values (Figure 3d).
Decision was a worse predictor of PPC activity than heading (Figure 4a-c). A model f(z, d) where responses depend on position and decision alone is implicit in representations where neurons are arranged in choice-selective activation sequences (Harvey et al., 2012). It could in principle explain the sequences seen in our data (Figure 1k-n). However, it provided only a rough approximation of the trial-by-trial activity of individual cells, missing its graded dependence on heading angle q ( Figure 4a). To compare the model with the position-heading model f(z, q), we calculated the correlation between trial-averaged measurements and model predictions, and we cross-validated the results. Before averaging activity in each trial, we excluded positions where decision and heading angle were so highly correlated as to be indistinguishable as predictors. The range of positions varied from session to session and invariably included the end of the corridor. This analysis gave a clear advantage to the position-heading model, with correlations higher by 5.6% than for the positiondecision model (±9.8%, m.a.d., n = 7646 neurons, Figure 4b). This advantage was visible also in individual sessions ( Figure 4c). Furthermore, a model with all three predictors performed only slightly better than the model with position and heading alone (Figure 4d-f). We extended the position-heading model to obtain a model f(z, q, d) that includes explicit knowledge of the mouse decisions (d = left or right). This extended model effectively endows the cell with two position-heading fields for trajectories that end in leftward vs. rightward choices. The extended model thus predicted slightly different curves for trials ending in left vs. right choices (Figure 4d). Across all neurons, the extended model performed at a similar cross-validated level as the simple position-heading model, improving the correlations by only 0.4% (±2.9%, m.a.d., n = 7646 neurons, Figure 4e). Similar results were seen in individual sessions ( Figure 4f). Conversely, adding heading angle q to a model that already includes d considerably improved the fits, with a median increase in correlation of 6.1% (±6.1% m.a.d., n = 7646 neurons). Therefore, heading angle was a much better predictor of responses than decision.
Taken together, these results suggest that much of the activity of PPC neurons in our task can be explained by two spatial attributes: position and heading. A possible caveat in this conclusion, however, is that in our experiment those spatial attributes may covary with visual and motor factors. Position and heading determined the visual scene, and the visual scene could in turn determine the activity of PPC neurons, especially given that mouse PPC overlaps at least partially with regions of higher visual cortex (Wang and Burkhalter, 2007;Zhuang et al., 2017). Likewise, position in z-q space is itself determined by the animal's movement on the ball and therefore by motor factors such as linear and angular velocity, which may in turn determine PPC activity (McNaughton et al., 1994;Nitz, 2006;Whitlock, 2014;Whitlock et al., 2012).
To assess the role of visual factors, we ran a control experiment where the animal passively viewed a playback of visual scenes presented in the task on the same session. In this playback condition only a minority of PPC neurons maintained their preferences for position and heading, and even in those neurons the responses were much weaker (Figure 4-figure supplement 2a). Moreover, for the majority of PPC cells, activity in the playback condition was not predictable from the preferences for position and heading estimated during the task. This is perhaps remarkable, given that parietal areas of the mouse cortex are considered to overlap with visual areas RL, A, and AM (Hovde et al., 2018;Kirkcaldie, 2012), which contain retinotopic visual representations (Garrett et al., 2014;Wang and Burkhalter, 2007). By comparison, responses measured in primary visual cortex (V1) during the task and during playback were in better agreement (Figure 4-figure supplement 2b).
To assess the role of motor factors, we evaluated a model where PPC activity depends on the mouse's movement, measured by the ball's angular and linear velocities. These quantities are related to the derivatives of position z and heading q, but they are not identical because they are in mousecentered coordinates and are unconstrained by the boundaries of the virtual corridor. The model based on motor factors performed markedly worse than the model based on position and heading in virtual reality (Figure 4-figure supplement 3).
We finally asked if PPC population activity and its dependence on position and heading were sufficient to decode the details of the mouse's trajectories and choices ( Figure 5). Using established methods (Oram et al., 1998;Zhang et al., 1998) (Figure 5d). This result provides further support for the view that during visuallyguided navigation, populations of PPC neurons encode spatial position and heading angle.

Discussion
We used a virtual reality task where mice use vision to decide and navigate, and we found that the activity of PPC neurons can be accurately predicted based on two simple spatial measures: position of the animal along the corridor, and heading angle. Using only these attributes, we could predict a large fraction of PPC activity during a complex task involving body movement, vision, decision, and navigation. These predictions are superior to those based purely on vision or on body movement.
These results resonate with the view that rodent PPC encodes combinations of spatial attributes (McNaughton et al., 1994;Nitz, 2006;Nitz, 2012;Save and Poucet, 2000;Save and Poucet, 2009;Whitlock et al., 2012;Wilber et al., 2014), but are also fully consistent with the observation that PPC cells can be divided into groups forming distinct sequences of activations depending on upcoming choice (Harvey et al., 2012). However, in our data, this division into choice-dependent sequences, and indeed the sequences themselves, could be explained by the effect on PPC of two measurable factors: the trajectories taken by the mouse in different trials, and the preferences of different cells for different combinations of position and heading. The selectivity of PPC cells for heading and position explained the cells' apparent selectivity for the mouse's decision.
Our results therefore appear to support a different view of PPC function to that proposed by Harvey et al. (2012). Perhaps this discrepancy is due to a difference between the tasks: for example in our task, unlike the main task by Harvey et al, the spatial cues indicating the appropriate decision were visible until the end of the corridor. This might have caused the animals to employ different strategies, resulting in genuinely different types of PPC coding across the two tasks.
It is also possible, however, that the same combination of spatial factors also contributed to the results of Harvey et al. (2012). Indeed, the animals' trajectories in that study did exhibit differences in heading angle that correlated with the final decision, but trials showing such differences were progressively excluded from analysis until the difference in mean heading angle no longer reached statistical significance. It would therefore be interesting to test whether preferences for position and heading may also contribute to the apparent decision-selectivity in Harvey et al.'s full data set.
In conclusion, we found that the activity of neurons in PPC during a task involving movement, vision, decision, and navigation, can be accurately predicted based on the selectivity of the neurons for two spatial variables: the position of the mouse along the corridor, and its heading angle. Consideration of this selectivity, and the mouse's trajectories through virtual space, fully accounts for the apparent formation of decision-dependent activity sequences in this task. In other words, when mice use vision to guide navigation, parietal cortex encodes navigational attributes such as position and heading rather than visual signals or abstract decisions.
Our results, however, do not completely rule out a possible role of decision signals in shaping the responses of PPC neurons. We found that adding decision as an explicit variable barely improved the fits of the position-heading model, but did not make them worse as it could have, given that the model fits were cross-validated.
Our task, in fact, cannot fully distinguish encoding of navigation variables and of decisions, because trajectory signals might strongly covary with an evolving decision variable. Such an evolving decision variable might be seen not only in covert neural signals, but also in ongoing body movements (Dotan et al., 2018;Resulaj et al., 2009;Song and Nakayama, 2009;Spivey et al., 2005). In our task, the clear dependence of trajectories on stimulus contrast is consistent with a close relationship between a decision variable and the animal's trajectories. It may not be possible to distinguish the neural encoding of the two.
Moreover, PPC activity could be influenced by a multitude of postural attributes that we did not monitor, and some of these may correlate with the apparent decision signals that improved our fits. Indeed, there is mounting evidence that postural and other motor variables act as powerful determinants of activity throughout the cortex (Musall et al., 2018;Stringer et al., 2018) including PPC (Mimica et al., 2018). The same observation, in fact, can be made for the apparent selectivity of PPC neurons for heading: perhaps neurons in PPC are sensitive to postural variables that in turn predict heading.
The precise motor, postural, or cognitive correlates of heading and decision need further examination, ideally with tasks explicitly designed to distinguish these correlates. In the meantime, our results indicate that the activity of large populations of PPC neurons can be explained based on simple embodied quantities such as heading and position in the environment.
The recordings from the three Ai93-Emx1 mice were made before we realized that this strain tends to show epileptiform activity (Steinmetz et al., 2017). We tested our recordings for this activity and the results were negative. However, we only imaged posterior regions of the cortex, where epileptiform activity can be missed (Steinmetz et al., 2017). For this reason, we recorded from the other strains and we ran a mouse-by-mouse analysis. This analysis did not reveal differences between the strains we used (Figure 4-figure supplement 1), so we pooled the data across all of them.

Surgery
For the initial surgery the animal was anesthetized with isoflurane (Merial) at 3-5% for induction, and 0.75-1.5% subsequently. Carprofen (5 mg/kg weight, Rimadyl, Pfizer) was administered subcutaneously for systemic analgesia, and dexamethasone (0.5 mg/kg weight, Colvasone, Norbrook) was administered to prevent brain swelling. The scalp was shaved and disinfected, and a local analgesic (Lidocaine, 5% ointment, TEVA UK; or intradermal injection, 6 mg/kg, Hameln Pharmaceuticals Ltd) was applied prior to the incision. The eyes were covered with eye-protective gel (Viscotears, Alcon; or Chloramphenicol, Martindale Pharmaceuticals Ltd). The animal was positioned in a stereotaxic frame (Lidocaine ointment was applied to the ear bars), the skin covering and surrounding the area of interest was removed, and the skull was cleaned of connective tissue. A custom headplate was positioned above the area of interest and attached to the bone with Superbond C and B (Sun Medical). Then, a round craniotomy (3-4 mm diameter) was made with a fine-tipped diamond drill and/or a biopsy punch (Kai Medical). A cranial window was inserted into the craniotomy and fixed with Vetbond (3M) and Superbond C and B. The cranial window consisted of two superimposed round coverslips (WPI, #1 thickness) -one matching the inner diameter of the craniotomy (3-4 mm), and the other one providing mechanical support on the skull (typically 5 mm diameter). The two coverslips were glued together beforehand using a Norland optical UV curing adhesive (NOA61, ThorLabs Inc.). After the surgery the animal was allowed to recover for at least three days before any behavioral or physiological measurements.
In C57Bl/6 mice, we injected the virus AAV2/1.Syn.GCaMP6f.WPRE.SV40 at a final concentration of 2.3e12 GC/ml before covering the craniotomy with the window. 100 nl of the virus was injected 300 mm below the brain surface at each of two locations targeting PPC (AP = À2 mm, ML = 1.7 mm) and V1 (AP = À3.5 mm, ML = 2.5 mm). The virus was injected at a rate of 2.3 nl every 6 s (Nanoject II, Drummond). The injection pipette was kept in place for about 10 min after the injection to allow full absorption of the virus solution in the tissue.

Water control
To motivate the mice to perform the task we controlled their water intake. Mice obtained a drop of water (typically 2 or 4 ml) for every correct choice. If the water obtained during the task was below the minimum daily dose (40 ml/kg/day), mice received the rest of the dose through an appropriately weighted amount of Hydrogel. On rest days (typically Saturday and/or Sunday) the mice received all their dose through Hydrogel.

Virtual reality setup
The mouse was head fixed with a headplate holder that did not obstruct the visual field. The mouse was free to run on an air-suspended Styrofoam ball (20 cm in diameter), whose rotation was measured by two optical computer mice (Dombeck et al., 2010) and then used in a custom virtual reality engine implemented in Matlab utilizing OpenGL through the Psychophysics Toolbox (Brainard, 1997;Pelli, 1997) to control the visual scene. The rotation of the ball along the axis perpendicular to the animal was responsible for forward movement in virtual reality, and the rotation of the ball along the vertical axis (at 20% gain) was responsible for turning in virtual reality. The lateral displacement of ball (rotation along the axis parallel to the animal's orientation) was ignored. The virtual reality scene was presented on three computer monitors (Iiyama ProLite E1980SD, 1280 Â 1024 pixels, 60 Hz) positioned in a U-shaped configuration around the mouse spanning 270 degrees of the visual field horizontally and 75 degrees vertically. We used a multiplex video card (Matrox Triple-Head2Go Digital Edition) to present the visual stimulus on three monitors in a synchronized manner. The light intensity response of the green and the blue channels of the monitors was linearized, while the red component was switched off to reduce light contamination in the fluorescence channel. In addition, to compensate for the light intensity drop-off at sharp viewing angles we attached three Fresnel lenses (f = 22 cm, BHPA220-2-6, Wuxi Bohai Optics Apparatus Electronic Co., Ltd, Wuxi, Jiangsu, China) in front of the monitors.

Behavior
The virtual reality environment consisted of a 110 cm long T-Maze with a 20 cm wide corridor. Virtual position was never allowed to be less than 5 cm to any wall. During a trial, a vertical grating appeared on the left or right wall of the corridor. The grating was superimposed on a noise texture (20% visual contrast), which was identical on both walls and across trials. The spatial frequency of the grating was 14 cycles/m, and the resulting spatial frequency in the mouse visual field (in cycles/deg) varied depending on the distance and angle of the wall relative to the mouse. To provide additional visual flow and context, a 40% visual contrast noise pattern was applied to the floor of the corridor (and the ceiling, in some experiments). The sequence of grating contrasts was randomly drawn from a uniform distribution, with negative values indicating positions on the left wall, and positive values positions on the right wall. However, to prevent the animal from developing behavioral biases, trials ending in a wrong choice were repeated until finished correctly, at which point the next trial in the sequence was again a random trial. This 'baiting' strategy was applied mainly when the animals displayed a behavioral bias. Correct trials were indicated by a brief beep (0.1 s, 6.6 kHz) tone, while error trials were indicated by a brief (0.2 s) white noise sound. During the inter-trial interval (~2 s) the screen was gray. Trials not finished within 45 s were timed out and a longer (3 s) white-noise sound was played. Mice typically performed between 200 and 400 trials per session (session duration 45-60 min), with typical duration of the finished trials of 6.0 ± 2.0 (median ±m.a.d.) seconds, varying between 4.7 and 11.6 s (median values) for individual animals. The behavioral session was aborted when either the animal stopped performing, or stopped consuming the water reward. Mice required different numbers of training sessions to reach behavioral performance sufficient to be considered for imaging (7 to 36 sessions, 21 on average across seven animals).

Playback
Playback trials were run immediately after the actual behavioral session, while recording the same cells. The water spout was removed, and the visual stimulus was constructed by chopping the sequence of visual scenes into 0.5 s segments and presenting them in randomized order. To reduce the flickering effect of the visual stimulus, each 0.5 s segment was modified by sinusoidally modulating the contrast at the frequency of 2 Hz, thus smoothing the transition between sequential segments. The animal was free to run on the ball, but this had no effect on the visual stimuli presented. Typically, during these measurements the animals chose to alternate bouts of running with periods of rest.

Two-photon imaging
Two-photon imaging (total of 33 recording sessions) was performed using a standard resonant B-Scope microscope (ThorLabs Inc.) equipped with Nikon 16x, 0.8 NA objective, and controlled by ScanImage 4.2 (Pologruto et al., 2003). Frame rate was set to~30 Hz, with the field of view of~500Â500 mm (512 Â 512 pixels). This frame rate was further shared between 3-5 imaging planes spanning the depth of L2/3 using a piezo focusing device (P-725.4CA PIFOC, Physik Instrumente) resulting in a 6-10 Hz effective sampling rate per cell. Laser power was depth-adjusted and synchronized with piezo position using an electro-optical modulator (M350-80LA, Conoptics Inc.). The imaging objective and the piezo device were light shielded using a custom-made metal cone, a tube, and black cloth to prevent contamination of the fluorescent signal caused by the monitors' light. Excitation light at 970 nm was delivered by an Ultra II femtosecond laser (Coherent, UK)

Data preprocessing
Preprocessing of the two-photon data routinely included registration, segmentation, and neuropil correction (. The whole cell detection pipeline is explained in Pachitariu et al., 2016. ). To analyze playback experiments we also applied a deconvolution algorithm to extract spikes from the continuous calcium data (Vogelstein et al., 2010). To calculate DF/F, the baseline fluorescence F 0 was taken as the 20th percentile of the overall level of fluorescence of a cell.

Estimation of z-maps
To estimate the position-heading field of each neuron we used a local likelihood approach (Loader, 1999). First, we used the data to estimate the occupancy map M occ z; ð Þ and the accumulated fluorescence signal map M sig z; ð Þ. Then, we filtered both maps with a Gaussian filter, and we calculated the resulting position-heading field as: Where F mean is the mean fluorescence of the cell, and l is a small number used for regularization, to prevent large estimation errors in location where little or no data is available in z-q space.
The size of the Gaussian filter s z ; s f g was optimally chosen for each cell through a 10-fold crossvalidation procedure. In this procedure, for each set of values s z ; s f g 90% percent of the trials (training subset) were chosen to estimateF z; ð Þ. Then, performance of the modelF z; ð Þ was measured on the remaining 10% of the trials (test subset). On each fold the following error function was used to estimate the performance of the fit: Where F train mean is the average DF=F of the training (90%) subset of the data. The procedure was repeated 10 times for different 90/10 partitions of the data. The set of filter values s z ; s f g, which resulted in the best overall performance of the model was chosen as optimal and used in subsequent analyses for that neuron.

Models involving decision
Models incorporating decision were estimated using a similar cross-validation approach. The data for trials ending in leftward and rightward choices were treated separately. For each half of the data, we estimated the optimal s z (for the f z; d ð Þ model) or s z ; s f g (for the f z; ; d ð Þ model) using the same cross-validation procedure as for the f z; ð Þ model, explained previously. This effectively resulted in two sub-models for each model (f z; d ð Þ or f z; ; d ð Þ), with two sets of optimal smoothing parameters -one for trials ending in leftward choices and one for trials ending in rightward choices. The two sub-models were then taken together to predict calcium activity on the full set of trials.

Quality of fit analysis
Depending on the model, different combinations of behavioral parameters (z-q, z-d, or z-q-d) were used to predict each cell's activity. For each session the data were randomly divided into 10 groups of trials (with balanced rightward and leftward trials in each group). For each group of trials, the activity was predicted using the other 90% of the datas z or s z ; s f g. The Pearson's correlation coefficient between mean trial-by-trial actual and predicted responses was used to evaluate and compare performance of different models.
At certain positions (z) of the T-Maze (typically towards the end of the corridor), heading (q) and final choice (d) become strongly correlated. To increase sensitivity of the comparison between the models we excluded data coming from these times (effectively, when the mouse is at certain z positions) when estimating quality of fits ( Figure 4). For each behavioral session and for each position z we have estimated the area under the ROC (auROC) curve for two variables -heading and choice (which is a measure of how well one can be predicted from another). On a session-by-session basis, data from positions z where the auROC curve was greater than 0.95 were excluded from the estimation of fit quality.

Analysis of playback data
Calcium dynamics measured with GCaMP6f is slow, with decay times as long as a few hundreds of milliseconds (Chen et al., 2013). During playback presentation of 0.5 s visual stimuli, this slowly decaying signal will cross-contaminate responses to sequential stimuli. Therefore, for the analysis of the playback experiment, where this issue is critical, we used inferred firing rate (Vogelstein et al., 2010) and not DF/F. To compare activity between the behavior and playback conditions at the corresponding 0.5 s segments, we used the correlation coefficient between the inferred firing rates (binned at 0.5 s).

Decoding of population responses
To predict the distribution of locations in z-q space visited by the animal during the session (Pr z; ð Þ) we used the position-heading fields ( i z; ð Þ estimated separately for each cell i), and employed a Bayesian decoding approach.
Below we show that in this approach, the posterior probability distribution for the animal's position in z-q space at time t is: log Post z; ð Þ ¼ À i X i z; ð Þ À r i t ð Þ ð Þ 2 2s 2 i þ log Pr z; ð Þ þ const where r i t ð Þ is the response of cell i at time t, and s 2 i is the overall variance of the response of cell i throughout the session.