A perceptual decision requires sensory but not action coding in mouse cortex

Sensory decisions involve multiple cortical areas, but it is unclear to what extent these areas carry distinct signals and play causal roles. We trained head-fixed mice to discriminate visual contrast and report their decision by turning a wheel. Widefield calcium imaging and Neuropixels recordings revealed stimulus-related activity in visual (VIS) and secondary motor (MOs) areas, and widespread movement-related activity across the dorsal cortex. Optogenetic inactivation biased choices only when it was targeted at VIS and MOs, at times corresponding to peak stimulus decoding. A neurometric model based on summing and subtracting activity in VIS and MOs successfully described performance, and predicted the effect of optogenetic inactivation. Thus, sensory signals in VIS and MOs are causally necessary for task performance, while diffuse cortical signals encoding movement do not play a causal role in the animals’ choice.


Introduction
When presented with multiple behavioral options, an animal must choose one, if any, of these options, and execute the associated action. These processes of choice and execution may be served by the multiple brain regions where neural activity correlates with upcoming actions [1][2][3][4][5][6][7][8] .
Distinguishing neural activity related to choice from activity related to sensation or action, however, is challenging. A key confound when attributing neural responses to choice is the widespread activity that pervades the brain before actions 6,[9][10][11][12][13] . The most common neural correlates of behavior appear to be with whether the animal will move at all, rather than which particular action will be chosen. For example, in a multi-alternative visual discrimination task, neurons in nearly all brain structures are modulated prior to upcoming actions, whereas neurons predicting which action will be chosen are rare and confined to specific regions such as basal ganglia, midbrain, and frontal cortex 6 .
It is unclear whether this widespread, non-specific premovement activity is necessary for movement. Traditional theories would not predict that brain-wide activity is required for simple sensory-motor tasks, and in some well-trained behaviors, cortical inactivation has little effect 14,15 . However, in other simple tasks such as licking following a whisker deflection, performance is impaired by inactivation of many structures, including medial prefrontal cortex and hippocampus 16 .
Inactivating a brain region during a choice task could have three potential consequences. First, inactivation could bias the choices, implicating the inactivated neurons in a sensory or choice circuit [17][18][19][20] . Second, inactivation might disrupt the execution of the chosen action, for example delaying it or reducing its accuracy 21 , but not affecting the probability of the choices. This would implicate the neurons in circuits for executing a chosen action, but not for the choice itself. Finally, inactivation might have no effects on the current trial, suggesting that the region's activity in the task reflects corollary discharge (feedback from other brain areas involved in action selection and execution 22 ), or cognitive processes such as memory, which only affect subsequent choices 23,24 .
Here we use imaging, electrophysiology, and inactivation to reveal the roles of dorsal cortical regions in vision, action and choice. We trained mice in a visual choice task 25 and found correlates of vision (regardless of behavioral output) in visual and frontal cortex, and correlates of action (initiation of any movement, regardless of stimulus and choice) everywhere, but strongest in primary motor and somatosensory cortex. Correlates of choice (regardless of stimuli) were not visible with widefield imaging and were revealed electrophysiologically only in rare neurons in frontal areas. The effect of optogenetically inactivating a region closely mirrored its encoding of sensory stimuli rather than its encoding of action or choice. Inactivating primary motor cortex (which had the strongest action correlate) had no effect beyond a slight decrease in peak movement velocity. We constructed a model of choice where a downstream circuit integrates cortical activity to produce a stochastic decision. This model predicted the effects of optogenetic inactivation, despite inactivation data playing no part in fitting its parameters. These results provide a quantitative and causal account for how cortical activity contributes to choice formation, revealing that the causal role of dorsal cortical regions reflects their representation of sensation rather than action.

Results
A visual discrimination task affording multiple types of error We trained mice to perform a two-alternative unforcedchoice visual discrimination task 25 (Fig. 1). Mice were head-fixed with their forepaws controlling a steering wheel surrounded by three screens (Fig. 1a). Each trial began after the wheel was held still for a minimum duration. Grating stimuli appeared in the left and right screens together with an auditory Go cue (Fig. 1b-d). Mice were rewarded with water for rotating the wheel Left or Right to bring the higher-contrast stimulus into the center, or for holding the wheel still for 1.5 s (NoGo) if no stimulus was present. Unrewarded trials ended with a 1 s white noise burst. Mice became proficient in the task, achieving 86 ± 9% correct choices (mean ± SD) on trials with single high contrast gratings, and the probability of their choices varied with the contrasts of the two gratings ( Fig. 1e-h). In the absence of visual stimuli, moreover, mice correctly held the wheel still (NoGo) in 54 ± 16% of the trials.
In this task design, mice could make multiple types of error (Fig 1h). When a stimulus was present, mice could err with a NoGo (a "Miss" trial, 16 ± 13% of all trials where a stimulus was present on one side, mean ± SD across sessions) or with a wheel turn in the incorrect direction ("Incorrect choice", 7 ± 4%). The probability of both types of error increased with decreasing stimulus contrast, reaching a maximum of 27 ± 21% Miss rate and 9 ± 8% Incorrect rate for single low-contrast stimuli on one side (Fig. 1h). These two types of errors permit us to separate the overall tendency to respond (Choice versus Miss) from the accuracy of perceptual discrimination (Correct versus Incorrect choices). Activity related to stimuli and movement in the dorsal cortex Widefield imaging revealed that the visual stimulus elicited a sequence of activations in the contralateral cortex, followed by widespread bilateral activity before a movement (Fig. 2a-e). Activity began in the primary visual cortex (VISp) 47 ± 2 ms after stimulus onset (time to 30% of peak; median ± m.a.d. across 6 mice), spreading to secondary visual areas (e.g. VISal at 54 ± 4 ms), and then to frontal cortex (secondary motor area MOs at 97 ± 6 ms; Supplementary Figures S1, S2). The pattern of activity during these first 100 ms appeared to be independent of the trial's outcome of Go (Left or Right) or NoGo (Fig. 2b,c). Later activity, however (150-200 ms following stimulus), strongly depended on whether the stimulus evoked a movement, with widespread bilateral activity seen on Go trials but absent on NoGo trials (Fig. 2b,c; Supplementary Figure S1; Supplementary Movies 1 and 2). This widespread activity preceded the mouse's choice, which did not occur until 229 ± 28 ms after stimulus onset (median ± m.a.d. across 39 sessions). However, while cortical activity was very different between Go and NoGo trials evoked by the same stimulus, cortical activity preceding Left vs. Right responses to the same stimulus appeared to be indistinguishable (Fig. 2d,e).
We analyzed these activations with a decoder, revealing extensive correlates of sensory and action variables but no correlates of choice ( Fig. 2f-h). We used the Combined Conditions Choice Probability 6 (CCCP) measure, which tests whether one can decode a behavioral or stimulus variable from neural activity observed at a single place and time, while holding all other behavioral variables constant. We first asked which regions' activity could be used to decode the presence of a sensory stimulus on one screen, amongst trials with the same behavioral outcome and the same contrast on the other screen ("Vision" correlates). These Vision signals appeared in contralateral visual and frontal cortices (Fig. 2f), starting in VISp at 50 ms (first detection of contralateral stimulus at p<0.01; nested ANOVA) and MOs at 100 ms. Further small decoding performance was possible in ipsilateral MOs at 125 ms, but no decoding from elsewhere. We next asked which regions' activity could decode Go vs NoGo choices, amongst trials with the same stimulus conditions ("Action" correlates). This showed a different pattern: Go vs. NoGo could be decoded from cortical activity from 125 ms prior to movement onset, starting in primary motor and frontal cortex, and expanding to most imaged regions by 25 ms before movement (Fig. 2g). Finally we asked which regions could decode upcoming Left vs Right choices amongst Go trials ("Choice" correlates); this was not possible from any recorded region (Fig. 2h).
To determine the timing of vision, action, and choice coding in the electrophysiologically recorded populations, we used the CCCP strategy outlined previously for widefield data (see also Supplementary Figure S3). Stimulus decoding began at ~60 ms in contralateral VISp, ~110 ms in contralateral MOs and ~180 ms in ipsilateral MOs (Fig. 2m). Go vs. NoGo decoding was first observed in each region 50-125 ms prior to movement onset (Fig. 2n), while Choice decoding was rare prior to movement ( Fig. 2o) but increased substantially afterwards, reaching a peak at 200-300 ms after movement onset (Fig. 2p).
Widefield imaging and Neuropixels recordings therefore suggested two primary cortical correlates of task variables: vision and action. First, neurons in visual cortex VIS and frontal cortex MOs correlated with the sensory visual stimuli. Second, neurons in all recorded regions correlated with upcoming action, with primary motor area MOp showing the strongest action correlates. In contrast, neurons encoding the direction of the animals' upcoming choice were rare, consistent with the resulting choice signals being absent in the widefield data. Optogenetic inactivation of sensorycoding regions biases choice To assess whether these cortical correlates of stimulus and action are necessary for task performance, we used optogenetic inactivation. We optogenetically inactivated each of 52 sites across the dorsal cortex by shining a blue laser (1.5 mW) in transgenic mice expressing Channelrhodopsin (ChR2) in Parvalbuminexpressing inhibitory interneurons 26 , using transcranial laser scanning 18 . Each randomly-selected site was inactivated on ~1.4% of trials. Laser illumination started at the onset of visual stimuli and lasted until a choice (or NoGo) was registered. If the cortical correlates of sensory stimuli in VISp and MOs are necessary for performance, then inactivating these regions should bias the subject's choices away from contralateral stimuli. If the non-specific bilateral correlates of action in other regions such as MOp are necessary for performance, then inactivating these regions should cause an increase in NoGo trials.
Inactivation of each cortical region affected Left/Right choices in direct proportion to the region's encoding of sensory stimuli (Fig. 3a-c). We first focused on trials with equal contrast on both sides, to which animals responded with Left and Right choices (rewarded with 50% probability) and NoGo responses (Miss trials, unrewarded). Optogenetic inactivation affected the animals' choices when targeted at the visual cortex (VIS; light diffusion made it impossible to distinguish effects in individual visual areas) and at frontal cortex (MOs; Fig. 3a), biasing choices away from stimuli contralateral to the inactivated hemisphere (+35%, p<0.0002 in VIS, +22%, p<0.0002 in MOs; permutation test; Supplementary Figure S4). The strength of the bias produced by inactivating a cortical location closely matched the accuracy with which that location's activity correlated with the presence of a contralateral stimulus (Fig. 3b,c).
In contrast, no matter how strongly a cortical region encoded upcoming action, inactivation caused no changes in NoGo responses (Fig 3d-f). Inactivation of primary motor and primary somatosensory areaswhose activity most strongly differed between Go and NoGo trials -had no effect on the proportion of Go vs. NoGo choices (Fig. 3d). Similar results were seen across the cortex, and we observed no relationship between the strength with which a region's activity measured by widefield imaging predicted action (Go vs NoGo choices), and the effect of inactivating that region on Go vs. NoGo behavior (Fig. 3e,f). Inactivation of primary motor cortex MOp did, however, reduce wheel peak velocity by a small amount for both Left and Right choices non-specifically (-21.2%, p<0.01, ttest; Supplementary Figure S5).
Consistent with their causal role in sensory encoding, visual and frontal cortex were most needed precisely at the time when they encoded sensory stimuli ( Fig.  3g-i). To determine the times at which activity in different regions played a causal role, we inactivated VIS and MOs with a brief laser pulse (25 ms, 15 mW) at different delays from stimulus onset (Fig. 3g). Inactivation of VIS significantly impaired task performance around the time of stimulus onset (-110 to +130 ms; Fig. 3h). Inactivation of MOs impaired performance at a later time window (+52 to +174 ms). These windows preceded the time of these mice's choices at 273 ± 21 ms (median ± m.a.d. across 65 sessions, on laser-off trials). Consistent with the scanning inactivation results, pulsed inactivation in MOp, produced no significant behavioral impairment at any time (Supplementary Figure S4g). It might seem paradoxical that inactivation in VIS prior to stimulus onset could affect behav-ior; however, pulse activation of inhibitory cells suppresses cortical activity for over 100 ms (Olsen et al., 2012; Supplementary Figure S4h). The critical time for inactivation is thus the last moment at which inactivation affects behavior. Notably, this critical time for VIS and MOs mirrored the time of peak contralateral stimulus decoding in these regions as previously identified in electrophysiological recordings (Fig. 3i). A lawful relationship between cortical activity and decisions predicts the effects of inactivation To formally relate neural activity to the mouse's behavior, we constructed a neurometric model, which predicts actions and choices based on neural activity. In contrast to the analyses above (Fig. 3), which focused on specific stimulus conditions (equal contrast), this model summarizes how cortical activity shapes the animals' decisions for all contrast combinations.
In the model, a hypothesized subcortical circuit performs weighted sums of population activity of visual and frontal cortex, to compute the evidence for a choice on each side (Fig. 4a). Because only the visual and frontal cortex had a causal role in choice (Fig. 3), we defined the decision variables as a weighted sum of activity in VISp and MOs, obtained from widefield imaging at the time this activity is causally relevant. The inputs to the model are thus the activities and of the left and right visual cortex (VISp) at time 75-125 ms after stimulus onset, and the activities and of the left and right frontal cortex (MOs) at time 125-175 ms. A weighted sum of these 4 variables yields the 'decision variables' representing the evidence for choices on the left and on the right: where and represent weights from contralateral visual and frontal cortex, and represent weights from ipsilateral visual and frontal cortex, and and are constant intercept terms. The two decision variables determine the animal's behavior probabilistically, using a 3-way logistic ("softmax") function, where the probabilities of Left, Right, and NoGo responses are: We fitted the parameters of this model using the data from widefield imaging, keeping the data from inactivations aside. To determine the activity variables, we calibrated widefield recordings against electrophysiologically-measured firing rates to provide an estimate of firing rate from the widefield fluorescence signal (see Methods; Supplementary Figure S6). To fit the weights we used a hierarchical Bayesian approach that allowed for variability in weights between subjects and recording sessions (Methods). The inactivation data was not used to constrain these weights, allowing us to use these data to later validate the model.
The estimated weights showed a fundamentally different structure for visual and frontal cortex (Fig. 4b). The weights on VISp activity were subtractive ( positive and negative): activity on one side of the visual cortex promoted contraversive choices while suppressing ipsiversive choices. By contrast, the weights on MOs activity were additive ( > , but both positive): activity on one side of the frontal cortex promoted both contraversive and ipsiversive choices (albeit slightly favoring the contraversive side). Thus, the decision variables represented a subtraction of visual cortical activity between the two hemispheres, and an addition of frontal activity from both hemispheres.
The model captured the behavior of the mice not only during imaging sessions (which were used to fit the model) but also during inactivation sessions, predicting the effects of inactivation even though inactivation data were not used in the fits (Fig. 4c,d). During inactivation sessions, the model was able to capture the overall dependence on stimulus contrast of each type of choice: Correct choices, Incorrect choices, and Misses (nonlaser trials; Fig. 4c; Supplementary Figure S7). To predict the results of optogenetic inactivation, we computed the model's prediction after setting the activity in a selected cortical region to zero. The model predicted a reduction in Correct choices and increase in Miss errors on inactivation of either VISp or MOs contralateral to a stimulus (Fig. 4d). Intriguingly however, the model's predictions for VISp and MOs inactivation were not identical: due to the subtractive nature of the VISp weights, the model predicted that VISp inactivation should increase Incorrect choices, but that MOs inactivation should not. To test these predictions, we performed an additional optogenetic inactivation experiment in VIS and MOs (1.5 s duration, multiple laser powers; see Methods). The empirical observations in the proportion of correct, incorrect and miss rates resembled the predictions from the neurometric model for VIS and MOs inactivation ( Fig. 4d; Supplementary  Figure S7). The neurometric model, therefore provides a quantitative link between the activity observed in visual and frontal regions, the choices of the animal, and the effects of inactivation of those regions.  1h. (d) Model predicts effects of inactivation on Correct, Incorrect and Miss trials, averaging over unilateral stimulus conditions. Open circles show the empirical probability for trials with laser off (brown), and for trials with optogenetic inactivation (1.5 s duration, multiple laser powers; see Methods) of VIS (blue) and MOs (green), averaged across sessions. Error bars indicate the 95% confidence interval of the average estimate. Brown horizontal lines indicate the neurometric model fit to the average contrast value (~30%). Blue and green horizontal lines indicate mean predictions from the neurometric model, obtained by setting the activity of VISp (blue) and MOs (green) in the model to zero. Shaded regions indicate the 95% credible intervals of the model predictions.

Discussion
Our results reveal a tight link between the behavior of a mouse in a visual choice task, and the sensory, but not the motor, activity of the dorsal cortex. Widefield imaging and large-scale electrophysiology revealed two correlates of cortical activity with task variables. First, the visual stimuli elicited activity in the visual cortex (VIS) followed by frontal cortex (MOs). Second, activity all over the dorsal cortexand particularly in primary motor cortex, MOpcorrelated with action before movements in either direction. Only a few neurons in frontal cortex showed correlates of choice between the two directions. Optogenetic inactivation showed that the localized cortical correlates of vision were causal, but the widespread correlates of action were not. Inactivation of VIS and MOs biased choices away from the contralateral stimulus, but inactivating MOp caused only a slight decrease in wheel velocity. The behavioral effects of inactivating a cortical region scaled linearly with the degree to which that region's activity correlated with sensory information, and not at all with the degree to which it correlated with motor information. Moreover, the behavioral effects of inactivation were in line with the predictions of a neurometric model trained to compute choice using cortical activity as the sensory signal. These results suggest that the main contribution of dorsal cortex in this task is that VIS and MOs transfer sensory information to downstream circuits that select the animal's choice. Other areas such as MOp may make an additional minor contribution to movement execution.
Our data confirm the critical role of rodent frontal cortex (MOs) in sensory decisions, but suggest that at least in this task, MOs' role is primarily to route information to other circuits, which feed back a decision to frontal cortex primarily only after the movement starts. MOs is thought to be critical for decisions based on sensory input 27 , from diverse modalities, such as somatosensation 18,28 , audition 17,29 , olfaction 10 , and vision 30 . Our data are consistent with this hypothesis, but suggest a primarily sensory role in this task. Widefield imaging revealed no difference in MOs activity between trials of identical stimulus conditions but different choices (Left or Right). Electrophysiology indicated that single neurons which could predict Left vs Right choices prior to movement onset were substantially rarer than neurons carrying a sensory signal, although choice direction could be decoded from more MOs neurons after the action had started. We therefore conclude that in this task, most MOs neurons serve to route sensory information to circuits that make the decision, receiving feedback on which decision has been made only once the movement is underway.
The rarity of pre-movement choice coding in dorsal cortex suggests that at least in this task, the animal's choice is largely determined by subcortical circuits. Our neurometric model accurately predicted the animal's average choices based on cortical activity, but it assumed that the choice on each trial was determined stochastically by a circuit downstream of cortex. Indeed, previous work in the same task identified neurons with strong choice signals in a variety of subcortical structures, including basal ganglia, superior colliculus and zona incerta 6 . These circuits feed back to cortex, so it is certainly possible that a small number of cortical neurons participate in a distributed recurrent circuit that determines the animal's choice. However, even in MOs, encoding of the animal's choice only became widespread after the action had already started. Thus, if MOs does play an important role in selecting the animal's choice, the neurons required for this would be substantially fewer in number than the neurons encoding the sensory stimulus. Moreover, while our data show that VIS plays an important role in routing sensory information to decision structures, they do not constrain whether this information flows directly from VIS to subcortical targets, or indirectly via MOs.
The strongest and most widespread cortical correlate of behavior was with the upcoming action (Go vs. NoGo), but this correlate most likely reflects a corollary discharge. For instance, primary motor cortex MOp showed the strongest correlation with upcoming action, but this correlation did not correspond to causation: inactivating MOp had no effect on the animals' choices, causing only a slight decrease in wheel velocity. Therefore, these strong action correlates are not involved in the decision to choose Go over NoGo. Instead, they might contribute to execution of the ongoing movement, or simply reflect efference copy or corollary discharge 22,31 from other circuits involved in producing the choice. These data are consistent with studies showing that neural circuits exhibiting choice correlates are not always necessary for it 17,32 . We do not know how this widespread increase in neural activity preceding an action might benefit the animal, however we speculate that increased firing rates may improve neural coding capacity by boosting spike counts and lowering time constants 33 .
The fact that the non-specific action correlates are so large and widespread highlights the difficulties of ascertaining neural correlates of choice in Go/NoGo tasks. Several studies have shown that in Go/NoGo tasks, neurons of many regions, including sensory cortex, change their activity prior to the movement 8,10,34,35,46 . Given the present results, and our recordings across the brain in this task 6 , it is not surprising that correlates of action are found in sensory cortex: they are found everywhere. However, as the inactivation of MOp in the present task makes clear, we should not generally expect brain activity that predicts an upcoming Go/NoGo choice to play a causal role in that choice.
In summary, we found that the dorsal cortex's involvement in a sensory discrimination task appears primarily to relay sensory evidence to a downstream circuit that stochastically determines the subject's behavior based on this evidence. Although all of cortex predicted whether the subject would make an action, this activity was not causal. Instead, the more a cortical region's activity correlated with sensory stimuli, the stronger the effect of inactivating it. Moreover, a neurometric model relating activity in each region to the animal's choice was able to predict the effects of cortical inactivation. This suggests that a stochastic circuit downstream of cortex might have also learned to optimally weigh cortical activity to produce the required behavior. The location of this downstream circuit is currently unconstrained, but may include subcortical structures with choice correlates (such as basal ganglia and midbrain) or the rare neurons in frontal cortex that encode choice. Testing the causal relevance of these circuits will require further targeted inactivation experiments.

Methods
All experimental procedures were conducted at UCL according to the UK Animals Scientific Procedures Act (1986) and under personal and project licenses granted by the Home Office following appropriate ethics review.  Table 1.

Surgery
For widefield imaging, optogenetic inactivation and electrophysiological recording experiments, mice were prepared with a clear skull cap similar to that of Guo et al. (2014) and described previously 6,25 . The implantation surgery proceeded as follows. The dorsal surface of the skull was cleared of skin and periosteum, and the junction between cut skin and skull was sealed with cyanoacrylate. The exposed skull was prepared with a brief application of green activator to ensure strong connection between cement and bone (Super-Bond C&B, Sun Medical Co, Ltd, Japan). The junction between skin and skull was again covered, using dental cement (Super-Bond C&B). In most cases, a 3D printed 'cone' was attached to the head with cy-anoacrylate and dental cement at this stage, surrounding the exposed skull and providing light isolation. A thin layer of cyanoacrylate was applied to the skull and allowed to dry. Two to four thin layers of UV-curing optical glue (Norland Optical Adhesives #81, Norland Products Inc., Cranbury, NJ; from ThorLabs) were applied to the skull and cured (~10 s per layer) until the exposed skull was covered (thin layers were used to prevent excessive heat production). A head-plate was attached to the skull over the interparietal bone with SuperBond polymer.

Behavioral task
Apparatus: The two-alternative unforced choice task design was described previously 25 . In this task, mice were seated on a plastic apparatus with forepaws on a rotating wheel, and were surrounded by three computer screens (Adafruit, LP097QX1) at right angles covering 270 x 70 degrees of visual angle (d.v.a.). Each screen was ~11 cm from the mouse's eyes at its nearest point and refreshed at 60 Hz. The screens were fitted with Fresnel lenses (Wuxi Bohai Optics, BHPA220-2-5) to ameliorate reductions in luminance and contrast at larger viewing angles near their edges, and these lenses were coated with scattering window film ("frostbite", The Window Film Company) to reduce reflections. The wheel was a ridged rubber Lego wheel affixed to a rotary encoder (Kubler 05.2400.1122.0360). A plastic tube for delivery of water rewards was placed near the subject's mouth. For full details of the experimental apparatus including detailed parts list see www.ucl.ac.uk/cortexlab/tools/wheel. All behavioral experiments were run using MATLAB Rigbox 36 .

Pre-stimulus quiescence:
For three experiments, trials began after a period of no wheel movement (widefield imaging: 0.3-0.7 s, 52-coordinate inactivation experiment: 0.2-0.6 s, Neuropixels electrophysiology 0.2-0.5 s). For all other behavioral sessions, there was no constraint however trials were excluded post-hoc if wheel movement was detected -0.15 to +0.05 s from stimulus onset.
Stimulus onset: At trial initiation, a visual stimulus was presented on the left, right, both, or neither screen. The stimulus was a Gabor patch with orientation 45 degrees, sigma 9 d.v.a., and spatial frequency 0.1 cycles/degree. The grating stimuli on the left and right screens displayed at all combinations of four contrast levels, totaling 16 contrast conditions. The proportion of trials of each stimulus type were weighted towards easy trials (high contrast vs zero, high vs low, medium vs zero, and no-stimulus trials) to encourage high overall reward rates and sustained motivation. Zero contrast trials made up ~31% of trials; High contrast and Medium contrast single-side contrast trials made up ~24%; equal contrast trials made up ~12% of trials; all other comparison contrast trials uniformly comprised the remaining trial types. For all experiments except for widefield imaging and Neuropixels electrophysiology (see 'open-loop period' below), the onset of the visual stimulus also coincides with the onset of an auditory 'go cue' (12 kHz tone, 100ms duration), marking the time at which the mouse can respond.
Wheel movements: Wheel turns in which the top surface of the wheel was moved to the subject's right led to rightward movements of stimuli on the screen, i.e. a stimulus on the subject's left moved towards the central screen. Put another way, clockwise turns of the wheel, from the perspective of the mouse, led to clockwise movement of the stimuli around the subject. A left or right choice was registered when the wheel was turned by an amount sufficient to move the visual stimuli by 90 d.v.a. in either direction. When at least one stimulus was presented, the subject was rewarded for driving the higher contrast visual stimulus to the central screen (if both stimuli had equal contrast, Left/Right choices were rewarded with 50% probability). When no stimuli were presented, the subject was rewarded if no turn (NoGo) was registered during the 1.5 s following the go cue.

Open-loop period:
For widefield calcium imaging & Neuropixels electrophysiology sessions, after stimulus onset there was a random delay of 0.5-1.2 sec, during which time the subject could turn the wheel without penalty, but visual stimuli were locked in place and rewards could not be earned. The subjects nevertheless typically responded immediately to the stimulus onset, and trials were excluded if choices were made after 0.5 s. At the end of the delay interval, an auditory go cue was delivered (8 kHz pure tone for 0.2 sec) after which the visual stimulus position became coupled to movements of the wheel. This small task modification was important to ensure that visual-stimulus-related cortical activity was not inter-mixed with activity related to the auditory go cue, and that movement-related activity was not inter-mixed with signals related to visual motion of the stimulus on the screen.
Feedback: Immediately following registration of a choice or expiry of the 1.5 s window, feedback was delivered. If correct, feedback was a water reward (0.7 -2.5 µL) delivered by the opening of a valve on the water tube for a calibrated duration. If incorrect, feedback was a white noise sound played for 1 s. During the 1 s feedback period, the visual stimulus remained on the screen. After a subsequent inter-trial interval of 1 s (or 2 s for the 52-coordinate inactivation experiment), the mouse could initiate another trial by again holding the wheel still for the prescribed duration.
Training: Mice were trained on this task with the following shaping protocol. First, high contrast stimuli (50 or 100%) were presented only on the left or the right, with an unlimited choice window, and repeating trial conditions following incorrect choices ('repeat on incorrect'). Once mice achieved high accuracy and initiated movements rapidly -approximately 70 or 80% performance on non-repeat trials, and with reaction times nearly all < 1 second -trials with no stimuli were introduced, again repeating on incorrect. Once subjects responded accurately on these trials (70 or 80% performance, at experimenter's discretion), lower contrast trials were introduced without repeat on incorrect. Finally, contrast comparison trials were introduced, starting with high vs low contrast, then high vs medium and medium vs low, then trials with equal contrast on both sides. The final proportion of trials presented was weighted towards easy trials (high contrast vs zero, high vs low, medium vs zero, and no-stimulus trials) to encourage high overall reward rates and sustained motivation.
Trial-exclusion: Trials were excluded from analyses based on several criteria. For all experiments, error trials were excluded if they represented the second (or more) consecutive error on easy trials (see 'repeat on incorrect' in previous section), as these errors likely reflect mouse disengagement. In addition, the first 5-10 trials of every session were excluded as these trials may include periods when the mouse is not settled into the task. For electrophysiological recording experiments, trials were excluded if they did not exhibit clear Left or Right wheel movements for Left and Right trials within 0.1 to 0.4 s from stimulus onset, or if they exhibited twitch movements for NoGo trials within -0.05 to 0.5 s from stimulus onset.

Widefield calcium imaging
Mice and apparatus: Imaging was performed in transgenic mice expressing GCaMP6 in excitatory neurons (tetO-G6s x CaMK2a-tTA; VGlut1-cre x Ai95) or all neurons (Snap25-GCaMP6s). For all widefield analyses, data was averaged across these mouse genotypes since all groups showed qualitatively similar responses. Aberrant epileptiform activity has not been observed in these mouse lines 37 . Details of the imaging have been described before 38 and are summarized here. We imaged using a macroscope (Scimedia THT-FLSP) with sCMOS camera (PCO Edge 5.5) and dualwavelength illumination (Cairn OptoLED). The macroscope used a 1.0x condenser lens (Leica 10450028) and 0.63x objective lens (Leica 10450027). Images were acquired from the PCO Edge with ~10 ms exposures and 2 x 2 binning in rolling shutter mode. Images were acquired at 70 Hz, alternating between blue and violet illumination (35 Hz each). The light sources were 470 nm and 405 nm LEDs (Cairn OptoLED, P1110/002/000; P1105/405/LED, P1105/470/LED). Excitation light passed through excitation filters (blue: Semrock FF01-466/40-25; violet: Cairn DC/ET405/20x), and through a dichroic (425 nm; Chroma T425lpxr). Excitation light then went through 3 mm core optical fiber (Cairn P135/015/003) and reflected off another dichroic (495 nm; Semrock FF495-Di03-50x70) to the brain. Emitted light passed through the second dichroic and an emission filter (Edmunds 525/50-55 (86-963)) to the camera. Alternation was controlled with custom code on an Arduino Uno, and illumination was restricted to the 'global' phase of the rolling shutter exposures, i.e. only the times when all pixels of a frame were being exposed together.

Preprocessing:
We de-noised the signal with singular value decomposition 39 and normalized the signal to the mean fluorescence at each pixel. The signal from the 405 nm illumination frames was used to correct for parts of the 470 nm signal that were due to changes in blood flow that obstruct the fluorescence signal 40 and the correction was performed with custom Matlab code (github.com/cortex-lab/widefield). We then low-pass filtered the signal at 8.5 Hz and applied a derivative filter to the fluorescence trace to approximate deconvolution of the calcium sensor's time course from the underlying neural activity. Fluorescence was extracted on a grid centered at bregma for each mouse and session, making it possible to average activity across sessions/mice. When computing stimulus-aligned averages of the fluorescence, pre-stimulus baseline activity was removed, removing the impact of long-term trends.

ROI selection:
Regions of interest (ROIs) corresponding to cortical areas were selected based on the Allen CCF atlas aligned manually to each mouse, guided by skull features and retinotopic maps. ROI positions were manually adjusted to account for inter-mouse differences. VISp was selected as the peak of the most posterior-medial activated site in the visual cortex in response to a contralateral stimulus. VISal was selected as the center of VISal according to the Allen CCF. VISal was taken as an exemplary secondary visual cortical area because it was furthest from the part of VISp activated by our visual stimuli, ensuring minimal contamination of fluorescence between these two ROIs. The MOs ROI was selected as the most anterior site activated by the contralateral stimulus. MOp and SSp ROIs were selected as the most anterior-medial and posterior-lateral regions of the region that spanned the MOp-SSp border and was active during wheel movements.
Decoding analysis: To decode task variables from neural activity at different cortical regions and timebins, we used a strategy that we have called 'combined conditions choice probability' (CCCP) 6 , which measures how neural activity can predict one behavioral or sensory variable, while holding the others constant. We describe this method by explaining how it is used to predict Action (Go vs NoGo) for constant stimulus conditions. For each of the 16 possible stimulus conditions (contrast pairs), we compute a Mann-Whitney U statistic: the number of Go-NoGo trial pairs of this stimulus condition for which the Go trial had more activity than the NoGo trial. We then sum the 16 U statistics, sum the total number of trial pairs for each condition, and divide to obtain an auROC (area under receiver operating characteristic) value between 0 and 1. This auROC therefore quantifies how well a decoder could distinguish between Go and NoGo trials from neural activity, analogous to Choice Probability analysis 41 but controlling for different stimulus conditions. For Vision decoding a similar strategy is used: to decode left contrast, we first divide trials into 12 groups corresponding to 3 possibilities for the animal's choice (Left, Right, NoGo) and 4 right stimulus contrasts. Within each group we calculate a U statistic: the number of trials, for which one trial had non-zero contrast on the left and the other had zero contrast, and the non-zero contrast trial had more activity. We sum these U-statistics across groups and divide by the total trial count to obtain an auROC value. For stimulus decoding on the right side, the same analysis is performed but swapping left for right contrast conditions. Contralateral and ipsilateral stimulus decoding is computed by combining the auROC values between hemispheres and hemifields. For choice decoding, NoGo trials are excluded, and a U statistic is computed between fluorescence for Left and Right choices, within each of the 16 stimulus conditions. The auROC value here gives an estimate for how well a decoder can discriminate Left from Right choices from neural activity, controlling for the stimulus contrast.
For the widefield dataset, decoding significance was measured for each coordinate and time bin using a nested ANOVA across sessions and subjects, testing whether decoding performance was significantly different from 0.5. To compute Action decoding at movement-aligned time bins, NoGo trials were assigned a 'movement time' based on randomly sampling from the distribution of reaction times for correct Go trials.

Optogenetic inactivation
While mice performed the task, we optogenetically inactivated several cortical areas through the skull using a blue laser. For these experiments we utilized transgenic mice expressing ChR2 in Parvalbumin-expressing inhibitory interneurons (Ai32 x PV-Cre).

52-coordinate inactivation experiment:
Unilateral inactivation was achieved by mounting a fiber-optic cable on a moving manipulator (Scientifica, Patch-Star). On every trial, custom code drove the manipulator to set the position of the fiber-optic cable to one of 52 different coordinates distributed across the cortex. Inactivation coordinates were defined stereotaxically from bregma. On ~75% of trials, the laser was switched on (473 nm, 1.5 mW, 40 Hz sine wave) to inactivate the cortical site. Laser and non-laser trials, and the location of the cortical inactivation, was randomized. The duration of the laser was from visual stimulus onset, until a behavioral choice was made. For any given session, a single cortical site on the inactivation grid may only be inactivated a handful of times (~1.4% of trials). This discouraged any adaptation effects that may occur on more frequent inactivation paradigms, however this approach does require combining data across sessions. The laser positioning was independent of laser power, so auditory noise from the manipulator did not predict inactivation.
Pulsed inactivation experiment: Unilateral pulsed inactivation was achieved using a pair of mirrors mounted on galvo motors to orient the laser (462 nm) to different points on the skull. We also introduced improved light isolation to ensure no light could reflect from the skull surface and be seen by the mouse. For ~66% of randomly-interleaved trials, the laser was switched on for 25 ms (DC) at random times relative to stimulus onset (-300 to +300 ms drawn from a uniform distribution). Inactivation was targeted at visual areas (-4 mm AP, ±2 mm ML), secondary motor area (+2 mm AP, ±0.5 mm ML), and primary motor area (-0.5 mm AP, ±0.5 mm ML).

Mixed-power inactivation experiment:
Unilateral inactivation was achieved using the same laser/galvo hardware as in the pulsed inactivation experiment. The mirrors oriented the laser at visual and secondary motor areas. For ~70% of randomly-interleaved trials, the laser was switched on from stimulus onset for 1.5 s fixed duration. Laser power was chosen randomly between 1.5, 2.9 and 4.2mW. For subsequent analyses, trials using different laser powers were pooled together.

Electrophysiological recordings
The Neuropixels electrophysiological dataset was described previously 6 . Methods relating to electrophysiological recordings have been detailed in this work, and are reproduced here.
Hardware: Recordings were made using Neuropixels electrode arrays 42 . Probes were mounted to a custom 3D-printed PLA piece and affixed to a steel rod held by a micromanipulator (uMP-4, Sensapex Inc.). To allow later track localization, prior to insertion probes were coated with a solution of DiI (ThermoFisher Vybrant V22888 or V22885) by holding 2 µL in a droplet on the end of a micropipette and touching the droplet to the probe shank, letting it dry, and repeating until the droplet was gone, after which the probe appeared pink.
Procedure: On the day of recording or within two days before, mice were briefly anaesthetized with isoflurane while one or more craniotomies were made, either with a dental drill or a biopsy punch. The craniotomies for VISp were targeted in some cases using measured retinotopic maps in the same mice, and in other cases to the same position stereotaxically (-4 mm AP, 1.7 mm ML, left hemisphere). The craniotomies for MOs were targeted stereotaxically (+2 mm AP, 0.5 mm ML, left hemisphere). After at least three hours of recovery, mice were head-fixed in the setup. Probes had a soldered connection to short external reference to ground; the ground connection at the headstage was subsequently connected to an Ag/AgCl wire positioned on the skull. The craniotomies as well as the wire were covered with saline-based agar. The agar was covered with silicone oil to prevent drying. In some experiments a saline bath was used rather than agar. Probes were advanced through the agar and through the dura, then lowered to their final position at ~10 µm/s. Electrodes were allowed to settle for ~15 min before starting recording. Recordings were made in external reference mode with LFP gain = 250 and AP gain = 500. Recordings were repeated on multiple subsequent days. All recordings were made in the left hemisphere.
Preprocessing: The data were automatically spike sorted with Kilosort 43 (github.com/cortex-lab/Kilosort) and then manually curated with the 'phy' gui (github.com/kwikteam/phy). Extracellular voltage traces were preprocessed using common-average referencing: subtracting each channel's median to remove baseline offsets, then subtracting the median across all channels at each time point to remove artifacts. During manual curation, each set of events ('unit') detected by a particular template was inspected and if the spikes assigned to the unit resembled noise (zero or near-zero amplitude; non-physiological waveform shape or pattern of activity across channels), the unit was discarded. Units containing low-amplitude spikes, spikes with inconsistent waveform shapes, and/or refractory period contamination were labeled as 'multi-unit activity' and not included for further analysis. Finally, each unit was compared to similar, spatially neighboring units to determine whether they should be merged, based on spike waveform similarity, drift patterns, or cross-correlogram features. For calculating event-triggered averages and decoding performance, spike counts were binned with a 1 ms window and then smoothed with a 25 ms causal Gaussian filter.
Decoding analysis: Action, Vision and Choice were decoded from electrophysiological recordings using the same CCCP analysis outlined above for widefield decoding, with one exception: since single-neuron data could not be averaged across sessions, statistical significance could not be assessed by comparing decoding performance across sessions. Instead, decoding performance as measured by auROC was compared to a shuffled null distribution of auROC values obtained by shuffling the trial labels 2000 times (e.g. shuffling Go vs NoGo trial labels for Action decoding).

Kernel analysis:
The cross-validated variance of each neuron's firing rate explained by Vision, Action, or Choice was determined using a reduced-rank kernel regression method detailed previously 6 . In brief, a predictor matrix was formed using the times and identities of stimuli and actions. Reduced-rank regression between the predictor matrices and the binned spike counts was performed across all recordings simultaneously. The variance explained by the regression was assessed with cross-validation. Vision/Action/Choice kernels were deemed significant if their cross-validated variance explained exceeded 2%. The false positive rate for this threshold was found with a shuffle test to be 0.33%.

Psychometric model
We modeled probabilistic choice behavior using a multinomial logistic regression described previously 25 , but with the addition of a hierarchical Bayesian framework to account for inter-subject and inter-session variability in the model parameters.
For each trial , the probability ratio of Left vs NoGo and Right vs NoGo choices are set by the exponential function of two decision variables ( ) and ( ) : Choices ( ) ∈ ( , ℎ , ) are drawn from a categorical probability distribution with these parameters: To capture the behavioral dependence on choice bias and stimulus sensitivity, the decision variables are modelled as a saturating non-linear transformation of stimulus contrast. We denote the session number in which trial occurred as [ ], and the subject (mouse) number that performed the session as [ ]. The decision variables depended on parameters which varied between sessions (and thus also between subjects) according to the following formulae: To capture how these parameters vary across sessions and subjects, we expanded the model to incorporate a hierarchical prior on sessions and subjects. Let be a 5-element vector containing the 5 sessionspecific parameters stated above, = [ ( ) , ( ) , ( ) , ( ) , ( ) ]. We model each session's parameter vector as drawn from a multivariate Gaussian distribution whose mean [ ] depends on the subject, with a common covariance matrix , The covariance matrix is given the following prior. It is first converted to a correlation matrix, which is given a (2) prior 44 to penalize large positive or negative parameter correlations across sessions. The standard deviation terms for each parameter are given a ℎ (0,1) prior to penalize large variability in each parameter across sessions.
The full joint posterior distribution of all parameters was numerically estimated with Hamiltonian Monte Carlo (No-U-Turn) sampling, using the Stan language 45 . Sampling was performed in 4 chains, each with 500 warm up iterations and 500 sampling iterations. The samples were checked manually to ensure convergence within and between chains. The posterior prediction/fit from the model is constructed by computing the model prediction from each of the posterior distribution samples, and then computing the mean and 95% credible intervals on the prediction across samples. All model predictions shown in the figures use the grand-average parameter posterior * , unless specified otherwise.

Neurometric model
The neurometric model predicts the animal's choice from the activity of left VISp, right VISp, left MOs and right MOs regions. Like the psychometric model, it has two decision variables, which are determined on each trial from a weighted sum of activity in the four cortical areas: The estimated population rate ( ) is derived from widefield calcium imaging at the four ROIs (see Widefield Methods for detail). Since the baseline activity in widefield calcium fluorescence is poorly defined, the calcium fluorescence was transformed to approximate population firing rates. To achieve this, we recorded extracellular spiking activity in VISp and MOs using Neuropixels probes in separate sessions, and computed trial-averaged firing rates for each of the contrast conditions over a time window (Supplementary Figure  S6; VIS: 75-125 ms, MOs: 125-175 ms). Calcium fluorescence was also averaged over the same windows but 30 ms later to allow for slower GCaMP6 kinetics. The transformation from widefield fluorescence to firing rate was computed by simple linear regression over the 16 contrast conditions. This linear transformation was then applied to the fluorescence value for each individual trial, thereby providing a population firing rate estimate for the four cortical regions on every trial. To improve fit stability, parameter symmetry was enforced between the left and right hemispheres (e.g. the weight of left VISp onto was the same as right VISp onto ).
To generate predictions from the neurometric model for the effects of optogenetic inactivation, the model was modified in two ways. Firstly, since neural activity in VIS and MOs was not measured during optogenetic inactivation sessions, the trial-by-trial activity in ( ) was replaced with the trial-averaged firing rate measured electrophysiologically for each contrast condition. Secondly, since the overall tendency to NoGo differed idiosyncratically between widefield imaging and optogenetic inactivation sessions, the model offset parameters ( and ) were re-fit to the non-laser trials contained within optogenetic inactivation sessions (Mixedpower inactivation experiment).
To simulate the effect of optogenetic inactivation of a single cortical area, one element of the firing rate vector was set to zero. This effect propagates forward through the model based on the fixed weights estimated from the widefield sessions, thereby affecting the decision variables and the probability associated with each choice. Importantly, the behavioral prediction obtained from the model when simulating inactivation did not depend on any empirical data involving actual optogenetic inactivation. In this sense, the neurometric model predicts behavior in a new dataset on which it was not fit.

Statistical tests
For the 52-coordinate inactivation experiment (Fig.  3a), statistical significance of the inactivation effect was assessed using a permutation test. The test statistic used was the difference in the proportion of a specific choice type, between laser and non-laser off trials (on trials with equal left and right contrast) for each of the inactivated coordinates, averaged across sessions. The null distribution of the test statistic was computed by repeated shuffling of laser and non-laser trial identities within each session. All other statistical tests are specified in the main text.

Code & Data availability
The code used in the current study is available from the corresponding authors on reasonable request. The datasets generated and/or analyzed during the current study are available from the corresponding authors on reasonable request.