Mice learn multi-step routes by memorizing subgoal locations

Animals must rapidly gather spatial information about new environments so that they can quickly reach food or safety even when direct paths are unavailable. The behavioral strategies used to implement multi-step routes to goals in naturalistic settings are unknown. Here we show that mice spontaneously learn a subgoal memory strategy while escaping to shelter or seeking food in an obstructed environment. We first investigated how mice navigate to shelter in response to threats when the direct path is blocked by a wall. Initially, mice ran straight toward the shelter and circumvented the obstacle using sensory cues. Over the course of 20 minutes, however, they switched to a spatial memory strategy to execute spatially efficient paths. Efficient escape routes were not learned by reinforcing egocentric actions or by constructing an unbiased internal map during exploration. Instead, mice used a hybrid strategy: they memorized specific subgoal locations encountered during previous running movements toward the obstacle. We then found that the same behavioral strategy is also used in a reward-seeking task. These results show that spontaneous memorization of local subgoals is a fundamental strategy by which rodents execute efficient multi-step routes to goals in novel environments.


Introduction
For prey species such as mice, quickly finding effective routes to goals is critical for survival because it 22 reduces exposure to potential predators (Lima and Dill, 1990). This is a challenging task: natural environments are 23 complex, and wild animals must compute multi-step routes taking into account uneven terrain, obstacles, and 24 dynamically changing environments. Ethological studies of wild rodents have emphasized the roles of locating salient 25 landmarks (Drickamer and Stuart, 1984;McMillan and Kaufman, 1995) and adhering to familiar paths (Benhamou, 26 1991; Thompson, 1982) in overcoming these challenges. However, observational studies are unable to identify the cues 27 and behavioral strategies that animals actually use to navigate. 28 Experimental evidence from rodents trained to locate goals has uncovered multiple types of spatial reasoning 29 that can be used to solve complex navigational problems. On the one hand, rodents can keep track of where they are 30 within an allocentric (environment-centered) reference frame (Morris, 1981). This sense of position is thought to be 31 has shown that gerbils can use spatial memory to reach the hidden shelter after a brief period of exploration (Ellard and 23 Eller, 2009). Thus, rodent escape offers not only reliable, stimulus-locked trajectories and rapid learning within a single 24 session but also a reliance on spatial reasoning. These qualities make escape a useful model for understanding how 25 animals learn and execute complex goal-directed trajectories within the time constraints compatible with survival in 26 natural settings. 27 Here we first investigate the strategies that mice use to navigate to a shelter in response to auditory threats 28 when the direct path is blocked by a wall. Through quantitative analysis of escape trajectories and their relationship to 29 exploratory behavior, systematic variation of spatial conditions, and dynamic modifications to the environment, we 30 describe how mice learn to execute efficient multi-step escape routes within minutes of entering a novel, obstacle-laden 31 environment. We then show that the navigational strategy for escape is also used for reaching a food reward goal. 32

Mice rapidly learn efficient escape trajectories in the presence of obstacles 2
As a baseline condition for investigating how mice learn escape trajectories, we placed naïve animals in a 3 circular, open-field arena with a shelter. After a brief exploration period during which mice spontaneously located the 4 shelter, we exposed them to a loud, overhead crashing sound while they were in a pre-defined threat zone (Fig. 1A). 5 This reliably elicited rapid escapes directed at the shelter along a straight 'homing vector' (Fig. 1A-B, Extended Data 6 Fig. 1A, Supplementary Video 1-2), similar to previous results (Vale et al., 2017). We then repeated this experiment in 7 a separate group of mice, with a wall positioned between the threat zone and the shelter. This wall was white against a 8 black background and all mice approached and walked along it during the exploration period (Extended Data Fig. 1B). 9 To quantify initial escape directions, we computed a direction score between 0 and 1, where 0 is an escape vector aimed 10 directly at the shelter and 1 is a vector aimed at the obstacle edge ( Fig 1A); escapes are classified as edge vectors if they 11 surpass the 95 th percentile of escape direction in the open field (direction score > 0.68). On the first trial of threat 12 presentation, 53% of the mice ran toward the shelter as in the open-field condition and only circumnavigated the 13 obstacle after approaching it ('homing-vector escapes; Fig. 1A test whether homing-vector escapes were directed at the shelter or were instead exclusively aimed at the safety that can 23 be provided by running along a wall (Simon et al., 1994). First, replacing the wall obstacle with an unprotective hole 24 obstacle did not reduce the fraction of homing-vector responses (Extended Data Fig. 1D-E). Second, moving the shelter 25 to the side of the arena abolished escapes directed at the center of the obstacle (Extended Data Fig. 1D-E). Thus, after 26 limited experience with an obstacle, a large proportion of mice default to homing-vector responses when exposed to 27 threats. 28 Over the course of 3 threat presentation trials within 20 minutes, mice performed escapes that were 29 increasingly spatially efficient (median ratio of shortest path to the actual escape path; trial 1: 0.77, IQR 0.65-0.89 vs. 30 4 1 trial 3: 0.92, IQR 0.86-0.95; F(2, 30) = 7.1, p = .003, repeated measures ANOVA on trials 1-3; Fig. 1C) and rapid -1 (median normalized escape duration: 3.6 s, IQR 3.  , after the animals explored the environment with the obstacle for 20 minutes and with 3 escape  19 trials, we removed the obstacle at the moment of threat onset ("acute obstacle removal"; Supplementary Video 6). 20 Despite the obstacle disappearing before the termination of the mouse's initial orientation movement, all animals 21 escaped along the edge vector and did not turn toward the shelter until they passed by the location where the obstacle 22 edge used to be (median direction = 0.98, IQR 0.84-1.01; N = 7 animals; Fig. 2A-B). This experiment shows that after 23 experience in the arena, edge-vector escapes have a strong memory component. Next, we examined how persistent this 24 memory-based strategy is. We allowed mice to explore for ~5 minutes after removing the obstacle ("chronic obstacle 25 removal"; Supplementary Video 6), during which time they all visited the now empty center of the arena (Extended 26 Data Fig. 3A). Escapes on 46% of the subsequent trials were still directed at the location where the obstacle edge used 27 to be (N = 29 trials, 13 animals, 2-3 trials per animal; Fig. 2A-B), indicating that memory-based escape trajectories 28 persisted even after exploring the arena with the obstacle removed. 29 Developing a memory for guiding edge-vector escape trajectories could in principle be acquired through 30 repeated escapes during exposure to threat or through exploratory behavior alone. To distinguish between these two 31 possibilities, we let mice explore the arena with the obstacle for 20 minutes without exposing them to threat stimuli. 32 Threat presentation after this period resulted in persistent edge-vector responses that were as frequent as when threats 1 were presented during exploration with the obstacle (Extended Data Fig. 3B). These results show that within 20 minutes 2 in a novel environment, mice spontaneously develop a robust strategy for multi-step escapes that relies on spatial 3 memory. 4 Our experiments so far have revealed a memory-based obstacle avoidance strategy. We have also shown, 1 however, that sensory input is used to navigate around the obstacle when experience is limited. We therefore tested how 2 perception and spatial memory operate in tandem when both are fully available. We repeated the chronic obstacle 3 removal experiment in a novel arena, but instead of removing the obstacle, we changed its length by 25% ( Fig. 2C Mice learn to avoid obstacles during escape by memorizing subgoal target locations 16 We next aimed to characterize the spatial-memory strategy and how it is learned. We evaluated whether mice 17 were learning escape routes using three possible strategies: habitual learning of turn angles, constructing a global 18 cognitive map of the arena, or learning subgoal locations individually. First, we tested whether mice learn egocentric 19 movements from the threat zone to the obstacle edge, similar to habitual learning in mazes. To test this, we extracted 20 from the chronic obstacle removal experiment all continuous turn-and-run movements from the threat zone to within 5 21 cm of the obstacle ("homing movements"; Fig After validating a linear prediction model to predict escape direction from turn angles (Extended Data Fig. 5A-B), we 24 tested whether mice could be implementing escapes by repeating turn angles from previous homing movements. We 25 took the previous turn angle that is most similar to the one used during the escape and used it to predict escape 26 direction, i.e. whether the mouse will escape toward the shelter or toward an obstacle edge. We found that these angles 27 did not match escape angles precisely enough to reliably predict escape direction (median R-square from linear 28 prediction model = -0.03; Fig. 3B). Thus, homing movements are not stereotyped enough to explain escape 29 directionality, and therefore reinforcement of turns cannot explain memory-guided edge-vector responses. 30 To experimentally verify that memory-guided edge-vector responses are not habitually repeated responses but 31 rather goal-directed actions, we examined whether their expression is sensitive to changes in the goal location. We 32 8 repeated the chronic obstacle removal experiment, but this time moving the shelter to a new location after the 20-minute 1 period with the obstacle. The distribution of egocentric actions during the initial 20 minutes was the same between the 2 constant shelter and shelter displacement conditions (Extended Data Fig. 4B), which should result in a similar 3 frequency of edge-vector responses if the underlying process were based purely on action reinforcement. In contrast, all 4 escape paths after moving the shelter were homing vectors directed toward the new shelter location (median direction = 5 0.25, IQR 0.20-0.34, N = 7 mice, 18 trials), with zero edge-vector responses (Fig. 3C). This experiment confirms that 6 the spatial memory mechanism for escape does not reinforce habitual, egocentric movements. Instead, our data suggest 7 that edge-vector responses result from a goal-directed process, where mice specifically target the obstacle edge location 8 in order to reach the shelter. 9 Next, we investigated whether learning the spatial relationship between the obstacle edge and shelter locations 10 arises from constructing an abstract internal map of the arena during the exploration period. Thus, we measured the 11 correlation between escape paths and the time spent exploring various features of the environment, such as the obstacle, 12 the obstacle edge, the back half of the arena and the entire arena, both before and after obstacle removal. Exploring the 13 environment should help incorporate its features into an internal model of space, and so these correlations could provide 14 evidence that mice use such an abstract representation for escape. However, none of the 12 correlations analyzed were 15 significant (median correlation coefficient 0.06, IQR 0.00-0.19; median p-value 0.57, IQR 0.32-0.84; Fig 3E; Table 1). 16 We therefore examined the alternative possibility that instead of using a global map, mice learn to repeatedly 17 target individual subgoal locations accessed during previous homing movements. To test this hypothesis, we extracted 18 the target, rather than the angle, of homing movements (Fig. 3A,D). We first found that the occurrence of a prior 19 homing movement targeting the obstacle edge was significantly correlated with the escape direction (R=0.52, P=0.004; 20 Table 2). Next, we computed the mean homing movement target prior to the escape and used this target point to predict 21 subsequent initial escape directions; this measures how often the mouse has previously run along homing or edge-22 vector paths (excluding edge-vectors to the obstacle edge on the opposite side of the arena; Fig. 3D). This prior 23 movement target direction was even more strongly correlated with the direction of subsequent escapes (R=0.83, 24 P=3.7x10 -8 ; Fig. 3E, Table 2). These correlations were only present when examining the relationship between escapes 25 directed toward a particular obstacle edge (i.e. left vs. right) and prior homing movements toward that same side, but 26 not with prior homing movements toward the opposite edge (Table 2). 27 To directly compare the predictive power of time spent exploring against average prior movement targets, we 28 built a linear model to predict escape directions from exploration inputs and prior homing movements. For the 29 exploration inputs, we used the best correlate with escape direction (time spent exploring the side of the arena opposite 30 from the shelter), both before and after obstacle removal. The model showed that prior homing movements are highly 31 predictive of the spatial targets of escape (median R-square = 0.60), while time exploring has no predictive power 32 (median R-square = -0.32; Fig. 3B, Extended Data Fig. 5C). Weighting prior homing movements more strongly if their 1 initial position or angle was close to the escape's initial conditions did not improve prediction (Extended Data Fig. 5D) . 2 This affirms that mice are learning subgoal locations rather than actions or paths. 3 Finally, we verified these results on the acute obstacle removal experiment by removing the obstacle during the 4 1 st trial. As expected by our analysis of the chronic removal experiment, all mice with at least one prior movement 5 targeting the obstacle edge also ran to that edge location during the escape (median direction = 0.98, IQR 0.91-0.98; 6 Extended Data Fig. 4C; Table 1). All mice with no such movements, however, ran straight toward the shelter (median 7 direction = 0.30, IQR 0.29-0.43; Extended Data Fig. 4C). Additionally, none of the correlations with exploration were 8 significant (Table 1). Together, these results suggest that the spatial-memory strategy for escape consists of directly 9 learning specific spatial subgoal locations targeted by previous homing movements, rather than repeating fine-grained 10 actions or gradually constructing an unbiased internal map through exploration. 11

12
Instinctive exploratory movements and one-shot learning can explain subgoal learning 13 The ability of our model to predict escape targets based on the prior history of edge-vector movements 14 suggests that these movements might be the basis for rapid learning of spatial subgoals. However, it remains unclear 15 what prompts these movements in the first place and how they may lead to the acquisition of subgoals. Thus, we further 16 analyzed the properties of spontaneous edge-vector movements and their relationship to learned escape paths. First, we 17 observed that edge-vector movements occur most during the first few minutes of the session and occur equally with or 18 without a shelter in the environment (Fig. 4A-B). Second, when the obstacle is a hole, learning to perform efficient 19 multi-step escapes takes twice as long (% edge-vectors escapes: 20% on trial 2-3, 67% on trial 6-7; Next, we analyzed whether exploratory movements toward or away from the shelter have a differential role in 28 establishing subgoals. While mice execute edge-directed movements from both the shelter side and the opposite side of 29 the arena, we found that movements from the threat area toward the shelter are much more predictive of subsequent 30 escapes (toward shelter: R = 0.83, P = 3.7x10 -8 ; away from shelter: R = 0.43, P = 0.019; Table 1). In addition, weighting 31 the importance of prior homing movement targets based on how soon they arrive at the shelter improved the prediction 32 of memory-guided escape direction (median R-square without weighting = 0.64; median R-square with weighting = 1 0.74; Extended Data Fig. 5D). These analyses suggest that subgoals are identified in a direction-specific manner and are 2 based on providing access to a goal on the opposite side of the arena. To test this hypothesis experimentally, we first let 3 mice explore the arena with a wall obstacle but without a shelter. After exploration, we removed the obstacle and added 4 the shelter, which all mice quickly located. In contrast to the behavior when the shelter is present throughout the 5 session, threat presentation under these conditions elicited escapes that were predominantly homing-vector responses 6 (82%), with only a few edge-vector trajectories (18%; median direction: 0.38, IQR 0.20-0.55; Fig. 4E). The subgoal 7 memory was therefore deployed infrequently. Nonetheless, escape direction was still significantly correlated with the 8 mean prior movement target but not with any other exploration or movement metric (Tables 1-2). Thus, as predicted by 9 our analysis of edge-vector movements, subgoal memorization occurs primarily when the shelter-goal is present during 10 exploration. These results support a role for instinctive edge-vector movements together with knowledge of a goal 11 location in generating the rapid learning of multi-step escape routes. 12 Our data show that mice learn efficient escape routes through a subgoal strategy that relies on execution of 13 edge-vector movements toward the shelter. We next further characterized how spatial efficiency changes with 14 experience. We found that the improvement in spatial efficiency with experience is fast, as a single prior edge-vector 15 homing movement is significantly associated with greater escape efficiency in the presence of an obstacle (median  Fig. 6A-B). A cost of the rapid subgoal 24 memorization strategy is therefore reduced flexibility to sudden changes in the environment. 25 26

Subgoal learning supports food-seeking trajectories 27
Based on this trade-off favoring speed over flexibility, we considered that this strategy could be specific to 28 stimulus-evoked escape behavior. To test this, we performed an obstacle removal experiment in the context of a less 29 urgent, reward-based task. First, we trained food-deprived mice to approach and lick a reward port in response to a 10-30 kHz tone, which indicated the availability of condensed milk at the port. This took place across 5 sessions, in an operant 31 conditioning box (Extended Data Fig. 7). Next, we transported this task to the arenas previously used for escape 32 behavior: the shelter was replaced by the reward port, and the threat stimulus was replaced by the 10-kHz tone. Mice 1 reliably ran toward the reward port upon tone presentation, but with slower reaction times (median time to start running 2 toward goal: 1.5 s, IQR 0.7-3.5 s for food task; 0.6 s, IQR 0.4-1.2 s for threat response; P=0.005, permutation test). Supplementary Video 9). As with escape, these trajectories were correlated to prior running movement targets but not 1 with other features of exploration (Tables 1-2). 2 Finally, we tested whether experience with the obstacle induces a non-specific increase in edge-vector 3 movements, as this could trivially explain the apparent use of subgoal memorization across two distinct tasks. We 4 measured how frequently mice moved from the ends of the arena toward the center and toward the edge locations 5 during exploration. In contrast with evoked escapes and food-approach paths, exploratory paths following obstacle 6 removal were no more likely to target the obstacle edges than in the open-field control condition (Fig. 5D-E). Subgoal 7 memorization therefore reflects a strategy for goal-directed navigation rather than a general bias in how mice move 8 around their environment following experience with an obstacle. These experiments suggest that subgoal memorization 9 and its underlying trade-off between speed and flexibility are general components of how mice implement multi-step 10 paths to goals in novel environments. 11

13
We have found that mice learn efficient routes to goals in obstacle-laden environments using a fast, innate 14 subgoal memorization strategy. For the first few minutes after entering a new environment with obstacles, mice escape 15 to shelter by relying on their homing instinct and memory of the shelter location to run directly toward the shelter, and 16 then use sensory cues to navigate around obstacles as they are encountered. These escapes are spatially inefficient. They 17 resemble paths that species with less advanced spatial reasoning, such as toads, crabs, and ant colonies, take around 18 obstacles to reach a goal (Collett, 1982;Freas and Schultheiss, 2018;Layne, 2003). Over the course of 20 minutes, 19 however, mice start taking escape routes that directly target the obstacle edge. These efficient escapes depend on a 20 memory of the edge location; this is particularly evident when mice complete multi-step escapes around an obstacle 21 even after the obstacle has been removed. escaping in an obstructed environment suggested that spatial memory was employed to reach the shelter (Ellard and  27 Eller, 2009), but the navigational strategy that the animals used was unknown. Our results show that mice efficiently 28 navigate to shelter by using subgoals in an allocentric reference frame. Several observations support this view. First, 29 mice accurately target the edge location at least 10 minutes after the obstacle has been removed, which cannot be 30 explained by a pure egocentric strategy. Second, escape trajectories involved immediately orienting and running toward 31 a sub-goal ~50 cm away, which is not consistent with following odor trails or gradients (Liu et al., 2020;Wallace et al., 1 2002). Third, mice switch between targeting the shelter and the subgoal depending on which side of the obstacle they 2 are on. This requires awareness of external metrics such as vectors to the obstacle and shelter. Fourth, the inability of 3 turning movements to predict memory-guided escape directions rules out repeating egocentric turns as a primary 4 mechanism. Fifth, moving the shelter after the exploration period abolished the expression of memorized subgoals, 5 showing that the spatial memory strategy is goal-directed rather than habitual. Finally, when we changed the obstacle's 6 length, escape paths inaccurately targeted not only the new obstacle edge location but also the shelter. This suggests 7 that mice are tracking the spatial relationship between the obstacle edge and the shelter within their spatial schema of Our results agree with ethology studies that have described movement patterns in the wild as highly 26 dependent on the individual animal's prior paths (Benhamou, 1991;Meade et al., 2005;Thompson, 1982). Many 27 strategies, such as odor trails, learning visual beacons, and learning fine-grained actions, could in principle 28 underlie these previous results. Here we identify repeating subgoal targets as a fundamental, spontaneous 29 learning process for mouse escape routes. In particular, our analysis of edge-vector movements supports the 30 following working model: mice spontaneously execute visually guided edge-vector movements toward a salient 31 wall edge during exploration or escape; if this movement brings the mouse toward a goal (here, the shelter), then 32 its target is memorized as a subgoal location that should be visited when escaping from behind the subgoal. We 1 hypothesize that a one-shot learning rule works on the spatial targets of these instinctive actions, but further 2 experiments should be done to directly test for causality. 3 Memorizing subgoals confers distinct survival advantages: it drives escape routes with the optimality of 4 map-based planning and the rapidity of instinctive responses. However, this strategy is less flexible than 5 sensory-guided or map-based mechanisms: mice continue to execute roundabout escapes in the absence of an 6 obstacle, until re-establishing the homing-vector path. Responses to imminent predatory threats are known to 7 favor quick reaction times at the expense of computational sophistication (Mobbs et al., 2020), so this strategy 8 could in principle be specific to escape from imminent threat. Nonetheless, we found that it was also used in a 9 less urgent food-seeking task, suggesting that it might be a general building block for quickly learning spatial 10 locations that are important for survival. Indeed, unlike food-approach paths, exploratory movements across the 11 arena were unaffected by experience with the obstacle. Thus, subgoals are not simply preferred locations but 12 rather take part in specific goal-directed behaviors. 13 Subgoal learning bears some resemblance to hierarchical reinforcement learning (HRL), a technique in 14 artificial intelligence for learning multi-step behaviors (Sutton et al., 1999). However, the learning process we The main arena was an elevated white acrylic circular platform 92 cm in diameter (Extended Data Fig. 8A). is the 9 platform had a 51 cm x 1 cm hole in its center; through this hole, the obstacle (white acrylic, 50 cm long x 12.5 cm tall 10 x .5 cm thick) could be raised (obstacle condition) or lowered (open field condition). For experiments in which the 11 obstacle appears or disappears, this was done by digitally triggering a custom-made pneumatic tubing system (time to 12 raise or lower the obstacle was ~100 ms). In the acute obstacle removal experiment, this was triggered simultaneously 13 with the stimulus onset. In chronic obstacle removal experiments, this was triggered while the mouse was in the shelter.

Escape behavior 28
Animals were given a 7-minute acclimation period during which they discovered the shelter. Stimuli were subsequently 29 delivered when the mouse entered the threat zone (the back 20 cm, on the end opposite from the shelter) and was 30 generally facing away from the shelter. Only stimuli delivered in this zone were analyzed. At least one minute was 31 allowed in between trials. Threat stimuli were loud (87 dB), unexpected crashing sounds played from a speaker located 1 1m above the center of the arena. Free sounds ("smashing" and "crackling fireplace") were downloaded from 2 soundbible.com. They were then edited using Audacity software such that they were equally and continuously loud. 3 Stimuli were alternated between the "smashing" sound and the "crackling" sound to prevent stimulus habituation. In 4 some sessions (4 with and 4 without an obstacle), we used an ultrasonic sweep stimulus (17-20 kHz, 3 sec). No 5 difference in response between the stimuli was observed and therefore the data from these sessions were pooled. For 6 each trial, the stimulus was triggered repeatedly until the mouse reached the shelter, for a maximum 9 seconds. Since 7 escapes take longer with the hole obstacle and in the dark, stimuli in these conditions were played for up to 12 seconds. 8 Stimulus responses were considered as escapes if the mouse reached the shelter within 12 seconds in the light or 18 9 seconds for the hole obstacle and for the wall obstacle in the dark. Mice varied in how many trials they performed in 10 each experiment. We thus limited analysis to the first 3 escapes in each condition (more than 50% of mice completed at 11 least 3 escapes in all experiments). In the arena with the wall obstacle, the probability of threat-evoked escape to shelter 12 was 93%, while the probability with a no-stimulus control was 12%. 13 14

Food-approach behavior 15
Mice were food restricted to 85% of their baseline weight. They were then trained in 5, ~1-hour sessions to approach 16 and lick a metal spout in response to a 9-second 10-kHz tone. Training was done in a 60cm x 15cm rectangular arena. 17 Licking the spout while the tone was on resulted in a 7-µL drop of condensed milk (diluted 1:1 with water) being 18 delivered. For the lick raster plots, licks were plotted at 5 licks/sec when the sensor was tonically triggered by licking. 19 These mice had two sessions. The first session was in the escape arena with no obstacle, the shelter in its usual location, 20 and a lick spout on the opposite end of the arena. They received "practice trials" of tone and milk, mostly when they 21 were near the lick spout. After 20 minutes, trials were initiated when the mouse was on the opposite side from the lick 22 spout, and these data were used for analysis. In the second session, the obstacle was initially present, and then after 20 23 minutes it was removed, while the mouse was in the shelter. Mice performed more trials than with the escape behavior, 24 so here we examined trajectories from the first 9 successful trials (greater than 50% of mice completed at least 9 trials). 25 For testing correlations, to match the analysis performed on escapes, we limited analysis to the first 3 trials. 26 27

Video tracking and visualization 28
Videos were acquired at 30 frames per second using an overhead camera with a near-infrared-selective filter. Videos 29 were then fisheye-distortion corrected, aligned onto a common coordinate framework, and visualized with custom 30 Python code using the OpenCV library (github.com/BrancoLab/Common-Coordinate-Behaviour; Supplementary Video 31 1). We used DeepLabCut (github.com/AlexEMG/ DeepLabCut) to track the mouse from the video, after labelling 1500 32 frames with 13 body parts. Post-processing includes removing low-confidence tracking, using a median filter to discard 1 outliers, and applying an affine transformation to the tracked coordinates to match the common coordinate framework. 2 3 Analysis 4 All analysis was done using custom software written in Python (github.com/BrancoLab/escape-analysis). 5 Escape initiation time was computed as the time from the stimulus onset to the first moment that the center of the 6 mouse moves toward the shelter at ≥62.5 cm s-1 averaged over 3 frames. The initial escape direction was computed by 7 taking the vector from the mouse's position at the reaction time to its position when it is 10 cm in front of the obstacle. 8 We computed a direction score where a vector aimed directly at the shelter received a value of 0; one aimed at either 9 obstacle edge received a value of 1.0; a vector halfway between these would score 0.5; and a vector that points beyond 10 the edge would receive a value greater than 1.0. The formula is: direction= abs((offsetHV-offsetEV+offsetHV-EV)/(2 * 11 offsetHV-EV )), where offsetHV is the distance from the mouse to where the mouse would be if it took the homing vector, 12 offsetEV is the distance from the mouse to where the mouse would be if it took the obstacle-edge vector, and offsetHV-EV 13 is the distance from the homing-vector path to the obstacle-edge-vector path. Only the obstacle edge closest to the 14 escape path was considered. Initial food-approach trajectories and spontaneous exploration trajectories were analyzed in 15 the same manner. The threshold for classifying a trajectory as an obstacle edge vector (as opposed to a homing vector) 16 was the 95th percentile of escapes in the open-field condition (0.68). For examining the effect of experience on 17 spontaneous exploration, we used a threshold of 0.5 to distinguish center-directed and edge-directed movements. 18 Previous homings used to predict escape trajectories included both stimulus-evoked escapes and spontaneous 19 homings. These were extracted by taking movements that start in the side of the arena opposite the shelter and behind 20 the wall by ≥10 cm, and then move toward the shelter or obstacle edges without any pauses longer than 1 s or moments 21 in which the mouse faces away from the shelter direction. To obtain the mean direction of previous movements, we 22 averaged the 10 most recent homings and then computed the direction score using the formula above. To predict escape 23 direction, we needed to prevent previous obstacle-edge vectors on the right from influencing our prediction of whether 24 the mouse will execute an obstacle-edge vector on the left and vice versa. To achieve this, we did not consider previous 25 movements targeting the left 20% of the obstacle (10 cm) when making a prediction for the trajectory of escapes that 26 are closer to the right edge. 27 Spontaneous exploratory traversals were considered exploratory paths that start at either end of the arena 28 (within 20 cm of either end) and then cross the center. Traversals that go along the boundary of the arena (i.e. greater 29 than 10 cm past the obstacle edge) or take longer than 2 seconds were excluded from analysis. 30 For permutation tests, the test statistic is the group mean difference (e.g. in escape direction or path efficiency). 31 The condition of each mouse (e.g. open field vs obstacle) is randomly shuffled 10,000 times to generate a null 32 distribution. For comparisons on quantities other than direction, outliers (> 2 IQR from median) were removed. Tests 1 for differences in efficiency, reaction time, and initial escape conditions were two-tailed; tests for increases in edge-2 vector responses compared to an open-field control were one-tailed. The ANOVA was performed using the linear 3 mixed effects model package in R, after removing outliers (z-score > 0.975). 4 For the linear prediction models, we used ridge regression with regularizer alpha = 0.1. Predictive power on 5 escape direction using exploration or turn angles was not dependent on alpha in the range [0, 10], while predictive 6 power using prior movements was constant in the range [0, 0.5] and gradually decreased above alpha = 0.5. 1,000 7 shuffles of a 2-fold cross validation were performed, and the probability density of r 2 prediction scores on the test data 8 was plotted. To predict using prior escape directions, we used the direction of the mean target of prior homing 9 movements, as described above. To subtract the contribution of time spent exploring to prior homing movement targets 10 and vice versa, we performed a linear regression predicting each variable from the other. We then used the residual 11 values from this prediction as input to the main linear prediction model. To weight prior homing movements by their 12 initial position or angle, we used a weighted mean target of prior homing movements in the prediction model. The 13 weight of each prior movement varied between 0 (initial positions ≥50 cm apart or body angle off by 180º) and 1 (same 14 initial position or body angle); to weight based on how long it takes to end up in the shelter after for executing a homing 15 movement from the threat zone, weights varied between 0.1 (≥12 seconds) and 1 (0 seconds). In all weightings, weights 16 were normalized to sum to 1. 17 To predict using turn angles, escapes and spontaneous movements were first decomposed into individual turn-18 and-run movements in which the mouse continuously turns and/or runs in a consistent direction. Only movements in 19 which the mouse moved at least 10 cm closer to the shelter or obstacle edges were used. We used the angle between the 20 mouse's body at the starting point of the movement and its body angle after it had moved 10 cm away from that point. 21 This value is negative for left turns and positive for right turns. For predicting direction from turn angles, we 22 trigonometrically extrapolated where the mouse would end up if it followed the predicted turn angle, and computed 23 initial escape direction as above. The data that support the findings of this study are available from the corresponding 24 authors upon request.