The sensorimotor strategies and neuronal representations of tactile shape discrimination in mice

Humans and other animals can identify objects by active touch, requiring the coordination of exploratory motion and tactile sensation. The brain integrates movements with the resulting tactile signals to form a holistic representation of object identity. We developed a shape discrimination task that challenged head-fixed mice to discriminate concave from convex shapes. Behavioral decoding revealed that mice did this by comparing contacts across whiskers. In contrast, mice performing a shape detection task simply summed up contacts over whiskers. We recorded populations of neurons in the barrel cortex, which processes whisker input, to identify how it encoded the corresponding sensorimotor variables. Neurons across the cortical layers encoded touch, whisker motion, and task-related signals. Sensory representations were task-specific: during shape discrimination, neurons responded most robustly to behaviorally relevant whiskers, overriding somatotopy. We suggest a similar dynamic modulation may underlie object recognition in other brain areas and species.

Animals have evolved sophisticated abilities to recognize objects, such as landmarks around food 39 sources. Peripheral sensory neurons detect low-level object features and the central nervous system 40 integrates them into a holistic representation of shape, endowed with behavioral meaning. This integration 41 can be over time, space, or even multiple senses. Moreover, animals choose how to move their sensory 42 organs to most effectively gather information about the world (Gibson, 1962;Yang et al., 2016c). A key 43 challenge in neuroscience is to understand the strategies animals use to explore the world and how they 44 integrate those motor actions with the resulting sensory input. 45 46 We investigated this problem in the mouse whisker system. Rodents rely on their whiskers 47 (macrovibrissae) for social interaction and guiding locomotion (Grant et al., 2018;Gustafson and Felbain-48 Keramidas, 1977; Stüttgen and Schwarz, 2018). The whiskers, like human fingertips, are moved together 49 onto objects in order to identify them (Ahissar and Assa, 2016;Diamond, 2010). Head-fixation permits 50 precise quantification of whisker motion and contacts in high-speed video, as well as a wealth of modern 51 techniques for monitoring and manipulating neural activity (Adesnik and Naka, 2018). Moreover, the 52 individual columns of barrel cortex that process input from each whisker are readily identifiable in vivo. 53 Thus, the whisker system is well-suited to the study of active touch, given an appropriate behavioral task. 4 importantly, during detection the neural population encoded contact by each whisker equally whereas 86 during discrimination responses to behaviorally relevant whiskers were enhanced. Our multi-pronged 87 approach of behavioral classification and neural encoding and decoding models reveals how the barrel 88 cortex integrates fine-scale sensorimotor events into high-level representations of form. 89

90
The shape discrimination and shape detection tasks 91 We developed a novel behavioral paradigm for head-fixed mice that challenged them to discriminate 92 shapes (Supplemental Video 1). On each trial, a linear actuator moved a curved shape (either convex or 93 concave) into the range of the whiskers on the right side of the face, though mice had to actively whisk to 94 contact it. The shape stopped at one of three different distances from the mouse (termed close, medium, 95 or far; Fig 1A, Mice learned to lick left for concave and right for convex shapes in order to receive a water reward. Two 100 seconds after the shape started moving, and soon after it reached its final position, the "response window" 101 began ( Fig 1C). The first lick in the response window (the "choice lick") determined whether the trial was 102 correct or incorrect. Early licks had no effect, but mice increased their rate of correct licks and licks 103 concordant with the eventual choice lick as the response window approached (Fig 1D), indicating the 104 formation of their decision. Mice could learn the trial timing from the sound of the actuator, but whiskers 105 were required to identify the shape (Supplemental Fig 1B). 106

107
To unambiguously identify each whisker in videography, we gradually trimmed off whiskers on the right 108 side of the face throughout training. The middle (C) row was spared: C1 is the caudal-most and longest 109 whisker; C3 is the rostral-most and shortest whisker still capable of reaching the shapes. Mice were 110 strongly impaired by each trim, falling to chance or near-chance levels, suggesting that they initially relied 111 on many whiskers (data not shown). However, with retraining, many were able to discriminate shape with 112 only these 3 whiskers. Some mice retained a straddler whisker ("C0"), but it rarely made contact and was 113 excluded from analysis. 114 115 We trained a separate group of mice on a "shape detection" task ( Fig 1E) to determine whether the 116 behavioral and neural responses were specific to shape discrimination or were simply due to the shapes 117 themselves. In this control task, mice learned to lick right in response to either shape and to lick left on 118 trials when the actuator presented an empty position with no shape. The shapes, trial timing, and trimming 119 were identical to those for discrimination. 120 121 Both groups of mice learned to perform well above chance (Fig 1F; n = 5 detection mice and 10 122 discrimination mice). Detection mice more accurately reported the presence of a shape when it was closer 123 (Fig 1G). Discrimination mice identified concave shapes equally well at all locations, but were more likely 124 to identify convex shapes correctly when closer. Thus, shape discrimination relied on "detecting 125 convexity", an observation we return to below. The whisk cycle synchronizes contacts across multiple whiskers into packets 128 To identify how mice identified the shapes, we acquired video of their whiskers at 200 frames per second. 129 This large dataset-15 mice, 88.9 hours, 115 sessions, 18,514 trials, 63,979,800 frames-necessitated 130 high-throughput automated tracking. To do this, we used the human-curated output of a previous-131 5 generation whisker tracking algorithm (Clack et al., 2012) to bootstrap the training of a deep convolutional 132 neural network (Insafutdinov et al., 2016;Mathis et al., 2018;Pishchulin et al., 2015). This method 133 successfully tracked the full extent of the whiskers even as they moved rapidly, became obscured, or 134 contacted the shape (example frames: Supplemental Fig 2A). 135 136 Trained mice whisked in stereotyped patterns that could differ widely across individuals (Fig 2A). We 137 decomposed whisker motion into individual cycles (Fig 2B, n = 882,893 whisks from 15 mice, excluding   138 inter-trial intervals). Individual whisks had a mean duration of 64.1 ± 4.0 ms, equivalent to a whisking 139 frequency of 15.6 Hz, with an amplitude (peak-to-trough angular difference) of 10.6 ± 1.9° (mean ± 140 standard deviation of the within-mouse average; Supplemental Fig 2B). Mice made contacts near the peak 141 of the whisk cycle (Fig 2C), synchronously across whiskers (Fig 2D; cf. Sachdev et al., 2001). Compared with the detection group, mice performing shape discrimination made more single-and multi-144 whisker contacts (Fig 2E). Both groups made C3 contacts less frequently because it was too short to 145 touch the shapes at the further positions. However, the shape discrimination group made much longer 146 duration contacts with the C3 whisker than the shape detection group (Fig 2F), suggesting an important 147 role for this whisker in discrimination. During both tasks, performance increased with the number of 148 contacts made on each trial ( Fig 2G). In combination with the stereotyped whisking pattern, this suggests 149 mice relied on a pre-planned motor strategy rather than an closed-loop strategy (Yang et al., 2016c;Zuo 150 and Diamond, 2019a). In sum, the whisk cycle synchronizes contacts across multiple whiskers into 151 discrete packets of sensory evidence, which mice use to identify shape.

153
Mice rely on brief "tapping" of the stimuli 154 The way mice contacted these shapes fundamentally differed from previous reports of mice and rats 155 exploring different objects. We exclusively observed tip contact whereas mice localizing poles make 156 contact with the whisker shaft (Hires et al., 2013, cf. a similar observation in rats discriminating texture in 157 Carvell and Simons, 1990). We never observed mice dragging their whiskers across the objects' surfaces, 158 as they do with textured stimuli (Carvell and Simons, 1990;Jadhav et al., 2009;Ritt et al., 2008). Strikingly, the contact forces we observed were much smaller than in previous reports of other tasks. The 167 typical maximum bend (Δκ) was 5.1 +/-1.0 m -1 for C1, 11.2 +/-1.2 m -1 for C2, and 19.1 +/-3.3 m -1 for C3 168 (mean +/-SEM over mice; Fig 2I), much less bent than the 50-150 m -1 typical of pole localization or 169 detection (Hires et al., 2015;Hong et al., 2018;Huber et al., 2012). This sensorimotor strategy of "minimal 170 impingement" onto the shape is the mode used by freely moving rodents investigating objects and may 171 thus be more naturalistic (Grant et al., 2009;Mitchinson et al., 2007). Behavioral decoding reveals the sensorimotor features that guide behavior 174 To uncover the strategies mice used to perform this novel task, we turned to behavioral decoding. First, 175 we quantified a large suite of sensorimotor features from the video (e.g., contact location, cross-whisker 176 contact timing) as well as task-related variables (choice and reward history). Then we trained linear 177 classifiers using logistic regression to predict either the stimulus identity (concave vs convex for 178 6 discrimination; something vs nothing for detection) or the mouse's choice (lick left or lick right) on each trial 179 using those features (Fig 3A).  Predicting the stimulus indicated which features carried information about shape whereas predicting   182   choice indicated which features might have influenced the mouse's decision. However, an important   183   challenge was to disentangle the extent to which each feature predicted stimulus or choice (Nogueira et   184 al., 2017). These two variables are correlated; indeed, they are perfectly correlated on correct trials. To 185 directly address this, we weighted error trials in inverse proportion to their abundance, such that correct 186 and incorrect trials were balanced (i.e., equally weighted in aggregate). This notably improved our ability to 187 predict the mouse's errors (Supplemental Fig 3A). To identify the most important features, we compared the accuracy of separate decoders trained on every 190 individual feature during shape discrimination (Fig 3B, left). The most informative feature for decoding both 191 stimulus and choice was a two-dimensional binary array representing which whisker made contact at each 192 timepoint within the trial, which we term "whisks with contact" (schematized in Fig 3A). The next most 193 informative feature was "whisks without contact": when the mouse whisked far enough forward to rule out 194 the presence of some shapes but did not actually make contact. Together, these two variables constitute 195 all "sampling whisks" that were sufficiently large to reach the closest possible shape position; the 196 remaining "non-sampling whisks" could not be informative because they were too small to reach the 197 shapes at any position. The "contact angle" feature was also useful for predicting the stimulus, likely due 198 to the geometrical information it contains. It was less useful for predicting choice, suggesting that mice did 199 not exploit the information despite its utility. 88.2 ± 1.8%; choice: 77.4 ± 1.3%). It outperformed the mice on shape discrimination (Fig 3E), indicating 217 that the mice were unable to access or use some of the information in the contact pattern. Shape detection and discrimination engage distinct motor strategies 225 The results from classifying stimulus and choice in the shape detection task differed strikingly from shape 226 discrimination: the total contact count summed over whiskers explained stimulus and choice better than 227 any other variable (Fig 3B, right). Total contact count was far less informative during discrimination. This 228 reflects the fundamental difference between these tasks: detection requires the mouse only to know that 229 contacts occurred whereas discrimination requires additional information-most critically, the identities of 230 the contacting whiskers. To test whether mice adapted their whisking strategies to the task, we asked whether shapes could be 233 classified from the data of mice performing the shape detection task, even though these mice did not 234 actually need to identify the shapes. We used the optimized behavioral decoder for discrimination ( Fig 3C,   235 dashed box) to predict shape identity from detection sessions. Its ability to decode shape identity during 236 the detection task was poor compared with during the discrimination task (Fig 3F), despite the fact that the 237 shapes in both cases were identical. Thus, mice adapt their whisking to the task at hand, collecting more 238 information about shape identity when behaviorally relevant. Thus, mice compare contacts across whiskers to discriminate an object's curvature whereas they sum up 249 contacts across whiskers to detect an object. Critically, this is not because any given whisker can only 250 reach one of the shapes; all whiskers can touch both shapes ( Fig 3H). Instead, the whisking strategy 251 employed for discrimination biases contact prevalence across whiskers, which the decoder exploits to 252 predict the mouse's choice. To visualize this process of spatial sampling, we registered all of our whisker video into a common 255 reference frame ( Fig 3I). As expected, the whiskers reliably sampled different regions of shape space (  In summary, behavioral decoding produced a computational model of the distinct sensorimotor strategies 262 that mice adopted in two different tasks. Inspection of the weights revealed that mice summed up contacts 263 across whiskers to detect shapes whereas they compared contacts across whiskers to discriminate shape 264 identity. This analysis could be used to dissect active sensation in other modalities as well. Neurons exhibited rapid transient responses to whisks with contact but not to whisks without contact (Fig   276   4E). These contact responses were stronger in the superficial layers and in inhibitory neurons, likely 277 reflecting greater thalamocortical input to this cell type (Bruno and Simons, 2002;Cruikshank et al., 2007). 278 Firing rates on timescales longer than the whisk cycle nevertheless tracked whisking amplitude, especially 279 in deep inhibitory neurons (Fig 4F). We treated the whisk as the fundamental unit of analysis rather than using arbitrary time bins because this 312 granularity was useful for identifying behavioral strategies (Fig 3) and because contacts ( Fig 2C) and 313 spikes ( Fig 4E) are highly packetized by the whisk cycle. Therefore we predicted total spike count on each 314 whisk cycle for each neuron. We again used model selection to quantify the importance of each feature for predicting neural responses. 317 Different GLMs were trained on individual families of features-contact ("whisks with contact" as above), 318 whisking (amplitude and set point), and task-related (choice and outcome of current and previous trial)- 319 and their goodness-of-fit (i.e., accuracy with which they predicted neural responses on held-out data) 320 9 compared. Each family of features alone had explanatory power, and a combined "task + whisking + 321 contacts" model surpassed any individual family ( Fig 5B). 322 323 By individually dropping each family from the "task + whisking + contacts" combined model, we were able 324 to assess whether explanatory power was unique to each family or instead shared across families due to 325 their correlation. In each case, this significantly lowered the goodness-of-fit (Fig 5C), indicating that each 326 family contained some unique information. Goodness-of-fit varied widely across the population but was in 327 general highest in inhibitory and deep-layer neurons ( Fig 5D).  359 We next asked which features of these contacts drove neurons and how this related to shape 360 discrimination. Barrel cortex is arranged topographically with neurons in each cortical column typically 361 responding to the corresponding whisker. Therefore preference for specific whiskers (somatotopy) was a Feature importance was assessed by comparing the goodness-of-fit of GLMs that had access to each 367 feature. Whisker identity (which whisker made contact) was the most critical element determining neural 368 firing ( Fig 6G). The exact kinematics of contacts were less important. Of all the kinematic parameters we 369 considered, contact force explained the most neural activity, but even this effect was relatively small 370 compared to whisker identity. 371 372 We considered the possibility that some alternative kinematic feature that was not measured (e.g., due to 373 limitations in viewing angle or frame rate) might be driving neural activity. We therefore fit a model that 374 also included the identity of the shape (concave or convex) on which each contact was made. If any 375 unmeasured kinematic feature drove neural activity differently depending on the stimulus, this feature 376 should capture some neural variability. Instead, it only slightly improved the model (Fig 6G), even less 377 than including whisker bending (which did not strongly differ between the stimuli). This rules out, at least in 378 a GLM framework, a latent variable that differentiates the stimuli and strongly drives neural activity. 379 380 Thus, during shape discrimination, contact responses are mainly driven by the identity of the whisker 381 making contact. This was also the key feature for decoding stimulus and choice from the behavioral data, 382 suggesting that contact responses might be dynamically modulated by task demands. Task-specific representation of contacts 385 Given that the identity of the contacting whisker was so critical for explaining neural responses, we 386 examined each neuron's tuning using the weights that the GLM assigned to each whisker. Neurons were 387 spatially tuned, exhibiting whisker preferences (Supplemental Fig 6B,C). We did not select for responsive 388 neurons, but rather included all neurons for which we had at least 10 contacts from each whisker. 389 390 During shape detection, the population of recorded neurons as a whole responded nearly equally to 391 contacts made by C1, C2, and C3 (Fig 6H, left). Individual neurons could prefer any of the three whiskers, 392 and in keeping with the somatotopy of barrel cortex, superficial neurons tended to prefer the whisker 393 corresponding to their cortical column (Supplemental Fig 6D). 394

395
In marked contrast, we observed a widespread and powerful bias during shape discrimination: at the 396 population level, neurons responded much more strongly to C1 contacts than to contacts by C2 or 397 especially C3 (Fig 6H, right). Neurons preferring C1 were more prevalent in all cell types and in all  Fig 6I). In an apparent violation of somatotopic organization, neuronal preference across columns was 400 dominated by C1 regardless of the anatomical location. Because this preference was specific to the 401 discrimination task, it could not be a trivial artifact of the shape stimuli or our analysis. Thus, whisker 402 tuning was task-specific and strong enough to override somatotopy. suggests that neurons are retuned to C1 contacts in order to promote convex choices. It would have been 408 equally plausible for neurons to prefer C3 contacts in order to promote concave choices, but this was not 409 observed. This mirrors our behavioral observation (Fig 1G) that mice seemed to rely on a "convexity We asked whether neurons' choice preferences could be explained by their whisker tuning. Specifically, 413 we assessed the tuning of two subpopulations of neurons preferring either concave or convex choices 414 (i.e., those assigned positive or negative weights by the decoder in Fig 4G). Indeed, the convex-preferring 415 subpopulation strongly preferred C1 contacts (Fig 6J, red bars). 416 11 417 In summary, our neural encoder model (Fig 5-6) explains how the neural decoder ( Fig 4G) was able to 418 predict stimulus and choice: neurons were tuned for sensory input that the mouse had learned to 419 associate with convex shapes. These representations were task-specific ( Fig 6H) and could not be 420 explained solely by simple geometrical aspects of the stimuli or whiskers. Indeed, the representations 421 match weights used by the behavioral decoders to identify shapes. Our results link the tuning of individual 422 neurons for fine-scale sensorimotor events to the more global and persistent representations of shape and 423 choice. This bridging of local features to global identity is the essential computation of shape recognition.

425
In this study, we developed a novel head-fixed shape discrimination behavioral paradigm. Mice In sum, we find that whisker identity during contact alone to be the critical parameter for shape 484 discrimination. We cannot exclude the possibility that mice employed this strategy because we had Barrel cortex is thus well-situated to bind precise sensory information to longer-lasting internal states. 523 Rather than generating decisions per se, its role may be to format sensorimotor information in a task- One theory is that whisker motion should be encoded in inhibitory signals so that the brain can predict and Task-specific coding for efficient sensorimotor identification 589 We suggest that the barrel cortex learns to code preferentially for the sensory features that are most 590 relevant for the animal's goals (Ramalingam et al., 2013). In shape discrimination, mice learned to 591 compare the space sampled by the C1 whisker with the space sampled by the C3 whisker. One way to 592 "detect convex" shapes is to preferentially enhance C1 contacts (overrepresented on convex shapes) and 593 suppress C3 contacts, essentially implementing a cross-whisker subtraction. Thus the neural responses to 594 contacts are reweighted to permit the detection of convexity. This computation relies on both a motor 595 strategy (targeting contacts on each shape to specific whiskers) and a neural coding mechanism 596 (enhancing responses to contacts on specific whiskers). Further studies are needed to assess the degree 597 to which neural mechanisms depend on local plasticity versus descending input from higher areas. 598 599 One intriguing possibility is that these computations may be related to efficient coding. Within the 600 timescale of a single trial, mice may refine increasingly accurate models of the shape, as they learn to 601 predict future sensory input from earlier input in the trial. In turn, they could adopt exploratory motion 602 strategies to test their current prediction. These prediction signals are thought to be represented by    enough to reach the shapes at some positions (pink lines). In this example, C1 and C2 were scored as "with contact" and C3 696 as "without contact". All three are considered "sampling whisks" because they protracted far enough to reach the shapes at 697 their closest position. Middle: Features were extracted into sparse two-dimensional arrays of whisker (rows) versus 250 ms 698 time bins (columns). Black squares indicate a whisk with contact (top) or without contact (bottom). Features could be binary 699 (e.g., contact by a specific whisker) or continuous (e.g., angle or force). Right: Logistic regression classifiers predicted 700 stimulus or choice. 701 B) Feature importance quantified by the accuracy of a behavioral decoder trained on that feature alone to identify stimulus 702 (green) or choice (pink). During shape detection (right), the total number of contacts (black arrow) was the most informative 703 feature; this same parameter was much less useful during discrimination. accurately than the mouse does (left panel) during discrimination (p < 0.001, paired t-test) but not during detection (p > 0.05). 713 F) Accuracy of decoders trained to distinguish concave from convex shapes using data from shape discrimination (top) or shape 714 detection (bottom) tasks. The decoders were significantly more able to identify shape during discrimination (p < 0.001, 715 unpaired t-test), indicating that the whisking strategy mice employed for shape discrimination extracted more information 716 about the shape's identity.

717
G) The weights assigned by the decoder to the "whisks with contact" feature, separately plotted by which whisker made contact. 718 Weights were relatively consistent over the trial timecourse (data not shown) and are averaged over time here for clarity. 719 They are expressed as the change in log-odds (logits) per additional contact.

720
H) The mean number of contacts per trial for each whisker during shape discrimination, separately by shape identity (concave or 721 convex) and position (far, medium, or close indicated by shading; cf. Fig 1B). Although each whisker may touch one shape or 722 the other more frequently, no whisker touches a single shape exclusively. 723 I) Videos for all sessions and mice were registered into a common reference frame based on shape positions. Top: single frame 724 showing whisker identity and location of whisker pad for reference. Bottom: location of the concave (blue) and convex (red) 725 shapes in the common reference frame, with average location of whisker pad marked. 726 J) Location of the peak of each whisk with contact (top) or without contact (bottom) in the common reference frame. Each 727 whisker (C1, C2, and C3; blue, green, and red) samples distinct regions of shape space (gray ovals).

728
K) The same data from panel (J), but now colored by their strength of the evidence about shape (red: convex; blue: concave) 729 using the decoder weights. Top: C1 (C3) contacts occur in a region that is more likely to contain a convex (concave) shape.

730
Bottom: On whisks without contact, the mapping between whisker and shape identity is reversed. Note that the sampled 731 areas can contain either shape, so sampling one area alone is not sufficient to perform the task.   Fig 4G. Neurons that fire more for convex choices respond much more 800 strongly to C1 contacts than to C3 contacts, similar to the weights used by the optimized behavioral decoder (cf. Fig 3G). We report data here from 17 adult mice (11 females and 6 males) of the C57BL6/J strain bred in the 814 Columbia University animal facilities. 11 mice were used for shape discrimination, 5 for shape detection, 815 and an image was used from 1 mouse from a different, anatomical study (Fig 4A). Of these, one shape 816 discrimination mouse was discarded from all video analysis because of poor video quality, but was still  Behavioral training 878 Throughout, the mice were denied access to water in the home cage and learned to receive their water 879 during behavioral training. We closely monitored their water intake, weight, and general health to ensure 880 they did not become dehydrated. Ad libitum water was provided if necessary to ensure health. 881 882 Mice were trained to perform either the shape discrimination or detection tasks using a process of gradual 883 behavioral shaping described below. Some mice were additionally trained to discriminate flatter, more 884 difficult shapes. 885 886 1. "Lick training." Mice initially learned to lick to receive water. They were advanced through each step 887 of this stage only once they learned to receive sufficient daily water from the apparatus. First, they 888 were placed in the apparatus without head-fixing and allowed to drink freely from the water pipes, 889 which rewarded every lick. Next, we head-fixed the mice directly in front of a single lick pipe and 890 rewarded every lick. Finally, mice were presented with two lick pipes (left and right) and learned to 891 lick alternately from each of them, first in blocks of ten licks and gradually decreasing to a single 892 lick on each side. This stage required 12.5 sessions on average. 893 2. "Forced alternation". We introduced the complete trial structure for the first time, presenting shapes 894 and rewarding the mouse only for correct responses and punishing it with a timeout for incorrect 895 responses. During this stage the shape on each trial was not random; instead, mice were 896 repeatedly presented with the same shape trial after trial until it gave the correct response. After a 897 correct response, the other stimulus was presented. Thus, mice could perform at 100% by 898 26 alternating responses from trial to trial. The timeout was initially 2 s and then increased to 5 s and 899 finally 9 s as the mice became accustomed to it. This stage required 11.3 sessions on average. 900 3. "Stimulus randomization with bias correction". During this stage, stimulus identity was randomized 901 on each trial and only presented at the closest position. Each session began with 45 trials of 902 "forced alternation" to ensure that mice were able to lick both directions. After that, trials were 903 generally random. The software continuously monitored their performance for biases; when a 904 strong bias was detected, it stopped presenting trials randomly and began presenting trials 905 designed to counteract the bias. For instance, if mice responded on the left ≥20% more than on the 906 right, the software would deliver only right trials. Alternatively, if the mice showed a significant 907 perseverative bias (ANOVA "choice ~ stimulus + side + previous_choice", p < 0.05 on 908 previous_choice), the software would deliver "forced alternation" trials. Critically, we only ever 909 analyzed truly random trials from the session. Non-random trials were used only for behavioral 910 shaping and were discarded from behavioral and neural analyses. 6. "Whisker trimming". We gradually trimmed whiskers off the right side of the face: first we trimmed 917 the A and E rows, then the B row, then the D row. After any trimming, we allowed mice to recover 918 to high performance before trimming additional rows. We retrimmed previously trimmed whiskers 919 as necessary to ensure they could not reach the shapes. Stages 3-6 required a total of 109.1 920 sessions on average. To record neural activity, we head-fixed the mouse in the behavioral arena as usual and removed the 945 temporary sealant over the craniotomy. We lowered an electrode array (Cambridge Neurotech H3) using a 946 27 motorized micromanipulator (Scientifica PatchStar), noting its depth at initial contact and at final position. 947 We used an OpenEphys acquisition system with two digital headstages (Intan C3314) to record 64 948 channels of neural data at 30 kHz at the widest possible bandwidth (1 Hz to 7.5 kHz). The backlight sync 949 pulse was acquired with an analog input to synchronize the neural, behavioral, and video data. 950 951 We used KiloSort (Pachitariu et al., 2016) to detect spikes and to assign them to putative single units. 952 Single units had to pass both subjective and objective quality checks. First, we used Phy (Rossant et al.,953 2016) to manually inspect every unit, merging units that appeared to be from the same origin based on 954 their amplitude over time and their auto-and cross-correlations. Units that did not show a refractory period 955 (i.e. a complete or partial dip in the auto-correlation within 3 ms) were deemed multi-unit and discarded. 956 Second, single units had to pass all of the following objective criteria: ≤5% of the inter-spike intervals less 957 than 3 ms; ≤1.5% change per minute in spike amplitude; ≤20% of the recording at <5% of the mean firing 958 rate; ≤15% of the spike amplitude distribution below the detection threshold; ≤3% of the spike amplitudes 959 below 10 μV; ≤5% of the spikes overlapping with common-mode artefacts. On the last day, we inserted a glass pipette coated with DiI (Sigma-Aldrich 468495) into the barrel field 977 twice to leave two landmarks, one anterior and one posterior, which were also photographed and aligned. 978 At the conclusion of the experiment, we deeply anesthetized the mice with pentobarbital, transcardially 979 perfused them with 4% paraformaldehyde, and removed the brain for histological processing. Throughout this manuscript, "*" indicates p < 0.05; "**" indicates p < 0.01; "***" indicates p < 0.001; and 990 "n.s." indicates "not significant". Eight equally spaced points along each tracked whisker were provided as the "joints" for the neural 1006 network to identify. We iteratively improved the neural network by evaluating it on new frames, choosing 1007 difficult frames from the result, semi-automatically improving the labels, swapping in the results from 1008 `whisk` as necessary, and then using this new training set to train a new version of the network. Whiskers 1009 of below-threshold confidence or below-threshold smoothness at any joint were discarded. We optimized 1010 these thresholds with a cross-validated grid search. Sessions with inaccurate labeling were discarded: we required that every whisker be labeled in ≥95% of 1013 the frames, that ≤2% of the contact events contained even a single frame with a missing label, and that 1014 the arcs traced out over the entire session by the whisker contained no discontinuities or jumps suggestive 1015 of tracking errors. In the remaining well-traced sessions we interpolated whiskers over any missing 1016 frames.
1017 1018 We identified the shape stimulus in each frame by thresholding and segmenting the frame and selecting 1019 the segment of the appropriate size and location. We identified contacts on the shape based on proximity 1020 (≤10 pixels Cartesian distance) between the tip of each whisker and the edge of the shape. To estimate each whisker's bending moment, we first fit a spline through its 8 identified joints and used the 1023 "measure" function of `whisk` to estimate curvature (κ). κ is the rate of change of direction of the whisker at 1024 each point along its length, i.e. the reciprocal of the radius of curvature at that point, and is measured in 1025 units of m -1 . `whisk` averages κ over the entire length of the traced whisker and we followed this 1026 convention. For comparison with other studies, we note that 1 m -1 is equal to 0.001 mm -1 due to this 1027 reciprocal. κ = 0 for a straight line. In our study, κ > 0 for a whisker pushing into a shape and κ < 0 for the 1028 reverse curvature, typically encountered while detaching from the shape. To register all videos within a common reference frame for visualization (Fig 3I-K), we extracted the 1031 location of the shape edge at each location (close, medium, or far). Because we knew the exact distance 1032 between edges in reality, we used the vector between adjacent locations in the image to measure the 1033 angle and scale for that particular video. After compensating for this angle and scale, we used the peak in 1034 the 2D cross-correlation to find the offset that best aligned the videos with each other.