Introduction

Decision-making is frequently defined as the selection of a course of action among several alternatives. The ubiquity and importance of decision-making has led to its use in describing a broad range of behaviors from taxes of unicellular organisms to economics and politics in human society [1, 2]. In decision neuroscience, laboratory experiments have investigated the behavioral choices of animals in well-controlled environments or tasks [3]. While these experiments have led to key insights into mechanisms underlying decision-making and related cognitive processes [4], a comprehensive understanding of decision-making remains elusive. Many researchers have advocated for a more neuroethological approach – suggesting that experiments designed to understand problems the brain evolved to solve offer a more rigorous framework [3, 5, 6]. Thus, one approach to enrich our understanding of decision-making is to look at the decisions made by animals foraging in naturalistic environments.

Foraging animals make a hierarchy of decisions to locate food (food search), choose between different food types (diet or patch choice), and allocate time spent within patches of food items (patch-leaving) [5, 7-10]. These foraging decisions often require that an animal exploit an environment for known resources or explore it for potentially better opportunities elsewhere [9, 11]. This exploration-exploitation trade-off requires cognitive computations such as learning the spatiotemporal distribution of food, route planning, estimation of food availability, and decision-making [12, 13]. According to optimal foraging theory, foragers may seek to maximize their rate of net energy gained over time [8, 9, 14] by using internal and external information to guide decision-making, especially in environments where resources are sparsely distributed or fluctuating. Although many studies have provided insight into the motivations, behavioral implementations, and genes associated with foraging decisions [9, 10], a more rigorous framework for exploring the neuronal mechanisms underlying foraging decisions is essential to establish a comprehensive understanding of decision-making.

The microscopic nematode Caenorhabditis elegans is well suited for investigating the cellular and molecular basis of foraging decisions [15]. A myriad of genetic tools, behavioral assays, and neuronal imaging techniques have been developed to take advantage of the species’ quick reproductive cycle, isogeneity, optical transparency, and ease of maintenance [16-18]. While C. elegans typically feed upon a diversity of bacterial types in the wild [19], they are commonly maintained in the laboratory on agar plates containing large patches of the bacteria Escherichia coli as a food source [16]. However, even in these simplified laboratory conditions and despite having a numerically simple nervous system of only 302 neurons [16, 20], C. elegans display complex and robust species-typical behaviors [21] involving learning and memory [22-25], and decision-making [26-31]. Recent studies have demonstrated that ecologically focused environmental enrichment permits identification of novel behaviors and gene functions in C. elegans and other animals [32-35].

Foraging animals often must make one of two types of decisions: stay-switch or accept-reject. Stay-switch decisions refer to scenarios where an individual experiences diminishing returns with the current action and must decide when to switch to a new action (e.g., patch-leaving and area-restricted search) [5, 7-10]. In contrast, accept-reject decisions refer to situations where an individual must decide between engaging with an option or ignoring it in search of a better one (e.g., diet or patch choice) [5, 8, 9]. Stay-switch decisions have been well described in C. elegans [25, 26, 36-41] and enable them to successfully explore an environment and exploit the bacteria within [28, 42-44]. However, to our knowledge, accept-reject decisions have not yet been demonstrated in C. elegans. While C. elegans have been shown to alter food preferences in a diet choice assay, this behavior has only been described by a set of stay-switch decisions [31, 36, 44]. The ability to make accept-reject decisions is likely advantageous for foraging in fluctuating or variable environments as rejecting an encountered food item of low quality creates the opportunity for a subsequent encounter with preferred food. Thus, while C. elegans can successfully forage in patchily distributed environments, it is not known whether C. elegans make decisions to exploit a patch of food upon encounter and how this decision-making process changes over a series of patch encounters.

In this study, we aimed to identify if C. elegans make accept-reject decisions upon encounter with bacterial patches. To answer this question, we performed a detailed analysis of the behavior of individual animals foraging in an ecologically relevant environment where bacterial patches were dilute and dispersed. In conditions where the bacterial density was much lower than that of previously visited patches, animals first explored the environment before accepting patches for exploitation. This explore-then-exploit strategy persists even when only one bacterial patch is present in the environment. Using a theoretical framework, we found that this initial exploration reflects a series of accept-reject decisions guided by signals related to the bacterial density of current and recently explored and exploited patches as well as the animal’s state of satiety.

Results

C. elegans forage in patchy environments with an explore-then-exploit strategy

To investigate whether C. elegans make accept-reject decisions upon encounter with bacterial patches, we observed the behavior of animals foraging on an agar surface containing an isometric grid of small, low density bacterial patches (Figure 1A, Video 1-2). Animals were confined to an arena where their behavior was recorded and tracked for 60 minutes (Figure 1A – supplement 1, Video 3). During this time, animals were observed to move about the arena (Figure 1A-C, Figure 1 – supplement 2, Video 4) with each animal encountering, on average, ∼8.4 total patches and ∼5.3 unique patches during the one-hour recording (Figure 1D). These patch encounters ranged in duration from seconds to tens of minutes and could be classified as either short or long (2+ minutes) using a Gaussian mixture model (Figure 1E, Figure 1 – supplement 3). Notably, animals were significantly more likely to stay on patch for longer durations at later time points (Figure 1F) which corresponded to an overall increase in their probability of residing on patch (Figure 1G, Figure 1 – supplement 4). Specifically, we found that while animals initially resided on bacterial patches at levels close to those predicted by chance, an animal’s probability of residing on a bacterial patch increased significantly after ∼10 minutes. These findings, that patch duration and residence increased over time, suggest that animals are more likely to exploit an encountered patch as time goes on.

C. elegans forage in a patchy environment with an explore-then-exploit strategy.

(A) An example animal’s midbody location (colored to represent time in the experiment) as it forages in an environment bounded by a large (30 mm diameter) arena containing 19 small (∼1.8 mm diameter) bacterial patches (gray). Each patch was made by pipetting ∼0.5 µL of OP50 E. coli diluted to OD600 ∼10 and grown at room temperature for ∼1 hour. (B) Distance between the example animal’s midbody position and the nearest patch edge (positive indicates inside patch) is plotted (black) for every time point. Putative encounters with a bacterial patch are indicated (gray). (C) Patch encounters (colored to represent the duration of the encounter) for 50 individuals foraging in these environments are plotted. (D) The number of total and unique patch encounters for each animal are shown. (E) Duration for each patch encounter was computed and classified as either short (0-2 minutes) or long (2-60 minutes) using a Gaussian mixture model. The distributions of all observed short and long encounters are plotted with duration binned logarithmically. (F) The observed start time of each patch encounter is shown for all short and long duration encounters. Long duration encounters occur significantly later (one-tailed Mann-Whitney U-Test). (G) The probability of residing on patch was computed for all worms across time (black) and compared to the probability of residing on patch if patch locations were semi-randomly permuted (pink). Smoothed median values are plotted with bootstrap-derived 2.5% and 97.5% quantiles shown in shaded regions. Time points where observed probabilities of residing on patch significantly exceed permuted probabilities are indicated by a black line (one-tailed Fisher’s exact test with Benjamini-Hochberg correction). (H) The track of the example animal in (A) is replotted with color used to represent the animal’s instantaneous velocity at each time point. (I) Velocity of the example animal over time is plotted (black) alongside patch encounters (gray) as previously identified in (B). Example encounters – one early, short duration (green) and one late, long duration (blue) – are indicated. (J,K) A 60-second time window surrounding the start of these example encounters is enlarged. (L) Velocity trajectories were aligned to patch entry for every encounter. Mean encounter-aligned (black/gray) and randomly-aligned (pink) trajectories are plotted for each animal (light) and across all animals (dark). (M) Deceleration upon encounter with the patch edge is plotted for every encounter and grouped by duration type. Deceleration was significantly lower for encounter-aligned as compared to randomly-aligned trajectories (pink) for all duration types (one-tailed Mann-Whitney U-Tests with Bonferroni Correction). (N) Mean velocity as a function of the distance from the edge of bacterial patches (computed for 50 μm bins) is shown for every animal (gray) and across all animals (black). (O) Each animal’s mean velocity during time spent on and off (midpoint at least -0.46 mm from patch edge) patch is shown. Velocity on patch was significantly slower than off patch (one-tailed paired-sample t-test). Sample data for one animal (worm #1) are shown in (A-C,H-K). Summary data for all animals (N = 50 worms) and encounters (N = 419 total encounters) are shown in (D-G,L-O). Violin plots in (D,F,M,O) give the KDE and quartiles for each measure. Asterisks denote statistical significance (***p<0.001). See also Figure 1 – supplement 1-5 and Video 1-4.

Given that the bacterial density of the experimental patches was approximately 20 times more dilute than that of conditions animals experienced during development and immediately preceding the assay, it was possible that the initial delay in exploitation could be due to animals’ inability to detect the presence of bacteria in these more dilute patches. We therefore set out to determine if animals detected patches at all time points. Previous studies have shown that C. elegans display an immediate and marked slowdown upon encounter with the edge of a food patch and sustain these slower speeds on food [28, 45]. Therefore, velocity can be used as a proxy for an animal’s ability to sense a bacterial patch. Following this precedent, we quantified the instantaneous velocity of individuals in our assay (Figure 1H). We observed significant deceleration of an animal’s instantaneous velocity upon encounter with the patch edge (Figure 1I), with no obvious difference between short duration, early time point (Figure 1J) and long duration, late time point (Figure 1K) encounters. Animals consistently displayed marked slowdown when approaching the patch edge (Figure 1L), achieving an average deceleration of -19.5 μm/s2 upon encounter with the bacterial patch (Figure 1M, Figure 1 – supplement 5). This slowdown was statistically significant for both long and short duration encounters (Figure 1M). Further, consistent with C. elegans behavior on larger and more densely seeded patches in other studies [46], animals in our assay maintained significantly lower average velocities on patch (∼52 μm/s) compared to off patch (∼198 μm/s) (Figure 1N,O). These results suggest that, despite detecting the availability of food during early patch encounters, C. elegans opt to initially prioritize exploration of the environment before switching to a more exploitatory foraging strategy during subsequent patch encounters.

The timing of the switch from exploration to exploitation varies with bacterial density

To determine whether this explore-then-exploit foraging strategy is dependent upon food-related characteristics of the environment, we varied the density of the bacterial patches. By diluting bacterial stocks and controlling growth time, we created 12 bacterial density conditions with relative density ranging from 0 to ∼200 (Figure 2A, Figure 2 – supplement 1-3). At the low end of this range (densities less than ∼0.5), animals do not appear to detect bacterial patches as indicated by on-patch velocities matching those of animals foraging on bacteria-free (density 0) patches (Figure 2B,C). At the high end of the range (density ∼200), bacterial density is comparable to the environments animals experienced during development and immediately prior to the assay (Figure 2 – supplement 2-3).

The timing of the switch from explore-to-exploit is density-dependent.

(A) The relative density (as estimated by fluorescently-labeled OP50-GFP) is shown for small (∼1.8 mm diameter) bacterial patches made by pipetting ∼0.5 µL droplets of OP50 E. coli diluted in LB to a range of optical densities (OD600 = {0, 0.05, 0.1, 0.5, 1, 2, 3, 4, 5, 10} and controlling growth time at room temperature (hours = {1, 12, 48}). For (A-G,L-O), gray-scale color saturation is proportional to the relative density of each condition and corresponds to labels in (A). (B) The mean velocities of animals foraging in environments containing patches matching one of the 12 bacterial densities are plotted as a function of the distance from the edge of bacterial patches (computed for 50 μm bins). (C) Animals’ average on-patch velocity is plotted as a function of the relative density of bacteria. Compared to animals foraging amongst bacteria-free patches containing only LB (relative density 0), animals foraging on bacterial patches with relative density of 0.5 or greater display significantly slower on-patch velocities (one-tailed Mann-Whitney U-Tests with Bonferroni Correction). (D) The midbody location (colored to represent time in the experiment) of example animals foraging in environments containing patches (gray) of relative density 0, 1, 5, 10, and 200 are shown. (E) The total time each animal spent on patch is plotted as a function of the relative density of bacteria. Time on patch increased monotonically with increasing bacterial density (Kendall’s τ correlation, p<0.001) following a sigmoidal trend. (F) Smoothed median values of the probability of worms residing on patch over time for each density condition are plotted. Time points where observed probabilities of residing on patch either match (pink) or significantly exceed (gray) the probability of residing on patch if patch locations were semi-randomly permuted are indicated (one-tailed Fisher’s exact test with Benjamini-Hochberg correction). (G) A KDE of the distribution of encounter durations is plotted for each density condition. (H) For each encounter, the average velocity of the animal during the encounter and the duration of that encounter are plotted on a double-logarithmic plot with color representing the probabilities of clustering classification as search (orange), sample (green), or exploit (blue). Contours showing the first, second, and third standard deviation of the GMM used to classify explore and exploit encounters are shown as shaded ellipses with saturation corresponding to standard deviation. KDEs for distributions of average on-patch velocity and encounter duration are plotted for each encounter type. (I) For each encounter, the minimum on-patch velocity and maximum change in velocity are plotted. Contours showing the separation of sensing and non-sensing encounters as estimated by semi-supervised QDA are indicated. A KDE for the distribution of the maximum change in velocity is plotted for each encounter type. (J) Features used to classify encounters as search, sample, or exploit are summarized. (K) KDEs of the distributions of animals’ velocities are shown for all timepoints during search off and on patch as well as during sample and exploit encounters. (L) Ethograms of patch encounters (colored to represent the probability of classification as search, sample, and exploit) are shown for 443 individuals. (M) The average proportion of each encounter type over time is plotted. (N) Time elapsed and (O) number of encounters occurring prior to the first exploitation event are plotted for every animal (blue). In the event that no exploitation event occurred, the maximum observed time and encounters are plotted (red-orange). Both time and encounter number before exploitation decrease monotonically with increasing patch density (Kendall’s τ correlation, p<0.001) following a sigmoidal trend. Summary data for all animals (N = 443 total worms; N = 20-50 worms per condition) and encounters (N = 6,560 total encounters; N = 46-876 encounters per condition) are shown in (A-C,E-I,K-O). Asterisks denote statistical significance (***p<0.001). See also Figure 2 – supplement 1-7 and Video 5-6.

Previous studies have shown that in diet choice assays where animals are given the option between patches of varying quality or density, animals spend more time on preferred patches [31, 36, 44]. We hypothesized that even when all patches in the environment are of equal density, an efficient forager should still modulate the amount of time spent on the bacterial patches in a density-dependent manner. To test this, behavior was recorded and tracked for one hour as animals foraged in patchy environments matching one of the bacterial density conditions (Figure 2D, Figure 2 – supplement 4). Consistent with our hypothesis, we found that the total time animals spent on bacterial patches increased monotonically with increasing bacterial density following a sigmoidal trend (Figure 2E). Further, the probability of an animal residing on patch as a function of time was highly dependent on the bacterial density (Figure 2F, Figure 2 – supplement 5). At the highest densities (50 and 200), animals spent nearly 100% of time in the assay on bacterial patches, while at the lowest densities (0 to 0.3), animals spent chance levels of time on patch for the duration of the experiment. At intermediate densities (0.5 to 10) animals initially resided on patches at rates predicted by chance, later transitioning to more time spent on patch. Notably, this delayed increase in patch residence is density dependent with animals switching earlier in environments with patches of greater density.

Consistent with our previous observation that animals reside on patches for either short or long durations (Figure 1E), we observed two distinct patch encounter types: 1) short (less than 2 minute) patch visits and 2) long (often tens of minutes) patch visits (Figure 2G). Using a two-component Gaussian mixture model (GMM), we classified all encounters based on the duration of these patch visits and animals’ average velocity during the encounter (Figure 2H, Figure 2 – supplement 6). We identified two behaviorally distinct clusters: 1) short duration and fast velocity (explore), and 2) long duration and slow velocity (exploit) encounters. The explore encounters suggest that an animal has rejected a patch, opting to continue exploration of the environment. In contrast, the exploit encounters suggest that an animal has accepted a patch and is consuming the bacteria within.

While we previously found that animals consistently slowed down upon encounter with the patch edge when foraging in relative density ∼10 (Figure 1J-M), we observed that a large portion of short duration, exploratory encounters were not accompanied by this slow down (Figure 2 – supplement 7A-B), especially for the lowest bacterial densities tested. Therefore, to determine which exploratory encounters displayed evidence that the patch was detected by the animal, we further classified encounters by an animal’s minimum velocity on patch, deceleration upon patch entry, and maximum change in the animal’s velocity upon encounter (i.e., the difference between the peak velocity immediately before the patch encounter and the minimum velocity achieved during the patch encounter) (Figure 2I, Figure 2 – supplement 7, Video 5). We again observed two behaviorally distinct clusters: 1) large slow-down and slow on-patch velocity, and 2) small slow-down and fast on-patch velocity. We classified these encounters as sensing and non-sensing, respectively, using a semi-supervised quadratic discriminant analysis (QDA) approach. The presence of a slow-down and the subsequent continuation of slower on-patch velocity suggest that an animal sensed the bacteria, while the absence of a slowdown suggests that the animal likely did not perceive the encounter. For simplicity, we refer to 1) non-sensing encounters as searching (i.e., on-patch behavior that matches off-patch behavior where an animal appears to be searching for food); 2) sensing, short duration encounters as sampling (i.e., evaluating a patch’s suitability as a food source, but ultimately rejecting the patch and continuing to explore the environment); and 3) sensing, long duration encounters as exploiting (i.e., accepting a patch and consuming its bacteria) (Figure 2J). Consistent with our interpretation of searching encounters, the average velocities that animals achieved during search on (∼200 μm/s) and off (∼207 μm/s) patch were similar, especially when compared to markedly slower on-patch velocities during sample (∼114 μm/s) and exploit (∼57 μm/s) encounters (Figure 2K). In summary, we have identified three distinct patch encounter types: encounters that were not detected (search) and encounters that were detected with the animal subsequently deciding to reject (sample) or accept (exploit) the patch.

We next characterized how the frequency of encounter types varied as a function of time and patch density. The behavior of 443 animals (20-50 worms per condition) was tracked and classified at each time point (Figure 2L, Video 6). In low density conditions (0 to 0.3), animals spent nearly all of their time searching on or off patch. With increasing bacterial patch density, animals spent less time searching and more time sampling and exploiting. Animals foraging in medium density patches (0.5 to 10) initially spent most of their time sampling patches upon encounter. However, animals eventually switched to mostly exploiting patches. Animals foraging on high density patches (50 and 200) almost exclusively exploited. Classification of on-patch behavior across all densities tested revealed a consistent switch from exploratory behaviors (searching and sampling) to exploitation (Figure 2M) with the timing of the switch occurring earlier for animals foraging in environments with higher bacterial patch density (Figure 2N). The delay in exploitation corresponded to a comparatively large number of initial exploratory encounters with animals on medium density conditions (0.5 to 10) exploiting after an average of 4.8 to 18.7 exploratory encounters (Figure 2O). To summarize, for densities similar to those experienced immediately preceding the experiment (50 and 200), animals immediately exploit available bacteria. On the other hand, for bacterial densities that appear to be below an animal’s sensory threshold (0 to 0.3), animals never exploit patches and spend the entire 60-minute assay searching for food. When foraging in medium density patches (0.5 to 10), animals initially explore the environment via a combination of searching and sampling encounters and eventually switch to exploiting. Notably, the timing of this switch is density-dependent with animals switching earlier when foraging on higher density patches.

Animals explore before exploiting even when only one patch is available

Given that bacterial patches within an environment were relatively invariable and that bacterial growth during the experiment was negligible (Figure 2 – supplement 3), it was surprising that animals were often willing to reject 10+ patches before exploiting a patch of the same density as those previously rejected (Figure 2O). This sampling behavior may be beneficial when food is patchily distributed in the environment as exploiting a dilute patch may result in a lost opportunity for future encounter with a higher quality patch. Thus, we hypothesized that an animal’s willingness to accept a patch whose density matched that of a previously rejected patch could be a specific feature of a patchily distributed environment where numerous observations of individual patches could contribute to learning the features of a changing environment. To address this, we observed whether animals were willing to reject a patch numerous times before accepting it even when only one patch is available in the environment. We created environments with single large (∼8.3 mm) or small (∼1.8 mm) diameter patches with relative density ranging from 0 to ∼400 (Figure 3A-C). Behavior was tracked for 60 minutes as animals foraged in these environments (Figure 3D-E, Figure 3 – supplement 1-2). We found that even in these single patch environments, animals initially explore (search and sample) before exploiting (Figure 3F-G) in a density-dependent manner. Just as when foraging in a patchily distributed environment (Figure 2N), animals explored (search and sample) the small and large single patches numerous times prior to exploiting with the timing of this switch occurring significantly earlier with increasing bacterial density (Figure 3H-I). These results suggest that the explore-then-exploit strategy employed by C. elegans is not specific to a patchily distributed environment. Rather, animals may sample the same patch numerous times before deciding to exploit, especially when foraging on dilute patches. The decision of when to stop exploring and start exploiting is highly dependent upon the density of bacteria within a patch with the switch occurring earlier when animals encounter patches of higher density.

C. elegans explore first even when only one patch is available.

(A) Relative density of large (∼8.3 mm diameter) and (B) small (∼1.8 mm diameter) bacterial patches was varied by pipetting 20 µL and 0.5 µL, respectively, droplets of OP50 E. coli diluted in LB to a range of optical densities (OD600 = {0, 0.05, 0.1, 0.5, 1, 2, 3, 4, 5, 10} and controlling growth time at room temperature (hours = {1, 48}). (C) Large patches were formed in the center of 30 mm arenas while small patches were formed in the center of 9 mm arenas. (D-E) The midbody location (colored to represent time in the experiment) of example animals foraging in environments containing a single (D) large or (E) small patch (gray) are shown. (F-G) Ethograms of patch encounters (colored to represent the probability of classification as search, sample, and exploit) for (F) 144 individuals (8-15 per condition) foraging on a single large patch and (G) 191 individuals (27-38 per condition) foraging on a single small patch are shown. (H-I) Time elapsed prior to the first exploitation event (blue) for animals foraging on (H) large and (I) small patches is plotted for every animal. When exploitation was not observed, time elapsed in the experiment is plotted (red-orange). Animals in large and small patch environments exploited higher density patches significantly earlier (Kendall’s τ correlation, p < 0.001) following a sigmoidal trend. See also Figure 3 – supplement 1-2.

External and internal sensory information guide the decision to explore or exploit

While our behavioral analysis demonstrated that C. elegans modulate their decision to explore or exploit in a density-dependent manner, it remains unclear whether these animals use more complex cognitive processes such as learning and memory to guide their foraging decision. It is plausible that animals are making decisions using simple heuristics given only available sensory information about the current patch. However, previous studies have shown that food-related behaviors in C. elegans can be driven by internal states [31] as well as memories of the environment [25, 36, 42]. Thus, to better understand the factors driving the exploitation decision, we implemented a generalized linear model (GLM) to test how foraging decisions are influenced by the density of the current patch as well as additional food-related factors such as an animal’s level of satiety and prior experience (Figure 4A).

Exploitation decisions are driven by available sensory information, satiety, and prior experience.

(A) Schematic of the covariates xk used in our logistic regression model to predict the probability of exploiting a patch upon any given encounter p(yk = 1|β · xk). xk includes the relative density of the encountered patch k (ρk), the duration of time spent off food since departing the last exploited patch (τs), the relative density of the patch encountered immediately before encounter k (ρh), and the relative density of the last exploited patch (ρe). (B) To account for uncertainty in our classification of sensation, we produced 100 sets of observations wherein we probabilistically included sensed encounters (νk = 1) estimated from the distribution νk|wk ∼ Bern(p(νk = 1|wk)) where p(νk = 1|wk) is the probability that the patch was sensed as estimated in Figure 2I. To account for uncertainty in our classification of exploitation, we substitute the response variable yk with our estimate of the probability that the patch was exploited p(yk = 1|zk) as estimated in Figure 2H, a procedure analogous to including exploitations (yk = 1) estimated from the distribution yk|zk ∼ Bern(p(yk = 1|zk)). A schematic of these procedures is shown (see Models of exploitation probability). (C) Coefficient values for each covariate in the GLM were estimated across 50000 replicates (500 replicates of hierarchically bootstrapped animals in combination with 100 sets of probabilistically sensed encounters). All coefficients are significantly greater than or less than 0 (two-tailed, one-sample bootstrap hypothesis tests with Bonferroni correction). (D) Using observed p(yk = 1|zk) and estimated p(yk = 1|β · xk) probabilities of exploitation, exploitation events were simulated from a Bernoulli distribution. Distributions of the probability of first exploiting as a function of the number of encounters as estimated by the model with covariates added one-by-one and as observed are shown for animals foraging in single-density, multi-patch environments of relative density 1 or 10. (E) A schematic of multi-density, multi-patch assays where animals foraged in environments containing small (∼1.8 mm diameter) bacterial patches (gray) of varying combinations of OP50 E. coli with relative densities 1, 4, and 7 is shown. (F) The probability of exploitation as estimated with (p(yk = 1|β0 + βkρk + βsτs + βhρh + βeρe)) and without (p(yk = 1|β0 + βkρk + βsτs)) the history-dependent terms and as observed p(yk = 1|zk) is shown for every pairing of current patch density (ρk) combined with the density of recently encountered (ρh) or exploited (ρe) patches. Heat maps for observed values were interpolated between the 9 patch density pairings tested. (G) Exploitation events were simulated from the distribution yk|zk ∼ Bern(p(yk = 1|zk)) and used to calculate the probability of observing exploitation for the first time as a function of the number of encounters for N2, mec-4, and osm-6 animals foraging in single-density, multi-patch environments of relative density 1 or 10. (H) Coefficient values for each covariate were estimated using ridge regression models for each strain across 50000 replicates. A subset of these coefficients significantly varied between wild-type and mutant strains (mean of differences tests with Benjamini-Hochberg correction). Summary data for all animals (N = 443 total worms; N = 20-50 worms per condition) and encounters (μ = 2659.8, σ = 15.9) in the single-density, multi-patch assay are shown in (C,D). Summary data for all animals (N = 198 total worms; N = 20-40 worms per condition) and sensed encounters (μ = 1,724.6, σ = 9.9) in the multi-density, multi-patch assay are shown in (F). Summary data for all wild-type and mutant animals (N = 221 total worms; N = 14-44 worms per condition) and encounters (N = 1,352 total encounters) in a single-density, multi-patch assay are shown in (G,H). Violin plots in (C,H) show the KDE and quartiles for each measure. Asterisks denote statistical significance († punadjusted<0.05; *p<0.05; **p<0.01; ***p<0.001). See also Figure 4 – supplement 1-5.

We considered that the probability of exploiting a patch upon any given encounter can be described by a logistic function:

where p(yk = 1|β · xk) represents the conditional probability that an animal exploited during patch encounter k; xkRn is a vector of covariates; and βRn is a vector of weights that describes how much each covariate influences the animal’s choice. In models compared here, xk includes a combination of a constant element and covariates that may empirically influence the decision to exploit. We considered the simplest model where every encounter is independent with fixed probability of exploiting (i.e., p(yk = 1|β0)) where β0 represents the average animal’s propensity to exploit. We compared this null model against a set of nested models containing covariates that vary from encounter to encounter and relate to: 1) the relative density of the encountered patch k (ρk), 2) the duration of time spent off food since departing the last exploited patch (τs), 3) the relative density of the patch encountered immediately before encounter k (ρh), and 4) the relative density of the last exploited patch (ρe). Using this model design (i.e., β · xk = β0 + βkρk + βsτs + βhρh + βeρe), we assessed how each of these covariates influences the probability of exploitation at each patch encounter k (Figure 4A).

Given that our aim is to understand what factors influence an animal’s decision to explore or exploit, we rationalized that encounters where the animal did not detect the presence of bacteria were unlikely to contribute to decision-making. Therefore, we excluded searching encounters from our analysis where the bacterial patch was not sensed. To account for the uncertainty in our classification of sensing, we probabilistically included patch encounters with frequency equal to the probability that the bacterial patch was sensed (Figure 4B) as previously estimated by semi-supervised QDA (Figure 2I, Figure 2 – supplement 7). In doing so, we simulated sets of observations of sensed (sample and exploit) encounters. Further, to account for the uncertainty in our classification of patch encounters as exploration or exploitation, we fit our GLM to the probability of exploiting p(yk = 1|zk) as previously estimated by GMM (Figure 2H, Figure 2 – supplement 6) rather than fitting to direct observations of exploitation yk (see Models of exploitation probability).

When selecting covariates for our model, we calculated the Bayesian information criterion (BIC) – a model selection test to avoid overfitting by penalizing increases in the number of parameters – and observed improved model performance upon addition of each covariate (Figure 4 – supplement 1A). Further, we found that all covariates (i.e., ρk, τs, ρh, and ρe) significantly contribute to the decision to exploit p(yk = 1|β · xk) as indicated by coefficient values significantly greater than or less than zero (Figure 4C, Figure 4 – supplement 1B). Specifically, we found that βk and βs are significantly greater than zero which suggests that animals are more likely to exploit patches with increasing patch density ρk and duration of food-deprivation τs. On the other hand, βh and βe are significantly negative, which suggests that the greater the density of a recently encountered or exploited patch, ρh and ρe, the less likely an animal should be willing to exploit the current patch.

In order to better understand how each of the covariates in our model affect the exploitation decision, we examined the probability of observing exploitation for the first time as a function of the cumulative number of patches an animal encountered. Exploitation events were simulated from a Bernoulli distribution with probability estimated by the model (i.e., yk|xk ∼ Bern(p(yk = 1|β · xk))) or observed from our classification of exploitation (i.e., yk|zk ∼ Bern(p(yk = 1|zk))). Although the probability of exploiting for the first time was not expressly fit by our model, this derived metric highlights the model’s ability to predict the delay in exploitation observed for animals foraging on low to medium density bacterial patches in our experiments (Figure 4D, Figure 4 – supplement 2). For the simplest model where every encounter is independent with fixed probability of exploiting p(yk = 1|β0), we find that the probability of exploiting for the first time is greatest for the first encounter and decreases for every subsequent encounter (Figure 4D, Figure 4 – supplement 2), fitting a geometric distribution.

We next considered whether the observed delay in exploitation could be explained by a simple density-dependent model (i.e., p(yk = 1|β0 + βkρk)). This model predicts that animals are more likely to exploit bacterial patches of greater density with probability proportional to the relative density of the current patch ρk. While this density-dependent model accurately predicted that the first exploitation occurs earlier on average for higher density patches, it also predicted that, regardless of patch density, the first exploitation is most frequently observed on the first encounter which did not match the observed distribution (Figure 4D, Figure 4 – supplement 2). We subsequently considered that the onset of food-deprivation during exploration of these low-density environments could drive the observed time-dependent delay in exploitation. We assume that animals become satiated during exploitation and use the duration of time an animal spent searching off-food since the last exploitation event (i.e., τs) as a proxy for the animal’s likely decrease in satiety. With the addition of this satiety-related signal (i.e., p(yk = 1|β0 + βkρk + βsτs)), we observed a slight delay in when animals are predicted to first exploit for the lowest density conditions tested (Figure 4D, Figure 4 – supplement 2). To validate our finding that animals use a satiety-related signal to inform decision making, we applied our model to observations of animals foraging in patchily distributed environments following 3 hours of food-deprivation (Figure 4 – supplement 3A-B). We found that only with the inclusion of a satiety-related covariate in our model, were we able to reliably predict the immediate exploitation that food-deprived animals exhibit (Figure 4 – supplement 3C). Altogether, these results suggest that animals use available external and internal sensory information to guide the decision to exploit.

Prior experience guides the decision to explore or exploit

Although the current patch density and satiety covariates significantly influence the decision to exploit, this model (i.e., p(yk = 1|β0 + βkρk + βsτs)) does not accurately predict the extent that exploitation was delayed. We hypothesized that because animals had experienced very densely seeded bacterial patches immediately prior to the assay, animals may have built an expectation that high density bacterial patches are available in the new environment. We would therefore expect an initial suppression in the probability of exploiting while animals updated their expectation using information learned from sampling patches in the current environment. To test whether the decision to exploit could be influenced by prior experience, we added a history-dependent covariate to our model (i.e., p(yk = 1|β0 + βkρk + βsτs + βhρh) where ρh is the relative density of the patch encountered immediately before encounter k). We find that inclusion of the density of the most recently encountered patch significantly improves our prediction of exploitation (Figure 4D, Figure 4 – supplement 2). We then considered whether the animal’s expectation of bacterial density in the environment might be a longer lasting memory. Specifically, we considered if the relative density of the most recently exploited patch ρe could have influenced the animal’s decision to exploit. The addition of this second history-dependent term to our model (i.e., p(yk = 1|β0 + βkρk + βsτs + βhρh + βeρe)) further improved the fit of our model (Figure 4D, Figure 4 – supplement 2) suggesting that C. elegans use recent experiences of encountered and exploited patches to guide their decision to exploit. Animals may use this learned information to create and update an expectation for the relative density of bacterial patches available in their environment and compare that estimate against the density of a subsequently encountered patch. Altogether, these results suggest that animals use prior experience to keep track of available resources and modulate their decision to explore or exploit, a strategy that is highly beneficial for behavioral adaptation in a changing environment.

To validate the role of prior experience in guiding foraging decisions, we observed animals foraging in environments with multiple patch densities (Figure 4E, Figure 4 – supplement 4A-C). Our model predicts that the lower the density of recently encountered and/or exploited patches, the more likely an animal should be to exploit a subsequent patch. Without the history-dependent terms ρh and ρe, our model predicts that no relationship should exist between prior experience and the probability of exploiting the current patch. To test which model best fit the animals’ behavior, we calculated the conditional probabilities of exploiting p(yk = 1|β · xk) for this new multi-density, multi-patch data set with more nuanced combinations of current (ρk) and recent patch (ρh and ρe) density using the coefficients β learned previously (Figure 4C, Figure 4 – supplement 4D). We observed significantly better predictions of exploitation probability for the model including prior experience as compared to the model without the terms ρh and ρe (Figure 4F) as confirmed by a likelihood-ratio test. We observed an augmentation in exploitation when animals move from low to high density (e.g., 1 to 4 or 1 to 7) as predicted by the model with history-dependence, but not the model without. It is important to note, that this improvement in prediction was achieved without fitting the model to this new multi-density data set. In summary, our modeling results suggest that animals evaluate bacterial density, monitor internal signals of satiety, and leverage prior experience to drive their decision to exploit a bacterial patch upon encounter.

Chemosensation is required for the evaluation of patch density

The quantitative modeling applied in this study provides a useful framework for testing the influence of behaviorally relevant features on decision-making. To validate this approach and further elucidate how animals evaluate current and recent patch density, we assessed the foraging behavior of mutants deficient in a sensory modality (Figure 4 – supplement 5). We found that animals with reduced function of non-ciliated mechanoreceptor neurons due to a null mutation in the mec-4 gene behave similarly to wild-type N2 animals, displaying increasingly delayed exploitation as patch density decreases (Figure 4G, Figure 4 – supplement 5). Contrastingly, animals with reduced function of ciliated chemoreceptor neurons due to a null mutation in the osm-6 gene displayed immediate exploitation even while foraging on low density patches (Figure 4G, Figure 4 – supplement 5). These results indicate altered decision-making in the chemosensory mutants. Specifically, it appears that the influence of patch density on the exploitation decision is reduced in osm-6 mutants and that these animals are more likely to accept a patch by default.

To further elaborate on these findings, we fit our GLM to each of the three data sets (i.e., N2, mec-4, osm-6) and assessed the difference in the estimated distributions of coefficients β between mutant and wild-type models (Figure 4H). We hypothesized that the density-related covariates (ρk, ρh, and ρe) would have smaller magnitude (i.e., less influence on decision-making) for animals with reduced sensation of bacterial density. Consistent with this hypothesis, we found a significant reduction in the magnitude of the influence of current patch density (i.e., βk) on the decision to exploit in osm-6 mutants. Further, we found a significant increase in the intercept β0 in osm-6 mutants which corresponds to the overall increase in exploitation observed in these animals (Figure 4G, Figure 4 – supplement 5). These results suggest that chemosensation plays an important role in evaluating the density of the current patch and that when this sensory modality is impaired, animals modify their default behavioral strategy to prioritize exploitation. We also observed a marginal increase in our estimate of the influence of recently exploited patches (i.e., βe) in osm-6 mutants which suggests that reduced efficacy in the evaluation of current patch density also affects learning and memory of patch density. No significant changes were detected in the mec-4 mutants. Although we cannot rule out a role for mechanosensation in contributing to the assessment of patch density, this modality likely provides less salient information than chemosensation. Altogether, these results suggest that chemosensation is necessary for the evaluation of patch density and that when this modality is impaired, animals prioritize exploitation. Further, these results demonstrate that this quantitative modeling approach can be used to probe mechanisms underlying decision-making.

Discussion

Like all foraging animals, C. elegans must choose between exploiting an environment for known resources and exploring it for potentially better opportunities elsewhere [5, 7-11]. Previous studies have shown that C. elegans use stay-switch decisions to efficiently explore a patchily distributed environment and exploit the bacteria within [28, 42-44]. In this study, we show that C. elegans also make accept-reject decisions while foraging. Specifically, we observe that animals often initially reject low density bacterial patches, opting to prioritize exploration of the environment, before switching to a more exploitatory foraging strategy during subsequent encounters. This explore-then-exploit strategy was consistent across a range of bacterial patch densities, sizes, and distributions. In order to better understand this phenomenon and identify the factors that contribute to the decision to exploit, we leveraged a quantitative modeling approach to hypothesis testing. We found that animals do not employ a default explore-then-exploit strategy; rather, this behavior reflects a series of accept-reject decisions guided by multimodal information related to an animal’s environment and internal state. Specifically, we show that each decision to explore or exploit is informed by available sensory information, internal satiety signals, and learned environmental statistics related to the bacterial density of recently encountered and exploited patches.

C. elegans make accept-reject foraging decisions

While C. elegans have been shown to alter food preferences in a diet choice assay, this behavior has only been described by a set of stay-switch decisions [31, 36, 44]. Specifically, C. elegans were found to modulate their patch-leaving frequency to stay on high quality bacterial patches and switch with declining food quality and quantity [26, 36, 40, 41]. The overall effect of leaving low quality patches more frequently is that animals are more likely to reside on high quality patches. Thus, stay-switch decision-making enables C. elegans to efficiently allocate time spent between exploring or exploiting in a manner consistent with optimal foraging theory [5, 7-11]. However, optimal foraging theory also predicts that an animal should never exploit (i.e., always reject) a low density patch if higher density patches are sufficiently abundant as inclusion of the low density patch type in the animals’ diet decreases the overall rate of energy gained [5, 9]. Thus, while leaving low density patches more frequently drives an overall increase in the rate of energy gained, it can still result in sub-optimal foraging behavior.

Here, we demonstrate that C. elegans are capable of making accept-reject decisions upon encounter with bacterial patches. We employed unbiased and quantitative methods – GMM and semi-supervised QDA – to estimate whether animals sensed a patch and, if they did, whether they accepted or rejected it. We found that animals initially rejected low density patches, opting to continue exploration of the environment, and that this reject decision did not reflect an animal’s inability to detect the presence of bacteria in these dilute patches. Further, we found that the decision to explore or exploit is density-dependent and robust across a range of bacterial densities, distributions, and sizes. The initial preference for exploration during foraging on low density patches suggests that animals may be searching for denser bacterial patches such as those experienced immediately preceding the assay and throughout development. This explore-then-exploit strategy is advantageous for animals when bacterial patch density is low or variable. On the other hand, we observed immediate exploitation of high density patches. In these environments, an explore-then-exploit strategy is disadvantageous, as delaying exploitation when patch density is already high results in spending more energy on food search with no expected increase in energy gained during exploitation of a subsequently encountered patch. Thus, consistent with an energy maximizing optimal forager, C. elegans explores first when bacterial patch density is low, but immediately exploits when bacterial patch density is sufficiently high. Altogether, our results demonstrate that C. elegans make a distinct decision to either explore or exploit a patch upon encounter and that the density-dependence of this decision is consistent with predictions from optimal foraging theory.

Our finding that C. elegans are willing to reject numerous encountered patches is somewhat surprising, especially given that C. elegans likely possess limited spatial memory [25] and do not appear to detect the presence of bacterial patches prior to encounter as slow-down only occurs within one body-length of the patch edge (Figure 2B). Further, C. elegans are likely unaware of how many patches are in the environment as evidenced by their willingness to reject a patch even when only one patch is available. Taken together, this suggests that animals are “knowingly” passing up an opportunity to exploit an immediately available food source for the potential opportunity to exploit preferred food later. This type of behavior has been described min humans and other animals in the context of delayed gratification [47, 48], intertemporal choice [47, 49, 50], self-control [51, 52], and optimal stopping [53, 54]. Notably, few animals display the capacity for delayed gratification when given the option between eating an immediately available but less preferred food item and waiting for a preferred food item [55-58]. Even fewer animals are willing to wait if the delayed reward is not visible or increases in quantity rather than quality [59, 60]. Our observation that C. elegans can exhibit delayed gratification suggests that this and similar processes require less complex cognition than previously considered or that we may have underestimated the cognitive capacity of C. elegans.

Prior experience and satiety guide foraging decision-making

Stay-switch decisions in C. elegans are strongly modulated by a variety of internal and external sensory cues over a range of behavioral timescales. For example, patch-leaving frequency can be modulated by an animal’s prior experience [25, 42], metabolic status, arousal state [31], as well as the presence of pathogens [61, 62], chemorepellents [63], predators [64, 65], and varying levels of environmental O2 and CO2 [40, 66].

Here, we used a quantitative framework to show that prior experience (i.e., the density of current and recently encountered and exploited bacterial patches) guides accept-reject decision-making. According to early models in optimal foraging theory, foragers behave as if they have complete information about the environment (e.g., animals are assumed to know the average density of bacterial patches) [9]. Later theoretical and empirical work expanded models of patch choice to accommodate situations where animals have incomplete information (e.g., environments with fluctuating resources) and, therefore, must both acquire information and forage [8, 10, 67]. This work suggests that animals may continuously sample areas in their environment to keep track of resource availability. Here, we found that animals initially choose to sample patches and that the duration of this period of sampling is correlated with the degree of mismatch between current and recently experienced and exploited patches (i.e., animals spend more time sampling as the magnitude of difference between the patch density experienced immediately before and during the experiment increases). When there is no difference between current and prior experience (i.e., animals foraging on patches of relative density 200), animals rarely sample. These results suggest that C. elegans use sampling as a way of re-evaluating the overall quality of patches available in the environment when a change is detected. Further, the results of our model suggest that animals likely use the information learned during sampling encounters to guide their decision to explore or exploit on subsequent patch encounters. We behaviorally validated this hypothesis by applying our model predictions to animals foraging in environments with multiple patch densities. We predicted and observed that the lower the density of recently encountered or exploited patches and the higher the density of the current patch, the more likely an animal would be to exploit. These results suggest that C. elegans can learn and remember features of recent experiences and use that learned information to guide efficient decision-making. Incorporating prior experience into the decision to explore or exploit currently available food is highly beneficial when foraging in a fluctuating environment. C. elegans thus may have evolved this ability to maximize foraging in the wild where animals experience a boom- and-bust environment [68].

In addition to prior experience, internal state signals serve a critical role in modifying decision-making in C. elegans [31, 69]. For example, food-deprived animals are more likely to cross an aversive barrier (e.g., copper, primaquine, glycerol) in search of food as compared to well-fed controls [69, 70]. Here, we find that a satiety-related signal likely drives the decision to exploit. Specifically, our model suggests that as animals’ satiety decreases, their willingness to accept a lower quality patch increases. We confirmed this prediction by analyzing the behavior of food-deprived animals, which immediately exploit even when bacterial patches are very dilute. Combined with the effect of prior experience, these results suggest that the decision to explore or exploit likely requires integration of food-related internal and external cues. Future studies should probe if additional factors related to the animal’s biotic and abiotic environment [35, 71-74] as well as alternative motivations (e.g., reproduction and predatory avoidance) [75-78] further modify these foraging decisions.

Quantitative and ethological approach to investigating decision-making

Naturalistic observations of C. elegans behavior are necessary to achieve a more complete cellular, molecular, and genetic understanding of how the nervous system has evolved to drive animal behavior. For example, large patches of densely seeded bacteria have primarily been used in experiments assessing C. elegans foraging [20, 21, 79-81]. However, wild nematodes experience a boom- and-bust environment [68] that may be more consistent with sparse, patchily distributed bacteria [28]. Thus, just as quiescence is only observed on high quality bacterial patches [82], additional behavioral states may be discovered when assessing foraging in dilute patchy environments. By conducting detailed analyses of ecologically inspired foraging behaviors in individual animals, we discovered that C. elegans make accept-reject decisions upon encounter with bacterial patches. By studying foraging in these environments containing small, dilute bacterial patches, we increased the frequency of opportunities for accept-reject decision-making (i.e., patch encounters and patch-leaving events are more frequent) and decreased the condition-specific bias towards accept decisions (i.e., animals are less likely to accept patches when moved between environments of differing bacterial density). We expect that further investigation into naturalistic behaviors could reveal additional insights into more complex behaviors and decision-making in C. elegans and other animals.

In this study, we fine-tuned an assay that enables observation of ecologically relevant decision-making in freely moving animals. We posit that future studies can leverage this assay to investigate the neuronal mechanisms underlying decision-making. The frequency of decision-making opportunities (i.e., numerous accept-reject decisions could be observed in the span of minutes) and consistency of patch choice decisions across hundreds of animals and a range of environmental conditions tested supports this claim. Further, we anticipate that the accept-reject decision occurs during a narrow time window – possibly at the time of encounter with the patch edge or shortly thereafter. Therefore, we expect that this assay could be adapted for experiments utilizing calcium imaging in freely-moving animals [17, 30, 83-87] to monitor neuronal activity as animals make these decisions.

Finally, we used simple quantitative models to dissect and validate the components underlying decision-making. Specifically, we employed a logistic regression GLM which we adapted to accommodate our uncertainty in classification of sensing and exploitation for each encounter. The GLM enabled us to conduct a sequence of hypothesis tests probing the influence of food-related signals on the decision to exploit. Further, the GLM enabled us to identify the simplest model that could explain the observed delay in exploitation. While even the null model predicted that, on average, numerous exploratory encounters were likely to occur before the first exploitation, models including satiety and prior experience significantly better predicted the extent of this delay. We demonstrated that we could validate these model predictions in food-deprived animals, animals exploring multiple patch densities, and animals with sensory deficiencies. We propose that this approach to investigating behavior and decision-making is incredibly powerful for refining hypotheses and enables subsequent investigation leveraging the diversity of cellular, molecular, and genetic tools available in C. elegans.

Abbreviations

  • (BIC): Bayesian information criterion

  • (GMM): Gaussian mixture model

  • (GLM): generalized linear model

  • (KDE): kernel density estimate

  • (KL): divergence, Kullback-Leibler

  • (LB): lysogeny broth

  • (NGM): nematode growth medium

  • (OD600): optical density at 600 nm

  • (QDA): quadratic discriminant analysis

Acknowledgements

We thank members of the Chalasani lab for comments on the manuscript and James Fitzgerald for advice on modeling. This research was funded by grants from the National Science Foundation (J.A.H.), UCSD Undergraduate Summer Research Award (T.C.), NIH RO1 MH096881, Dorsett Brown Foundation, and Salk Innovation Grant (S.H.C.).

Additional information

Author Contributions

Jessica Haley: Conceptualization, Methodology, Software, Validation, Formal analysis, Investigation, Resources, Data Curation, Writing – Original Draft, Writing – Reviewing & Editing, Visualization, Supervision, Project administration, Funding acquisition. Tianyi Chen: Investigation, Data Curation, Writing – Reviewing & Editing. Mikio Aoi: Methodology, Formal analysis, Writing – Reviewing & Editing, Visualization, Supervision. Sreekanth Chalasani: Conceptualization, Resources, Writing – Reviewing & Editing, Supervision, Funding acquisition.

Declaration of Interests

The authors declare no competing interests.

Materials and Methods

Key Resources Table

Data and Code Availability

All data reported in this paper will be shared by the lead contact upon request. All original code has been uploaded to GitHub (https://github.com/shreklab/Haley-et-al-2024) and are publicly available as of the date of publication. Any additional information required to reanalyze the data reported in this paper is available from the lead contact upon request. Source data files contain the summarized data for all plots.

Bacterial cultures

Stock liquid cultures of the OP50 strain of Escherichia coli were prepared via inoculation of a single colony in sterile lysogeny broth (LB) grown overnight at room temperature. Stock liquid cultures were subsequently stored at 4°C for up to 6 weeks.

Solutions of OP50 for each experiment were prepared via a series of dilutions in LB (Figure 1 – supplement 1A). 50 mL of OP50 stock solution was centrifuged at 3000 rpm for 5 minutes. After removal of supernatant, approximately 500 to 1000 µL of saturated liquid culture remained. The bacterial density of this saturated solution was estimated by measuring the optical density at 600 nm (OD600) of a 1:50 dilution of the homogenized solution on a spectrophotometer (Molecular Devices SpectraMax Plus 384). The saturated solution was subsequently diluted to achieve an OD600 of ∼10 (μ = 10.22, σ = 0.31). Measurements of the number of colony forming units in the “10” solution estimated 13.1×109 cells per mL on average. Additional densities (OD600 = {0.05, 0.1, 0.5, 1, 2, 3, 4, 5}) were prepared via dilution of the “10” solution with LB and kept on ice to prevent bacterial growth. A “0” density solution was prepared with just LB.

For all experiments, these density solutions were seeded onto cold, low-moisture nematode growth medium (NGM) plates (3% agar) to facilitate pipetting of small, circular, quick-drying patches. Unless otherwise noted, seeded plates were immediately returned to 4°C after patches dried to prevent bacterial growth. Plates were stored at 4°C for an average of 6 days before experimentation.

For experiments using an OP50 strain expressing green fluorescent protein (OP50-GFP) [88], cultures were prepared as above, but with the addition of 100 µg/mL of carbenicillin to the liquid LB. All bacterial strains used in this study are listed in the Key Resources table.

Nematode cultures

Caenorhabditis elegans strains were maintained under standard conditions at 20°C on NGM plates (1.7% agar) seeded with stock liquid culture of OP50 [16]. All experiments were performed on young adult hermaphrodites, picked as L4 larvae the day before the experiment (μ= 24.6 hours, σ = 3.4). Unless otherwise indicated, well-fed animals of the standard C. elegans strain N2 Bristol were used for experiments. Transgenic strains were always compared to matched controls tested in parallel on the same days. All C. elegans strains used in this study are listed in the Key Resources table.

Assay preparation and recording

Single-density, multi-patch assay

Several days before the experiment, condition and acclimation plates were prepared (Figure 1 – supplement 1A). For the condition plates, a large circular arena (30 mm in diameter) made of clear transparency film (6 mil, PET) was cut using a computer-controlled cutting machine (Cricut Maker 3) and placed in the center of a 10 cm petri dish filled with 25 mL of NGM (3% agar). These arenas function to corral animals with a low probability of escape [89]. A pipetting template made of the same material was designed and cut with an isometric grid consisting of 19 circular holes spaced 6 mm apart from center-to-center. The pipetting template was overlaid on top of the arena and 0.5 µL of OP50 solution (OD600 = {0, 0.05, 0.1, 0.5, 1, 2, 3, 4, 5, 10}) was pipetted into each hole. After drying, the template was immediately removed, and the petri dish lid replaced to prevent contamination and dehydration. For two conditions (“1 (12H)” and “1 (48H)”), plates were seeded with OD600 = 1 and then left at room temperature for 12 or 24 hours, respectively, prior to storage at 4°C. For all other conditions, plates were immediately stored at 4°C after drying. Acclimation plates were prepared by seeding NGM (3% agar) plates with one large patch of 200 µL of OD600 = 1 grown for 24 hours at room temperature.

Approximately 24 hours before the experiment, acclimation plates and “1 (48H)” condition plates were transferred from 4°C to room temperature. After plates warmed to room temperature (∼1 hour), 30-60 L4 animals were picked onto the acclimation plates. Plates were then stored at 20°C until the experiment for a combined bacterial growth time of approximately 48 hours (24 hours from freshly seeded to 4°C; 24 hours from 4°C to experiment). The combined bacterial growth time for all condition plates was approximately 1 hour (μ= 1.16 hours, σ = 0.23) unless otherwise noted as “12” (μ= 13.63 hours, σ = 0.50) or “48” hours (μ= 49.28 hours, σ = 2.94).

On the day of the experiment, each set of condition plates was transferred from 4°C to room temperature. After one hour, 4 young adult animals were gently transferred to an empty NGM plate to limit the spread of bacteria from acclimation to condition plates. Animals were then quickly transferred to a condition plate. Animals were transferred using cylindrical plugs excised from clean 3% agar [64, 89].

Condition plates were subsequently placed face down on a piece of glass suspended above an edge-lit backlight (Advanced Illumination). Recordings were acquired using PixeLink cameras (PL-B741F) combined with Navitar lenses (1-60135 and 1-6044) and Streampix 8 software. Behavior was recorded for one hour at 1024×1024 pixels and 3 frames per second (fps) with spatial resolution of ∼33 pixels per mm (μ= 32.68 pixels/mm, σ = 1.70).

The assay was repeated over numerous days with every condition assayed on each day when possible. The order of seeding assay plates and recording behavior was randomized for each day to compensate for the potential effects of time on animal age and bacterial density. Further, the average temperature (μ= 21.99°C, σ = 0.95) and humidity (μ= 51.39%, σ = 11.67) during each experiment were recorded. As a result of randomization, animal age, bacterial growth time, temperature, and humidity did not significantly vary between density conditions.

Large, single-patch assay

Plates were prepared as described for the single-density, multi-patch assay with the exception that only one large patch was created by pipetting 20 µL of OP50 solution (OD600 = {0, 0.05, 0.1, 0.5, 1, 2, 3, 4, 5, 10}) into the center of the 30 mm diameter arena.

Small, single-patch assay

Plates were prepared as described for the single-density, multi-patch assay with the exception that only one small patch was created by pipetting 0.5 µL of OP50 solution (OD600 = {0, 0.5, 1, 5, 10}) into the center of a 9 mm diameter arena. Given the smaller arena size, only one young adult animal was transferred into the arena. Behavior was recorded for one hour at higher spatial (μ= 104.76 pixels/mm, σ = 17.6) and temporal resolution (8 fps). The acquisition set-up was otherwise unaltered except for the removal of a 0.25x Navitar lens (1-6044) from the light path.

Multi-density, multi-patch assay

Plates were prepared as described for the single-density, multi-patch assay with the exception that varying combinations of OD600 = {1, 5, 10} (i.e., OD600 = {1, 5, 10, 1+5, 1+10, 1+5+10}) were pipetted onto each assay plate in a patterned isometric grid of 18 0.5 µL droplets. Behavior was recorded for two hours. To compensate for the longer duration recordings, NGM agar plates were poured without Bacto™ peptone (BD 211677) to prevent bacterial growth. The result of this change was that the relative density of bacterial patches was ∼30% lower as compared to comparable 0.5 µL patches in the single-density, multi-patch assay and the small, single-patch assay (Figure 2 – supplement 2-3). Further, to prevent censorship of our data at the beginning of the recording, we formed a small droplet of S-Complete solution [90] in the middle of the arena where no bacterial patch was placed. Animals were transferred to this droplet using an eyelash pick immediately prior to the assay plate being placed on the imaging set-up. The recording was started once the droplet evaporated and animals were free to crawl about the arena. This process ensured that recordings began prior to an animal’s first patch encounter.

Bacterial patch location detection

Most bacterial densities tested in these experiments were too dilute to be visible under normal imaging conditions. Therefore, several strategies were employed to accurately detect the location of bacterial patches. First, a small reference dot was cut into the arena and pipetting templates enabling consistent and traceable patch placement. Further, prior to each behavior recording, a “contrast” video was acquired wherein a piece of dark cardstock was passed between the light source and the condition plate (Figure 1 – supplement 1B-D, Video 2). This produced an effect where diffraction of light through the patches provided enough contrast to view the patches. Binary masks of the circular arena and patches were extracted from these videos in MATLAB using the Image Processing Toolbox and further refined manually in Photoshop (Adobe, 2024). Arena masks were used to calculate the scale (pixels/mm) of each image. In early experiments, the “contrast” video was acquired prior to worms being added to the condition plate, which resulted in displacement of the arena within the camera’s field-of-view. Image registration using MATLAB’s Computer Vision Toolbox was performed to accurately map the patches detected in the “contrast” video onto the behavioral recording.

Bacterial patch density estimation

As described above (see Assay preparation and recording), we varied the relative density of bacterial solutions by diluting OP50 in LB and growing patches for different lengths of time. As a result of these procedures, the relative bacterial density throughout the assay was not known and needed to be estimated. To determine the relative density of these bacterial patches, we seeded plates with fluorescently labeled OP50-GFP under identical conditions as in our assays (Figure 2 – supplement 1A). We imaged these bacterial patches for several hours using a Zeiss Axio Zoom.V16. Images were analyzed using the Image Processing Toolbox in MATLAB. After correcting for inconsistent illumination across the field-of-view and normalizing images using matched controls (Figure 2 – supplement 1B-C), we detected the location of each bacterial patch and extracted a fluorescence intensity profile along each patch’s radius (Figure 2 – supplement 1D). Consistent with previous studies, we found that even in extremely dilute conditions, bacterial density was greater at the patch edge where actively proliferating bacteria are concentrated [43, 91]. Therefore, we detected the patch edge and computed the peak amplitude of each bacterial patch at all time points assayed (Figure 2 – supplement 1E). We then performed linear regression on the values for each condition to create models of peak amplitude as a function of time. For low density conditions (i.e., OD600 = {0.05, 0.1}) of small patches, fluorescent signals could not be detected. We therefore estimated these functions from a multinomial regression of values taken from OD600 = {0.5, 1, 2}. Through this process, we used the total time that bacteria were allowed to grow at room temperature for each condition plate to estimate the peak amplitude at each time point (Figure 2 – supplement 3). Finally, to minimize confusion about density conditions between experiments, we computed values for relative density by linearly scaling estimated peak amplitude values so that 0.5 µL patches seeded with OD600 = 10 and grown for 1 hour at room temperature would have relative density equal to 10. We labeled each condition using the relative density rounded to one significant digit.

Behavioral tracking

WormLab® (MBF Bioscience) was used for tracking animal behavior (Figure 1 – supplement 1E-G, Video 3). For each video, we adjusted thresholds for pixel intensity and worm dimensions to enable automatic tracking. WormLab then fit the worm’s body at every frame and stitched together a track of each worm across frames. Subsequent manual corrections were required for instances where the software created new worm tracks. This occurred most frequently when animals: 1) encountered the arena border, 2) collided with each other, or 3) overlapped with bubbles or dust particles embedded in the agar. To correct for these discontinuities, we manually “stitched” worm tracks together enabling us to keep track of each animal’s location throughout the duration of the experiment. We exported the location of each animal’s midpoint for further analysis in MATLAB (Mathworks, 2024a). For small, single-patch assays where higher spatial resolution enabled reliable distinction between the head and tail of the animal, we manually confirmed the head-tail and exported 25 points along the animal’s midline (Figure 1 – supplement 2A-C).

Animals were excluded from analyses when 1) the animal’s location could only be tracked for less than 75% of the video due to the animal escaping the arena and when 2) the location of bacterial patches could not be reliably assessed due to missing or low-quality “contrast” videos (see Bacterial patch location detection).

Patch encounter detection

As the head position of animals in our experiments was difficult to track due to low spatial resolution and limited automated detection of head position using WormLab, we instead tracked the midpoint position of the worm’s body and estimate patch encounters using a set of measured criteria. To do this, we tracked the behavior of worms in higher resolution (∼105 pixels/mm compared to ∼33 pixels/mm and 8 fps compared to 3 fps), single patch assays (Figure 1 – supplement 2A-C). We found that when the head of the animal was in contact (i.e., within 1 pixel) with the patch edge (see Bacterial patch location detection), the animal’s midpoint was on average 0.46024 mm away (Figure 1 – supplement 2D). We therefore defined a patch encounter as the time when an animal’s midpoint came within 0.46024 mm of the patch edge. However, this definition led to two types of errors: 1) putative entry events where the animal merely passed by the patch and 2) putative leaving events where the animal did not fully leave the patch.

To remove putative entry events where the animal nearly passed by the patch, we defined an additional distance threshold based on the distance between the animal’s midpoint and the patch edge for all time points when the head was within the patch (Figure 1 – supplement 2E). The midpoint was almost always (99% of time) within 0.28758 mm of the patch edge. Therefore, we removed patch encounters where the midpoint never got closer than 0.28758 mm from the patch edge. Although this criterion removes most “near miss” events, some events remain where the animal approached the patch, but its head never entered. Further decreasing this threshold (e.g., midpoint must be on patch) would result in real events being excluded due to the animal taking on specific postures where the midpoint remains outside the patch while feeding within the patch. Therefore, we chose to be more liberal (i.e., more false positive patch encounters than false negatives) in our detection of patch encounters. Subsequent analysis of these putative patch encounters removed the majority of remaining false positives (see Patch encounter classification as sensing or non-sensing).

To address putative leaving events and avoid splitting a single patch encounter into multiple encounters, we considered that a lawn leaving event is most frequently defined as an event where all body parts have left the patch [31]. When tracking only the midpoint, it is not possible to ensure that the worm’s entire body has exited the patch. Using the criterion that an animal exits a patch when it’s midpoint exceeds 0.46024 mm from the patch edge accurately predicts exit events most of the time, but under certain scenarios (e.g., animals maintain an outstretched feeding posture [64]) false leaving events were detected. To exclude these leaving events, we analyzed the variability in the distance from the midpoint to the patch edge during on- and off-patch events (Figure 1 – supplement 2F). We found that on-patch events had low distance variability while off-patch events displayed a bimodal distribution, with some events having high variability as expected, and some events having low variability. We fit a two-component Gaussian mixture model to the off-patch distance variability and found that low variability leaving events could be reliably excluded when the standard deviation of off patch distances was less than 0.13259. We subsequently combined putative patch encounters where variability was below this threshold, resulting in fewer overall encounters.

Patch encounter classification as exploration or exploitation

To classify patch encounters as exploration or exploitation events, patch encounters were detected (see Patch encounter detection) and two features were computed: 1) duration of patch encounter and 2) average on-patch velocity. Both the duration and velocity features displayed a bimodal distribution with two visible clusters: one with short duration encounters and high on-patch velocity and one with long duration encounters and low on-patch velocity (Figure 2 – supplement 6A). To classify patch encounters into one of these clusters, we used a two-component Gaussian mixture model (GMM) to estimate p(yk = 1|zk) where for each encounter k, zk are the log transforms of the duration and average velocity of the patch encounter, yk = 1 indicates an exploitation, and yk = 0 indicates an exploration. We optimized the GMM across cross-validated replicates with respect to the regularization value α to minimize the posterior variance given by

We found that α = 0.025 best separated the exploration and exploitation clusters (Figure 2 – supplement 6B). The posterior probability of exploitation p(yk = 1|zk) was subsequently estimated for all encounters (Figure 2 – supplement 6C-D).

Patch encounter classification as sensing or non-sensing

To classify patch encounters as sensing or non-sensing events, we computed animals’ 1) deceleration upon encounter with the patch edge, 2) minimum velocity during the patch encounter, and 3) maximum change in velocity between the peak velocity immediately prior to the start of the patch encounter and the minimum velocity during the encounter (Figure 2 – supplement 7A). Deceleration was defined as the slope of the line fit on an animal’s velocity between -1.5 seconds before and 6.5 seconds after the start of an encounter. Minimum velocity was defined as the absolute minimum velocity observed during the duration of the patch encounter. The maximum change in velocity was computed by subtracting the minimum velocity from the peak velocity within 10 seconds of the patch encounter. The combination of these three metrics reveals two non-Gaussian clusters representing encounters where animals sensed the patch (i.e., slow minimum velocity, large changes in velocity) or did not appear to detect it (i.e., maintained fast minimum velocity, with little to no change). We estimated the probability of sensing p(νk = 1|wk) where for each encounter k, wk = (sk, tk, uk) are the three velocity-related features (i.e., minimum velocity, deceleration, and maximum change in velocity, respectively), νk = 1 indicates an encounter that was sensed, and νk = 0 indicates an encounter which did not appear to be sensed. Using a semi-supervised approach to quadratic discriminant analysis (QDA), we labeled a subset of all encounters and iteratively estimated labels on the remaining unlabeled data (Figure 2 – supplement 7C-E, Video 4). All encounters with bacteria-free patches (i.e., LB only, relative density 0) were labeled as true negatives νk = 0. Across 1000 replicates, we probabilistically included exploitation encounters yk = 1 estimated from the distribution yk|zk ∼ Bern(p(yk = 1|zk)) as true positives νk = 1. Using this approach, the conditional probability of sensing p(νk = 1|wk) was iteratively estimated for all encounters using QDA and averaged across replicates.

Although we found that the two clusters were successfully discriminated by this semi-supervised QDA approach, a small subset of encounters (252 of 20109 encounters) could not be reliably classified in this manner as the onset of the patch encounter was not observed. This type of data censoring occurred when the behavioral recording was started after the animal had already entered the patch. Although we could compute deceleration-related metrics for these encounters with the assumption that the animal entered the patch at the first frame, these measurements are censored with a bias towards lower magnitudes of deceleration. Therefore, to better predict the conditional probabilities of sensing for these 252 encounters, we assumed that the minimum velocity on-patch sk was a reliable metric and marginalized the conditional probabilities over the other two metrics (tk and uk) as defined by

We numerically integrated using an adaptive quadrature method over the product of the QDA estimated conditional probability distribution and the kernel density estimate of the joint probability distribution. This procedure resulted in a slight increase (μ= +0.0615, σ = 0.1832) in our estimation of the probability of sensing (Figure 2 – supplement 7H).

Altogether, this classification approach resulted in low false positive and false negative rates. Specifically, 3.35% of the time encounters with bacteria-free patches were incorrectly identified as sensing while 2.92% of the time exploitatory encounters were incorrectly identified as non-sensing. Further, this classification removed many of the remaining near miss patch encounters in which animals came close to but did not truly enter the patch (see Patch encounter detection). For all analyses, we excluded near miss encounters where the animal’s midpoint never entered the patch and the probability of sensing was less than 5% (i.e., p(νk = 1|wk) < 0.05).

Models of exploitation probability

We consider that the probability of exploiting a patch upon any given encounter can be described by a logistic function:

where p(yk = 1|β · xk) represents the conditional probability that an animal exploited during patch encounter k; xkRn is a vector of covariates; and βRn is a vector of weights that describes how much each covariate influences the animal’s choice. In models compared here, xk includes a combination of a constant element as well as covariates that may empirically influence the decision to exploit: 1) the log-transformed relative density of the encountered patch k (ρk), 2) the duration of time spent off food since departing the last exploited patch (τs), 3) the log-transformed relative density of the patch encountered immediately before encounter k (ρh), and 4) the log-transformed relative density of the last exploited patch (ρe).

The observations of exploitation and sensation for our data are derived predictions from classification models (see Patch encounter classification as exploration or exploitation and Patch encounter classification as sensing or non-sensing). As such, the labels for both whether a patch encounter was sensed by the animal p(νk = 1|wk) and whether the animal exploited the patch p(yk = 1|zk), are both reported as probabilities rather than direct measurements.

To account for uncertainty in sensation, we produced 100 sets of “encounter sampled” observations wherein we probabilistically included sensed encounters νk = 1 estimated from the distribution νk|wk ∼ Bern(p(νk = 1|wk)). In doing so, we assume that only patch encounters recognized by the animal guide the decision to exploit (Figure 4B). After removing non-sensing encounters where νk = 0, we defined observations of all covariates (i.e., ρk, τs, ρh, and ρe) using only sensed encounters.

To account for uncertainty in exploitation we modified the standard maximum likelihood. To understand our approach, consider that standard logistic regression models binary observations as realizations of the Bernoulli distribution yk|xk ∼ Bern(p(yk = 1|β · xk)) and that the likelihood for this model is given by

However, we do not have direct observations of yk and cannot evaluate the logistic likelihood directly. Rather, we have posterior probabilities of exploitation determined by a classifier, denoted by p(yk = 1|zk), where zk are a set of velocity-related features that are distinct from xk (see Patch encounter classification as exploration or exploitation). Thus, rather than maximizing the Bernoulli likelihood, we accommodate our uncertainty about yk by learning the regression parameters that minimize the Kullback-Leibler (KL) divergence between p(yk|β · xk) and the reference probability distribution p(yk|zk) as given by

where Cβ is a term that is constant with respect to β, and the second term is equivalent to the logarithm of the logistic likelihood with p(yk = 1|zk) replacing yk. Put plainly, minimizing the sum of the KL divergence between our classifier probabilities and logistic regression probabilities over all encounters k is equivalent to maximizing the logistic likelihood with our classifier-based exploitation probabilities p(yk = 1|zk) as observations instead of direct measurements of exploitation yk as given by

To train our model, we therefore fit a standard logistic regression GLM where we provided sets of observations of covariates xk and response variables p(yk = 1|zk) for sensed encounters.

Exploitation of single-density, multi-patch environments

As described above, we used an “encounter sampling” protocol to generate 100 replicate observations of only sensed encounters by removing all encounters that were not sensed (i.e., νk = 0) as randomly estimated from the distribution νk|wk ∼ Bern(p(νk = 1|wk)) (Figure 4B). For example, we can consider an animal foraging in this single-density, multi-patch environment. Although we detected 10 total encounters K = k1, k2, …, k10, several of these encounters had low probabilities of sensing p(νk = 1|wk) (Figure 4B). We use our “encounter sampling” protocol to simulate sensation of the patch during each of these 10 encounters and find that νk = 0 for k1, k3, k6 and k8. By removing these 4 non-sensed encounters, we generate a new observation comprised of the 6 sensed encounters . Using only the data related to this new sequence of encounters , we generated a vector of covariates (i.e., ρk, τs, ρh, and ρe). Importantly, this procedure considers time spent during the non-sensed encounters k1, k3, k6 and k7 the same as time spent searching off patch. We repeated this process 100 times to generate new observations of encounter sequences (i.e., ). In doing so, we reduced the number of encounters from 6,560 total encounters (as defined in Patch encounter detection) to 2,604-2,698 (μ = 2659.8, σ = 15.9) sensed encounters for each of the 100 replicates.

Additionally, we used a “worm sampling” protocol to generate 500 hierarchically bootstrapped replicates [92]. Specifically, we took our vector of 443 animals A = a1, a2, …, a443 and resampled with replacement (e.g., ) to generate 500 new samples . When combined, the “encounter sampling” and “worm sampling” protocols created 50,000 unique replicates of observations of the covariates xk and response variables p(yk = 1|zk) which were used to estimate the coefficients β (Figure 4C). A null distribution of coefficients β* was estimated by shuffling the response variable vector (Figure 4 – supplement 1B). A two-tailed, one-sample bootstrap hypothesis test was used to assess whether our covariate estimates were significantly greater than or less than 0 (i.e., p = 2 × min[P(β0), P(β0)]).

Exploitation of food-deprived animals in single-density, multi-patch environments

To validate model predictions related to the satiety signal covariate τs, a novel data set of well-fed and 3-hour food-deprived animals foraging in single-density, multi-patch environments of relative density 5 was generated (Figure 4 – supplement 3A-B). The “encounter sampling” protocol described above was used to generate 100 replicates of observations of the covariates xk and response variables p(yk = 1|zk) for this data set. As a result of “encounter sampling”, we reduced the number of encounters from 42 total encounters to 30-37 (μ = 34.6, σ = 1.3) sensed encounters for food-deprived animals and 235 total encounters to 94-107 (μ = 99.8, σ = 2.1) sensed encounters for well-fed animals. Coefficient values β were re-estimated in the absence of the satiety signal τs (Figure 4 – supplement 3C) using the original single-density, multi-patch data set. Using the mean coefficient values β for both models (with and without satiety), we predicted the conditional probabilities of exploiting p(yk = 1|β · xk) for the new data set for well-fed and food-deprived animals. We subsequently simulated a series of exploitation events from a Bernoulli distribution using the estimated (i.e., yk|xk ∼ Bern(p(yk = 1|β · xk))) and observed (i.e., yk|zk ∼ Bern(p(yk = 1|zk))) exploitation probabilities. These simulated exploitations were used to generate distributions of the probability of an exploitation occurring for the first time as a function of the number of encounters (Figure 4 – supplement 3D).

Exploitation of multi-density, multi-patch environments

To validate model predictions related to the prior experience covariates ρh and ρe, a novel data set of animals foraging on multi-density, multi-patch environments was generated (Figure 4E, Figure 4 -supplement 4A-C). The “encounter sampling” protocol described above was used to generate 100 replicates of observations of the covariates xk and response variables p(yk = 1|zk) for this data set. As a result of “encounter sampling”, we reduced the number of encounters from 4,296 total encounters (350-984 total encounters per condition) to 1,702-1,745 (μ = 1,724.6, σ = 9.9) sensed encounters. Coefficient values β were re-estimated in the absence of the recently encountered and exploited patch density terms ρh and ρe (Figure 4 – supplement 4D) using the original single-density, multi-patch data set. Using the mean coefficient values β for both models (with and without prior experience), we predicted the probabilities of exploiting p(yk = 1|β · xk) for the new data set. To generate the heat maps of predicted behavior (Figure 4F), we varied ρk and ρh as well as ρk and ρe across a range of values and set the remaining covariate terms to the average values observed in the data set. To generate the heat maps of observed behavior (Figure 4F), we averaged the observed probabilities of exploiting p(yk = 1|zk) for each pairing of ρk and ρh as well as ρk and ρe and linearly interpolated values between these 9 points.

Exploitation of sensory mutants in single-density, multi-patch environments

To test the utility of our model in identifying covariate-specific phenotypes in animals with varied genotypes, a novel data set of wild-type animals and sensory mutants foraging on single-density, multi-patch environments was generated (Figure 4 -supplement 5A-B). The “encounter sampling” and “worm sampling” protocols described above were used to generate 50,000 replicates of observations of the covariates xk and response variables p(yk = 1|zk) for this data set. As a result of “encounter sampling”, we reduced the number of encounters from 1,352 total encounters (27-193 total encounters per condition) to 862-894 (μ = 879.4, σ = 7.4) sensed encounters. As the number of encounters were significantly less in these data sets as compared to the original single-density, multi-patch data set, we used ridge regression to regularize the magnitude of the covariates. We optimized each model across cross-validated replicates by varying the regularization value λ. We found that λN2 = 0.0175, λmec−4 = 0.0223, and λosm−6 = 0.0614 maximized the mean log-likelihood of each model (Figure 4 – supplement 5E). Coefficient values β were estimated for each of the three strains tested using these values (Figure 4 – supplement 5D). To assess whether the magnitude of coefficients significantly differed between wild-type and mutant models, we conducted a two-sample test of the mean of differences as given by

where μ and σ are the mean and standard deviation, respectively, of the distribution of a covariate across replicates. Statistical significance was calculated as a left-tailed test ϕ(Z) for the density coefficients (βk, βh, and βe) and a two-tailed test ϕ(−|Z|) for the other coefficients (β0 and βs) where ϕ is the standard normal cumulative distribution function.

Figure Supplements

Assay preparation, arena and patch detection, and behavioral tracking.

(A) Graphic describing the steps to prepare assay plates. Created with BioRender. (B) Example frames from a “contrast video” showing how a piece of dark cardstock passed between the light source and the assay plate enables visualization of dilute bacterial patches. (C) An image of the bacterial patches is generated from the “contrast video”. (D) Masks of the arena (black) and bacterial patches (gray) were constructed using image processing techniques and, when applicable, subsequent manual corrections (see Bacterial patch location detection). Arena masks were used to calculate the image scale in pixels/mm. (E) Example frame from a behavior video containing four adult C. elegans is shown. (F) WormLab was used to identify the midbody location of animals in each frame (see Behavioral tracking). An inset shows detection of one of the four worms. (G) An example animal’s tracked location as it forages in this environment is plotted with color used to represent time (dark blue = 0 mins; dark red = 60 mins).

Defining a patch encounter using high resolution behavioral recordings.

(A) Example frame from a behavior video containing one adult C. elegans is shown. (B) WormLab was used to track the body of the animal in each frame (see Behavioral tracking). (C) An example image showing the center spline of the example animal as well as the location of the bacterial patch (gray) and arena (black). The inset shows the animal’s center spline and bacterial patch superimposed on top of the raw image. (D) Example body postures/orientations (black) of an animal during frames when its head is on the patch edge. The distance (blue lines) between the head (black dot) and midpoint (blue dot) of the animal was calculated. A histogram of this head-to-midpoint distance is plotted, and the median value (blue) is indicated (sample size: 220 animals; 74839 frames). The median head-to-midpoint distance was subsequently used as a threshold for detection of patch encounter and leaving events. For one example animal, the distance between the head (black) or midbody (blue) position and the nearest patch edge (positive = inside patch; negative = outside patch) is plotted for every time point. The edge of the patch (solid black line) and threshold for encounter detection (dashed -.- black line) are indicated. Putative patch encounter (green) and leaving (red) events are shown. (E) Example body postures/orientations of an animal when its head is on the patch. The distance between the midpoint of the animal and the patch edge (blue lines) was calculated. A histogram of this midpoint-to-patch distance is plotted, and the 1st percentile (blue) is indicated (sample size: 220 animals; 1571163 frames). This value is used a threshold for excluding putative encounters where the animal’s midpoint never comes within 0.28768 mm of the patch edge. A 1.5 minute time window of the example animal’s position in (D) is shown. The edge of the patch (solid line), threshold for encounter detection (dashed -.- line), and threshold for encounter exclusion (dashed – line) are indicated. Example putative encounters are shown. The first two sets of enter and exit events were excluded. The third set shown was included. The included encounter is shaded in gray. (F) The standard deviation of the distance between the location of the patch edge and the midpoint of the animal was calculated for every putative on-patch encounter and off-patch event (sample size: 220 animals; 2945 putative on-patch events; 2725 putative off-patch events). A subset of putative off-patch events had low standard deviations matching those of on-patch events. A one-dimensional Gaussian mixture model was fit to the off-patch standard deviation values and a threshold was set where the posterior probability of events falling in the high or low variance cluster was 0.5. A 1.5 minute time window of the example animal’s position in (D) is shown. Examples of two excluded off-patch events and one included event are shown.

Classifying encounters based on duration using a Gaussian mixture model.

(A) As in Figure 1E, duration for each patch encounter (N = 419 events; 50 worms) was computed and classified as either short or long using a Gaussian mixture model (GMM). The distributions of all observed short and long encounters are plotted with duration binned logarithmically. The probability density functions for the two component Gaussians are shown. (B) The posterior probabilities for classification as short or long are sorted for all encounters, highlighting the low posterior variance of the GMM. (C) Given that some patch encounters were not fully observed (i.e., ∼22% of animals were already on patch at the start of the recording and ∼96% of animals were on patch when the recording ended), we identified that ∼14% of observed patch durations were left-censored (i.e., having actual duration ≥ observed duration). Thus, to confirm findings in Figure 1E-F, we re-classified only non-censored observations where both the entry and exit of a patch encounter were observed. As in Figure 1C, patch encounters for 50 individuals foraging in these patchy environments are plotted across time. Encounters that were uncensored (pink) and censored (gray) are indicated. (D) The distribution of the duration of only fully observed (uncensored) encounters (N = 360 events; 50 worms) is plotted. The component Gaussians for a GMM fitting this subset of data are shown. (E) Sorted posterior probabilities for the uncensored model are shown. (F) The observed start time of each uncensored patch encounter is shown for all short and long duration encounters. Long duration encounters occur significantly later (Mann-Whitney U-Test, ***p<0.001). Violin plots show the KDE and quartiles for each duration type. (G) Posterior probabilities for classification in the long duration cluster are shown for the two models. The uncensored data model results in a slight increase in posterior probabilities of long duration classification, but ultimately affected classification of only one of the 419 encounters.

Permuting patches to test for significance of the observed time-dependent increase in patch residence.

(A) Locations of bacterial patches (dark gray) are shown with the threshold for putative encounters (light gray) set at 0.46024 mm as described in Figure 1 – supplement 2 and Patch encounter detection. (B) Patches were permuted via randomized rotation and translation with the restriction that patches could not overlap with other patches nor with the arena. (C,D) Midbody location of the animal over time was overlaid on the original and semi-randomly permuted patches. (E,F) On patch events were subsequently identified. This permutation procedure was repeated for 1000 replicates for every worm tested. Smoothed median values of the probability of worms residing on patch over time was compared for every time point in Figure 1G, 2F and Figure 2 – supplement 5.

Analyzing deceleration upon encounter with a patch.

(A) To quantify the magnitude of slow-down upon encounter with the patch edge, we averaged the velocity trajectories across encounters and found the velocity reached a maximum at 1.5 seconds before (green) and a minimum at 6 seconds after (red) the start of the encounter (gray). (B,C) Subsequently, for every encounter, a line (blue) was fit to the animal’s velocity (black) for that 8 second time window surrounding the start of the encounter. Deceleration was defined as the slope of this line. Examples matching (B) the short duration encounter in Figure 1J and (C) the long duration encounter in Figure 1K are shown.

Obtaining intensity profiles for fluorescent bacterial patches.

(A) Fluorescently labeled OP50-GFP bacterial patches were seeded onto agar plates under conditions matching those in the experimental assay. Small patches (0.5 µL) were pipetted in an isometric grid (6 mm center-to-center spacing) on a 16 × 25 mm rectangular template comparable to the one used in behavioral assays. Large patches (20 or 200 µL) were seeded directly onto agar plates. Brightfield and fluorescence images were acquired for every condition at multiple time points of bacterial growth. The fluorescence intensity profile of these images was obtained. (B) Due to uneven illumination within the field-of-view of our imaging system, matched fluorescence images of an empty agar plate were acquired at each time point. These “background” images were smoothed using a two-dimensional averaging filter to remove noise. (C) Fluorescence images of the bacterial patches were normalized to these background images. (D) Locations of bacterial patches within the template were automatically detected using image processing techniques. Each patch was then radially segmented in bins of equal area. The mean pixel intensity value for each bin was computed and used to create an intensity profile of the patch. (E) The patch border and peak were detected using signal processing techniques. Specifically, the patch border was identified by finding a peak in the curvature κ of the edge profile. Border amplitude was defined as the magnitude of the difference between the patch border and peak. Relative border amplitude was defined as the border amplitude divided by the exposure time. A line was fit to the values of relative border amplitude across numerous time points and experiment days (5 replicates shown as varying color points).

Example fluorescence profiles of bacterial patches under varied growth conditions.

Fluorescently-labeled OP50-GFP bacterial patches were imaged as described in Figure 2 – supplement 1 and Bacterial patch density estimation. Inverted images (darker saturation = more bacteria) are shown here to highlight the range of bacterial densities tested in these experiments. All patches are shown on the same spatial scale and using one of the two linear saturation scales: 1) regular – normalized to show variance in high density patches; 2) augmented (∼22x) – normalized to show variance in low density patches). Each patch shown is labeled with the optical density (OD600) at time of seeding and the amount of time bacteria was grown for at room temperature (i.e., 1, 12, or 48 hours). (A) An example large (200 µL) bacterial patch of the type that animals experienced immediately prior to the assays in this paper. (B) Example small (0.5 µL) bacterial patches of greatest density. (C) Example small (0.5 µL) bacterial patches of lower density. The saturation of each image has been uniformly augmented to ∼22x darker to the extent that the OD600 10 (1H) bacterial patch is the same patch as the one in B. (D) Example small (0.5 µL) bacterial patches of lower density seeded on NGM agar plates lacking peptone. (E) Example medium (20 µL) bacterial patches of greater density. (F) Example medium (20 µL) bacterial patches of lowest density. The OD600 1 (1H) bacterial patch is the same patch as the one shown in E, but ∼22x darker.

Quantifying the relative density of bacterial patches across conditions and time points.

(A) Relative density of OP50-GFP bacterial patches matched to all assay conditions in this paper are shown. Relative density represents the relative border amplitude (as defined in Figure 2 – supplement 1 and Bacterial patch density estimation) normalized to the mean density of patches seeded with 0.5 µL of OD600 = 10 grown for 1 hour on plates with peptone (blue asterisk). In this manner, the bacterial patches experienced by animals in Figure 1 have been set to an average relative density of 10. Violin plots show the KDE and quartiles for each condition. (B) Linear fits for the relative density of bacterial patches in each condition as a function of time are plotted. Saturation of each line corresponds to the relative density as depicted in (A). For each experimental plate, the relative density of bacterial patches was estimated by applying the coefficients from these linear regressions to the total amount of time the bacteria was grown at room temperature.

Example traces of animals foraging in environments with varying bacterial density.

Traces showing the midbody location of 12 example animals as they forage within a 30 mm arena are plotted with color used to represent time (dark blue = 0 mins; dark red = 60 mins). Locations of bacterial patches are indicated in gray. The relative density of bacterial patches in each environment is noted. Animals shown foraging on relative density 0, 1, 5, 10, and 200 are the same as those in Figure 2D.

Time- and density-dependent increase in patch residence.

Probability of residing on patch was computed for all worms across time (black) and compared to the probability of residing on patch for semi-randomly permuted patch locations (pink) as described in Figure 1 – supplement 4. Smoothed median values are plotted with bootstrap-derived 2.5% and 97.5% quantiles shown in shaded regions. Time points where observed probabilities of residing on patch significantly exceed permuted probabilities are indicated by a black line (one-tailed Fisher’s Exact Tests with Benjamini-Hochberg correction, ***p < 0.001). The smoothed median values for observed data are shown in Figure 2F. Data for relative density 10 match those in Figure 1G.

Classifying encounters as exploration or exploitation.

(A) The average velocity of the animal during an encounter and the duration of that encounter are plotted for each encounter as visualized on a double-logarithmic plot. Contours showing the first, second, and third standard deviation of the two-dimensional Gaussian mixture model (GMM) are shown as shaded ellipses with saturation corresponding to standard deviation. Encounters for all data in the paper are individually plotted as in Figure 2H but with color representing the posterior probability of clustering classification as explore (green) or exploit (blue). (B) Posterior variance of the data as defined in Patch encounter classification as exploration or exploitation was calculated for 1000 replicates of GMMs with varied regularization value α. The classifier with minimum posterior variance (i.e., α = 0.025) was used. (C) The posterior probabilities for classification as explore (green) or exploit (blue) are sorted for all encounters, highlighting the low posterior variance of the GMM. (D) Posterior probabilities for only the data in Figure 2 are shown.

Classifying encounters as sensing or non-sensing.

(A) Minimum velocity (min. velocity on patch), maximum change in velocity (max. Δ velocity), and deceleration (Δ velocity) were calculated as described in Patch encounter classification as sensing or non-sensing. (B) Maximum change in velocity for every density condition is shown. Violin plots show the KDE and quartiles for each condition. (C) Deceleration upon encounter and minimum on-patch velocity during the encounter are plotted for each encounter. A three-dimensional parabolic boundary between sensing and non-sensing clusters was fit using semi-supervised QDA and a subset of labeled data (blue circles = sensing, dark orange circles = non-sensing). Regions identified by the classifier as non-sensing or sensing are indicated by colored contours (orange = non-sensing, green = sensing). Encounters for all data in the paper are individually plotted as in Figure 2I but with color representing the conditional probability of clustering classification as non-sensing (orange) or sensing (green). (D) Maximum change in velocity and minimum on-patch velocity during the encounter are plotted for each encounter in the paper as in (C). (E) Minimum velocity on patch, maximum change in velocity, and deceleration are shown for every encounter in the paper. See Video 5 for three-dimensional rotation of this plot. (F) The probabilities for classification as sense (green) or non-sense (orange) are sorted for all encounters. (G) Probabilities for only the data in Figure 2 are shown. (H) For a subset of encounters that were censored (i.e., recording did not observe animals entering the patch), probabilities of sensing were estimated using the semi-supervised QDA approach as well as via marginalization over the conditional probabilities using only the observed minimum velocity on patch. Marginalized probabilities were used for these values as described in Patch encounter classification as sensing or non-sensing.

Example traces of animals foraging in environments with one large bacterial patch.

Example traces showing the midbody location of 11 animals as they forage within a 30 mm arena are plotted with color used to represent time (dark blue = 0 mins; dark red = 60 mins). Location of bacterial patches are indicated in gray. The relative density of bacterial patches in each environment is noted. The animal shown foraging on relative density 10 is the same as that in Figure 3D.

Example traces of animals foraging in environments with one small bacterial patch.

Example traces showing the midbody location of 6 animals as they forage within a 9 mm arena are plotted with color used to represent time (dark blue = 0 mins; dark red = 60 mins). Location of bacterial patches are indicated in gray. The relative density of bacterial patches in each environment is noted. The animal shown foraging on relative density 10 is the same as that in Figure 2E.

Model selection for nested GLMs.

(A) Values of log-likehood, Aikake Information Criterion (AIC), and Bayesian Information Criterion (BIC) were computed for 50,000 replicates of the linear regression model described in Models of exploitation probability. Each of these metrics is plotted here across 100 replicates of “encounter samples” (i.e., we removed encounters where the animal likely did not sense the encounter νk = 0 as estimated from the distribution νk|wk ∼ Bern(p(νk = 1|wk))) and 500 replicates of hierarchically bootstrapped “worm samples” (i.e., we resampled animals with replacement and included all encounters of the resampled animals). Values for each metric at each replicate are colored to match their respective color bar. Metrics were computed for the addition of each covariate to the model. Lower AIC and BIC values for the full model ((i.e., β · xk = β0 + βkρk + βsτs + βhρh + βeρe), represent better model performance even with penalization for increasing the number of parameters. (B) Coefficients β* for the null distribution (i.e., observations of the response variable p(yk = 1|zk) shuffled relative to the covariates xk) are plotted. Only β0 was significantly greater than or less than 0 (two-tailed, one-sample bootstrap hypothesis tests with Bonferroni correction). Violin plots show the KDE and quartiles for each covariate across the 50,000 replicates. Asterisks denote statistical significance (*p<0.05; **p<0.01; ***p<0.001). These β* represent the null distribution for the β in Figure 4C.

Probability of first exploitation as a function of the number of encounters.

Histograms of the probability of first exploiting as a function of the number of encounters as estimated by the models and as observed are shown for animals foraging in single-density, multi-patch environments of all 12 density conditions. Exploitation events were simulated from a Bernoulli distribution with probability estimated by the model yk |xk∼ Bern(p(yk = 1|β · xk)) where covariates were added one at time as well as from the observed probabilities estimated by the Gaussian mixture model classification yk|zk ∼ Bern(p(yk = 1|zk)) in Figure 2H. Histograms for relative density 1 and 10 are the same as those in Figure 4D.

Exploitation decision of food-deprived animals is well-predicted by the model.

(A) Schematic of experiments used to test satiety’s influence on the decision to exploit. As in all experiments, animals were acclimated to high density (relative density ∼200) patches for ∼24 hours. Well-fed animals were then removed from these acclimation plates, cleaned of bacteria, and then immediately transferred to the assay plate with relative density 5. Food-deprived animals moved about a bacteria-free arena for 3 hours prior to the assay. Examples of animal behavior while foraging in acclimation-like, bacteria-free, and single-density, multi-patch environments of relative density 5 are shown. (B) Patch encounters for 28 food-deprived and 28 well-fed individuals are plotted across time. Each encounter is colored to match its probability of classification as search (orange), sample (green), and exploit (blue). (C) Coefficient values were re-estimated across 50000 replicates as in Figure 4C for a model with the satiety term removed (i.e., p(yk = 1|β0 + βkρk + βhρh + βeρe)). All coefficients are significantly greater than or less than 0 (two-tailed, one-sample bootstrap hypothesis tests with Bonferroni correction; ***p<0.001). Violin plots show the KDE and quartiles for each measure. (D) Histograms of the probability of first exploiting as a function of the number of encounters are shown for food-deprived and well-fed animals. Model predictions of exploitation events were simulated from a Bernoulli distribution yk|xk ∼ Bern(p(yk = 1|β · xk)) where the coefficient values β corresponded to those previously estimated for our linear regression model with (Figure 4C) and without (Figure 4 – supplement 3C) the satiety term using the data set shown in Figure 2 (i.e., the 443 well-fed animals foraging in one of 12 density conditions). Observed exploitations were simulated from a Bernoulli distribution using the probability of exploitation estimated by our GMM classifier yk|zk ∼ Bern(p(yk = 1|zk)) in Figure 2H. Summary data for all animals (N = 56 total worms; N = 28 worms per condition) and encounters (N = 277 total encounters; N = 42-235 encounters per condition) are shown in (B,D).

Example traces and classified behavior of animals foraging in environments with multiple patch densities.

(A) Example traces showing the midbody location of 7 animals as they forage within a 30 mm arena are plotted with color used to represent time (dark blue = 0 mins; dark red = 60 mins). Locations of bacterial patches are indicated in gray with saturation indicating the relative density. Environments contained combinations of patches with relative density 1, 4, and 7 as noted. (B) Patch encounters for 200 individuals (20-40 per condition) are plotted across time. Each encounter is colored to match its relative density. (C) Patch encounters are colored to match their probability of classification as search (orange), sample (green), and exploit (blue). (D) Coefficient values were re-estimated across 50000 replicates as in Figure 4C for a model with the history-dependent terms removed (i.e., p(yk = 1|β0 + βkρk + βsτs)). All coefficients are significantly greater than or less than 0 (two-tailed, one-sample bootstrap hypothesis tests with Bonferroni correction; **p<0.01; ***p<0.001). Violin plots show the KDE and quartiles for each measure. Summary data for all animals (N = 198 total worms; N = 20-40 worms per condition) and encounters (N = 3,493 total encounters; N = 282-795 encounters per condition) are shown in (B,C).

Example traces and classified behavior of animals with chemosensory or mechanosensory deficiencies.

(A) Example traces showing the midbody location of 9 animals as they forage within a 30 mm arena are plotted with color used to represent time (dark blue = 0 mins; dark red = 60 mins Location of bacterial patches are indicated in gray. The relative density of bacterial patches in each environment is noted. 3 strains of C. elegans were tested (grey = N2, pink = mec-4, orange = osm-6) across 3 conditions of relative density (1, 5, and 10). (B) Patch encounters for 76 individuals (16-44 per density condition) of each strain are plotted across time. Each encounter is colored to match its probability of classification as search (orange), sample (green), and exploit (blue). (C) Histograms of the probability of first exploiting as a function of the number of encounters are shown for each strain and density condition. Observed exploitations were simulated from a Bernoulli distribution using the posterior probability of exploitation defined by our GMM classifier yk|zkBern(p(yk = 1|zk)) in Figure 2H. Histograms of each strain for relative density conditions 1 and 10 are the same as those in Figure 4G. (D) Coefficients β* for the null distribution (i.e., observations of the response variable p(yk = 1|zk) were shuffled relative to the covariates xk) are plotted. Violin plots show the KDE and quartiles for each covariate across the 50,000 replicates. These β* represent the null distribution for the β in Figure 4H. (E) The ridge regression parameter λ was optimized for each strain to maximize the mean log-likelihood of the model. Summary data for all animals (N = 221 total worms; N = 14-44 worms per condition) and encounters (N = 1,352 total encounters; N = 27-193 encounters per condition) are shown in (B,C).