Skip to main content
  • Loading metrics

Measuring the repertoire of age-related behavioral changes in Drosophila melanogaster


Aging affects almost all aspects of an organism—its morphology, its physiology, its behavior. Isolating which biological mechanisms are regulating these changes, however, has proven difficult, potentially due to our inability to characterize the full repertoire of an animal’s behavior across the lifespan. Using data from fruit flies (D. melanogaster) we measure the full repertoire of behaviors as a function of age. We observe a sexually dimorphic pattern of changes in the behavioral repertoire during aging. Although the stereotypy of the behaviors and the complexity of the repertoire overall remains relatively unchanged, we find evidence that the observed alterations in behavior can be explained by changing the fly’s overall energy budget, suggesting potential connections between metabolism, aging, and behavior.

Author summary

Aging is a ubiquitous biological phenomenon that affects many aspects of an animal’s appearance, physiology, and behavior. Our understanding of how changes in physiology lead to behavioral changes, however, has been partially limited by our ability to robustly quantify how behavior alters over timescales of days and weeks. In this study, we measure a large repertoire of behaviors of fruit flies at various ages, finding how the actions the animals perform shift with age. We observe a difference between the aging dynamics of male and female flies, and we show that many of these changes can be explained with a model of energy consumption, leading us to make predictions as to the role of metabolism in changes in aging behavior.


Aging is a biological process that affects nearly all organisms, resulting in profound changes to their morphology, physiology, and behavior [13]. While there exists variability in the precise form and timing of these alterations, stereotyped patterns of aging-related change are commonly observed at scales ranging from molecules to tissues to the entire organism [4]. However, we lack a comprehensive framework for predicting how the multifarious age-related changes at the molecular and neuronal levels lead directly to behavioral changes.

While many age-related changes in behavior are due to direct reductions in an animal’s capacity for movement (e.g., arthritis in humans or wing damage in flies), another commonly posited hypothesis is that aging effects in behavior can be partially understood as an alteration in an animal’s energy budget [5, 6]. In other words, while the organism may still be able to physically perform most activities within its repertoire, its reduced metabolic efficiency might impose constraints on an animal’s total amount of energy to expend, leading to age-related changes in its behavioral repertoire. This idea, that the available energy an animal possesses would have systemic effects on its chosen actions, is reminiscent of the “hydraulic” theory of action selection that was popularized by Lorenz and others [7] and might be related to molecular models of metabolic decline such as insulin pathway modifications [810].

Testing the hypothesis that age-related alterations can be understood through alterations in energy budgets, however, has proven difficult, partially due to the limitations in our ability to accurately measure full repertoires of behavior across time. Aging is a complex, dynamical process that cannot be measured at a single time-point, but, rather, it must be characterized as a trajectory across a lifetime. Accordingly, to measure how animals’ behavioral repertoires and their usage alter with age, we need to have not only a framework to measure repertoires at the timescale of single stereotyped movement (order of tens of milliseconds to seconds), but also new analysis methods to isolate the between-age-group variability from the within-age-group variability in these behaviors, finding combinations of behaviors that best describe the dynamics of aging.

In this paper, we study the age-related changes in the behavioral dynamics of the fruit fly Drosophila melanogaster, a common model system for the study of aging and behavior [1114]. We measure the full repertoire of behaviors that flies of varying ages perform. While previous research on aging and behavior in flies focus on how only a small number of behaviors change with age, here, by quantifying the full repertoire of behaviors that the animals exhibit in our experimental conditions, we can observe how behavioral performance, in terms of both usage frequency and context-dependent usage (e.g., transition probabilities), changes with age. To measure the animals’ behavior, we use an unsupervised method that identifies the stereotyped behaviors that the fly performs without a priori behavioral definitions—behavioral mapping [15]. Our results show that (1) large changes and a sexual dimorphism in how the behavioral repertoire changes with age; (2) despite these changes, the overall complexity of the flies’ behavior remains unchanged; (3) as the fruit flies age, their behavioral repertoires alter, but the behaviors are still performed with similar stereotypy; (4) we can explain most of the inter-age-group behavioral variability that we observe by using an estimation of average power consumption. Thus, we provide evidence that the energy budget that an animal has available may be a key factor in regulating its behavior with age. This result encourages further investigation into the physiological basis of aging, lending credence to hypotheses that link metabolic decline to age-related behavioral changes in animals.


Experiments and behavioral densities

In order to characterize how flies’ behavioral repertoires changes with age, we imaged flies (Drosophila melanogaster) in a largely featureless environment (see Materials and methods for details). In total, we imaged 304 flies (155 male and 159 female), each imaged once with and age between 0 and 70 days old (the average lifespan is 60–80 days [16]). The flies were placed in the arena via aspiration and given 5 minutes to acclimate to the environment. To measure the flies’ behavioral repertoires, we use the behavioral mapping approach originally described in Berman (2014) [15]. In brief, this method uses image compression techniques to measure a time series of the fly’s postural dynamics, computes a continuous wavelet transform to isolate the dynamical properties of these time series (i.e., finding which parts of the body are moving at what speeds), and uses t-Distributed Stochastic Neighbor Embedding (t-SNE) to perform dimensionality reduction on the amplitudes of this transform, creating a 2-dimensional probability density function over the space of postural dynamics. We refer to the arrangement of peaks within this probability density function as our behavioral space.

Each peak within this density represents a distinct stereotyped behavior (e.g., grooming, running, idle, etc.). Thus, the relative probabilities of observing a fly within each peak in the density is a measure of the animal’s behavioral repertoire, seen in Fig 1A. Following the procedure described in Cande (2018) [17], all flies—including all males and all females of all ages—were embedded into the same space in order to facilitate comparisons between individuals, sexes, and ages. We isolate the individual peaks by applying a watershed transform [18] to segment the density into 122 discrete states, with near-by regions corresponding to similar behaviors (Fig 1B). The density for all the males can be seen in Fig 1C, and the density for all the females in Fig 1D. These behavioral densities provide the foundation for our analysis, as we use them to quantify how behavioral repertoires change with age.

Fig 1. Behavioral densities for quantifying the full repertoire of behaviors of male and female fruit flies (D. melanogaster) with ages ranging from 0–70 days.

(A) A behavioral density averaged across all flies in this study (both males and females). The color scale corresponds to the probability density function, where red peaks correspond to individual stereotyped behaviors. (B) Applying a watershed transform on the PDF from (A) produces boundary lines for the different behavioral states. Similar types of movement (described via manual annotation of the videos) are clustered together on the behavioral space, and broad descriptions of the type of movements in each cluster are obtained from the original videos. By taking the embedded points and sorting them by sex, we can make behavioral densities for the males and females separately. (C) The behavioral density averaged over all the male flies from all age groups. (D) Same as in (C), but averaged over all female flies.

Quantifying behavioral changes with age

Dividing the males and females each into two-week-interval age groups (Fig 2), we observe a sexual dimorphism in how their behaviors change with age. Specifically, the younger male flies mostly perform idle behaviors. In mid-life, they perform more active behaviors before again becoming lethargic in later life. Conversely, the females perform active behaviors when young, and gradually begin to perform more idle behaviors as they increase in age (excepting the last age group, which is likely under-sampled). While these results could have been found with center-of-mass tracking or other less computationally intensive methods than behavioral mapping, that our method replicates previously observed experimental results [12], provides additional confidence in the analyses to follow.

Fig 2. Behavioral densities as a function of age.

Behavioral densities for male and female flies are shown on the left, with ages broken down into 2-week intervals. We construct these densities by separating the embedded points into subgroups of male, female, and age. In this figure, we see a broad description of behavior as a function of age emerge. Male flies mostly perform idle or slow throughout their life, with the exception of mid-life, when they do more active behaviors. In contrast, females are very active when young and become more idle as they age. An annotated behavioral space from Fig 1 is displayed on the right.

While the data plotted in Fig 2 displays how flies’ mean behavioral profile alters with age, there also exists variance and co-variance within sex and age groups [1921] (although no notable structure based on the precise time of imaging—see S1 and S2 Figs). Thus, we need to isolate the variance in our data that is associated with changing age, rather than from inter-age-group variability. To quantify the inter-group behavioral variance structure, we measured the behavioral covariance matrix across all sex/ages, providing a quantification of the behaviors that are shifting together with age.

Our analyses here use the discretized version of the behavioral densities, using the watershed-transform-derived regions shown in Fig 1B. P(i) is a vector of probabilities, where, is the the time-averaged probability that fly i performs behavior j during the one hour filming epoch—we call this vector our behavioral vector. Given these values, we can then calculate the average behavioral density for all individuals within each sex/age group. We define this group-specific mean behavioral vector to be , where z ∈ {male, female} and k is the age group. From these means, we can then compute the covariance matrix of the set of mean behavioral vectors, (5 different 2-week groups for each sex).

This covariance matrix (C(M) ≡ Cov(M)), shown in Fig 3A, quantifies which behaviors are likely to increase or decrease with respect to each other across sex/age groups. To further quantify the structure within C(M), we calculate its eigenvectors and eigenvalues (Fig 3B and 3C), effectively performing Principal Components Analysis on the mean vectors. Because the covariance matrix is, by definition, real-valued and symmetric, all of its eigenvalues must be greater or equal to zero. We focus here on only the modes corresponding to the two largest eigenvalues, as only these two modes have eigenvalues that are significantly larger or similar in value to those from a covariance matrix derived from independently shuffling each of the columns in M. Although there is not a clear interpretation of these two eigenvectors ( and ), both appear to capture the relative performance of idle and locomotory behaviors, and the first also appears to capture the relative usage of slow vs. fast locomotion. By plotting the projection of each fly’s behavioral vector as a function of age and finding Gaussian-smoothed average curves (see Materials and methods), we see how this low-dimensional space of behaviors alters as the flies age (Fig 3D). There is a clear sexual dimorphism in the projections onto the first eigenmode, with the male flies exhibiting non-monotonic dynamics with age, whereas the female’s average curve is largely monotonically decreasing. A similar dynamic can be observed in the second eigenmode but with a more subtle shift, as well as a sign flip. These results agree with the visual intuition from Fig 2 and provide a quantification of the most important changes in the flies’ behavioral repertoire with age.

Fig 3. Identifying aging-specific behavioral covariances.

(A) The covariance matrix of the mean behaviors sorted according to the clusters in Fig 1B. (B) The eigenvalues of the covariance matrix. There are two eigenvalues (blue) that are larger or approximately equal to the eigenvalues returned from shuffling the behavioral density matrix (red, error bars are the standard deviations from many independent shuffles of the data). These two modes account for approximately 62% of the variation in the data. (C) The eigenvectors corresponding to the largest (top) and second-largest (bottom) eigenvalues. (D) Projections of the data onto the largest (top) and second-largest (bottom) eigenvectors in (C), plotted as a function of age. Here, dots are values for individual animals, and the solid lines are from smoothing the data with a Gaussian of σ = 3.5. Error bars are the standard deviations of this process as a function of age after re-calculating the curve with re-sampled data (drawn with replacement from the original data).

Estimated energy consumption alters with age

As stated in the introduction, a potential mechanism for the flies’ observed changes in behavior could be an overall reduction in the flies’ energy budget with age. While it was not possible to directly measure the power consumption from the animals in our experiments, we can instead estimate the metabolic cost of the observed behaviors with a biomechanical model.

Given that the flies are constrained to move within a two-dimensional environment, we focus our modeling efforts on estimating the cost of legged locomotion within the arena (making the assumption that non-locomotion behaviors like grooming are negligible in energetic cost compared to locomotion, see Materials and methods for further justification). Our model of the power consumption during locomotion largely follows that of Nishi (2006) [22], which estimates the heat dissipation and work done during each swing and stance phase of locomotion at a given velocity using a biomechanical model of force production during legged locomotion (see Materials and methods for details). While this model has several free parameters related to the fly morphology and how gait dynamics alter with speed, we use morphological and scaling data from the literature on legged locomotion [23, 24] to set these parameters. More precisely, we wish to calculate R(v), the specific power (mechanical power per unit mass) required for the fly to move at a speed v.

From tracking the center-of-mass of each fly, we are able to measure pi(v), the probability density function for speed for fly i, for each animal. Given this distribution and our expression for R(v), we can calculate the average specific power consumption, for each animal through numerically integrating (1) where vmax is the largest observed speed for the flies. To make this calculation more tractable, we find that for biologically realistic range of locomotion speeds (0–60 mm/s), R(v) is well-approximated by a quadratic function (R(v) = av2 + bv + c, where a = 19.9s−1, b = 1.17m/s2, and c = .0002m2/s3), as shown in Fig 4A.

Fig 4. Energy usage predicts aging-specific changes in behavior.

(A) Comparison of the quadratic model to the full model of Nishii (2006) to estimate specific power (power per unit mass) of legged locomotion in fruit flies. (B) Specific power as a function of age for male (blue) and female (orange) fruit flies. Each point represents an individual, and the curves are the Gaussian-smoothed means (σ = 3.5 days), with error bars generated in the same manner as Fig 3D. (C) Average projections onto the first eigenmode (Fig 3C (top)) plotted versus the average specific power consumption for both male and female flies. Each point represents the value (plus error bars) from the curves in (B) and Fig 3D (top), each spaced 7 days apart. Dashed lines are the linear fits to the data. (D) Same as (C), but instead using projections onto the second eigenmode (Fig 3C (bottom)). Note that at over 70% of the mean aging-specific variation can be explained using the first two eigenmodes.

The results of this calculation for each individual animal are shown in Fig 4B as a function of age. While there is significant scatter in the data (likely due to variance in the internal activity state of the flies [19, 25]), when we compute a smoothed average of the data, a clearer portrait emerges. Specifically, we observe that these curves are reminiscent of the sexual dimorphism we observed in the inter-group eigenvector projections in Fig 3. More quantitatively, we see that when plotting the eigenvector projections versus the group-average specific power (Fig 4C), we see a high degree of correlation for each of these values. As seen in the figure, we can explain at least 72% of the aging-specific behavioral variation using a linear fit to the estimated specific power consumption. Thus, these analyses imply that most of the age-related changes we observe in the animal’s behavior are correlated with changes in the average energy expenditures of the flies.

Complexity of the behavioral repertoire

Although we show that most age-related changes in fly behavior are correlated with energy consumption, it still may be possible that other factors such as the complexity of the behavioral repertoire or the degradation of stereotyped behaviors might also be observed as the animals age [26, 27]. We test the former of these hypotheses by calculating the entropy of the behavioral space, using this metric as a proxy for the overall repertoire complexity.

Specifically, we measure the entropy, Hi, of each individual fly’s behavioral density according to (2) where ρ(x, y) is the probability distribution over the two-dimensional behavioral space. Plotting Hi as a function of the flies’ ages (Fig 5), we see no discernible trend in entropy vs. age, with the best fit slopes showing a value of −0.00 ± 0.03 for the male flies and −0.01 ± 0.03 for the female flies. (We also took a measure of the entropy using the probability distribution over the 122 discretized behaviors and obtained comparable results—S4 Fig). Thus, even though the behavioral densities are dramatically changing with age, the overall complexity remains largely unaltered, and thus we cannot conclude that the complexity of the repertoire degrades with age.

Fig 5. Entropy of the behavioral densities, integrated via Eq (2), as a function of age for the males (left) and females (right) with a best-fit line.

Error bars for individual animals are smaller than the symbol size in the plot. The males have a slope of −0.00 ± 0.03 and the females have a slope of −0.01 ± 0.03.

Long time scales and hierarchical structure in behavior with age

While the complexity of the behavioral repertoire remains unchanged, the complexity of how the animals traverse through this space over time might still show significant deviations. Prior investigations into the complexity of fly behavioral sequences have shown that these dynamics of transitions between stereotyped behaviors exhibit long time scales and hierarchical organization [19, 25]. A hypothesis for aging-related behavioral change is that the structure of the behavioral repertoire becomes less complex with age [26, 27], and with the detailed measurements of behavior described here, we can test this idea, potentially gaining insight into changes occurring to the internal programs that may generate these patterns.

First, to assess the overall timescale structure of the flies’ behavioral patterns, we measure the transition matrix at different time scales, (3) where i and j as two stereotyped behaviors, S(n) is the behavioral state of a system at transition n (note: to decouple waiting time in a state from complexity in the order of pattern of transitions between states, we measure time in units of transitions, following the methods in [25]). We can decompose each of these matrices via (4) where and are the ith right and jth left eigenvectors of the matrix, respectively, and λμ is the eigenvalue with the μth largest modulus. Because the columns of each of these matrices must sum to one, λ1(τ) = 1 for all values of τ, and |λμ>1(τ)| < 1 by the Perron-Frobenius Theorem. While for a Markov Model, the eigenvalues should decay exponentially with τ, we find that flies in all sex and age groups exhibit super-Markovian time scales (Fig 6 shows the results for the second-largest eigenvalues in each transition matrix. The 3rd-5th eigenvalues can be seen in S5 Fig). With the exception of the > 56 day-old females (for which we had fewer individuals in our sample), however, we found no differences larger than the standard error of the mean between the time scales across age groups.

Fig 6. Absolute value of the second eigenvalue of the transition matrices as a function of transitions into the future, averaged over all flies in each age group with error bars corresponding to standard error of the mean for the male flies (left) and the female flies (right).

The light blue line, which acts as a noise floor, is the second eigenvalue in a transition matrix calculated after shuffling our finite data set.

While the complexity of the repertoire or the overall timescale might not be changing with age, the underlying structure of the behavioral transitions might still be altering. To test for this possibility, we applied a predictive clustering analysis to the space to identify groupings of behaviors that best preserve information about the long timescale structure in our data. More precisely, we would like to find a partition of our behavioral space, Z, such that this representation has a simple of a representation as possible, while still maintaining information about the future behavioral states of the animal. Here, we achieve this using the Deterministic Information Bottleneck (DIB) approach [28, 29], which minimizes the functional (5) where Z is our partition, H(Z(n)) is the entropy of the partition, β is a Lagrange multiplier that modulates the relative importance of simplicity and predictability, and I(Z(n); S(n + τ)) is the mutual information between the partition and the future behavioral state at a time τ in the future. We perform this optimization for several values of τ for each age group, in all cases varying β and the number of initial clusters in Z to create a full curve of values (see Materials and methods for details and S6 Fig).

The resulting clusterings for τ = 100 with five clusters can be seen in Fig 7. As with the eigenvalues in the previous plot, the clusters obtained via this approach remain nearly constant with varying age, with only small-probability behaviors flipping between regions. Thus, we lack evidence of significant alterations of the temporal complexity of the flies’ behavior with age.

Fig 7. Hierarchical partitioning solutions from deterministic information bottleneck for the behavioral density with τ = 100 and 5 clusters for male flies (top) and female flies (bottom) as a function of age.


Lastly, while we observe no significant changes to the flies’ repertoire or temporal complexity, we still can measure if there is deterioration in how the behaviors are performed, potentially implying that the flies are undergoing a physical deterioration or some other inability to consistently perform behaviors while aging. To assess changes in how stereotyped behaviors are performed, we measure how much the performance of individual behaviors are altered with age, quantifying a decreased stereotypy with an increase in the variance of the postural trajectories underlying the performance of these actions.

We divide the data into age groups of two-week intervals, with a one-week overlap (0–14 days, 8–21 days, 15–28 days, etc.), finding the postural trajectories associated with the performance of each behavior. While the details of this can be found in Materials and Methods, broadly, we use a phase-reconstruction method (based on Revzen (2008) [30]) across all of the postural modes for each time a behavior is performed. We measure the mean postural dynamics across all individuals in a given sex/age group and assess the stereotypy of each behavior (b) in each age group (κ) with our Stereotypy Index, χb,κ, which is the fraction variance explained by the mean trajectory for that behavior. Thus χb,κ → 1 implies that each time the behavior is performed, its postural trajectories are exactly the same (maximally stereotyped), and χb,κ → 0 implies that the postural trajectories are different each time the behavior is performed (minimally stereotyped).

The values of χb,κ for each behavior and three different age groups are displayed in Fig 8A. By eye, we can see only minimal changes across the age groups (and no outside errorbar changes after accounting for multiple comparisons using Bonferroni corrections). Note that a few behaviors, while stereotyped, were not performed enough to get a good estimate of their synchronization parameters so those behaviors are listed as having a synchronization parameter of 0 (see Materials and methods for more details).

Fig 8. Few measurable changes in stereotypy with age.

(A)The stereotypy of each behavior (or how stereotyped each behavior is—1 being very stereotyped, 0 being not at all stereotyped) plotted as a function of age by calculating the maximum synchronization parameters of each behavior for the males (top) and females (bottom). (B) Quantification of how the synchronization parameters change between each age group and the initial age group by taking the mean difference between the synchronization parameters of each behavior. Error bars are bootstrap estimates from re-sampling individuals with replacement.

To quantify this lack of change across the whole behavioral repertoire, we calculated the average stereotypy for each age group, (6) where Gκ is the set of all flies in age group κ, Nκ is the number of flies in the group, and is the fraction of time that fly i performs behavior b. We then measured the difference in the average stereotypy of the youngest age group and each of the subsequent age groups for each sex (). Fig 8B shows the results of this calculation for both males and females. Although we do observe some changes between the age group, they are within 1.5 standard deviations. Thus, although the probability of choosing a behavior changes with age, each behavior, when performed, is, on average, no less stereotyped.


In this paper, we measured the behavior of fruit flies (D. melanogaster) at many points along their lifespan, aiming to isolate patterns of behavioral change with age and to make predictions about the physiological basis of these changes. Consistent with previous studies, we found a sexual dimorphism in changes in the animals’ overall activity level, but we also identified subtler patterns of change with age by measuring the largest eigenvalues, and their corresponding eigenvectors, of the inter-age-group covariance matrix. Despite observing no significant changes in the repertoire complexity or stereotypy with age, we find that most of the age-specific behavioral alterations are correlated with age-specific changes in a model of energy consumption, implying that energy budget may play an overarching role in regulating aging behavior.

This observation that energy may play a key role in aging-specific changes in behavior is in accordance with results from long-lived mutants in a variety of species, many of which have changes in gene regulation pathways that affect energy availability [31]. For example, mutations in the insulin/IGF-1 receptors or homologs, which promote food storage and cell replication, have been shown to extend lifespan in flies [32, 33], nematodes [10, 34], and rodents [35]. In addition, another long-lived fly mutant, the E(z) histone methyltransferase heterozygous mutation, is associated with large alterations in a variety of metabolic regulation pathways [36]. In addition, these changes were found to exhibit sex-dependent effects, similar to our results as well. However, these studies do not examine how longevity affects full repertoires of behavior. There is a known inverse correlation between frequency of high energetic cost behaviors and longevity [37], so we would expect the long-lived mutants to use fast locomotion less and idle more than an unaltered fly. We further hypothesize that caloric-restricted animals too would exhibit fewer of the high energetic cost behaviors.

In future efforts where behavioral repertoire and metabolic state could be simultaneously assayed (through, for example, proteomic or transcriptomic measurements), we would expect to find correlations between positions along the curves seen in Fig 3D and key metabolic regulators. Through this methodology, it may be also possible to provide an effective age for each individual in a heterogeneously aging population, providing a phenotyping tool for identifying new molecules involved in increased and decreased longevity, as well as for the study of evolutionary aging dynamics. A possible follow-up study could use measurements of metabolic state and behavioral repertoire with groups of flies that are optogenetically altered to express primarily higher energy costing behaviors versus lower energy costing behaviors. This would allow some probing at the question of whether performing more lower energy behaviors leads to higher longevity or if the idleness in longer living flies is a result of a lower energy budget overall.

While the analysis framework detailed in this paper should be generalizable to other data sets, including other species [38, 39] and neuroimaging data [40], the data used in this study present several limitations that need to be studied in future work. First, despite the wide range of behaviors we observed in our assay, many natural behaviors, including courtship and flying, were not measured here. Flight in particular is known to be more common in young flies [37] and likely a large source of oxidative stress and potential injury for the animals, likely creating more opportunities for decreased stereotypy and the degradation of behavioral performance. Additionally, due to technical constraints in our experimental set-up (e.g., food availability and long-term imaging quality), we only imaged flies for one hour during their life. Future studies would benefit from having longer recording epochs—up to the animal’s full lifetime—that could capture the influence of circadian rhythms and could more ably measure inter- vs. intra-individual variability across the lifespan and could potentially reduce any effects that emerge from the flies changing arenas jut prior to imaging.

Despite these limitations, this study points a way forward for using full repertoires of behavior to study aging and its physiological underpinnings. Although many of our energy budget-related analyses here could have been performed using center-of-mass tracking alone, by studying multiple actions simultaneously, it becomes not only possible to identify the age-relevant behavioral changes (here, primarily related to locomotion and slow/idle behaviors), but also to control for other possibilities such as the complexity of the animal’s usage of its behavioral repertoire or behavioral degradation and to isolate covariances between and within age groups. These measurements allow us to better predict how genetic or neural manipulations may affect aging across individuals and across the lifespan, as well as to make more specific predictions as to what types of physiological factors might play a role in these changes.

Materials and methods


The data consist of 304 flies (D. melanogaster), 150 of which are male and 154 of which are female, with ages ranging from 0 to 70 days of age (all from strain Oregon-R, see Table 1). Within 4 hours of eclosion, flies were isolated in a vial that was changed every other day for food (female flies were all unmated). While unmated and mated female flies might behave differently, we decided to focus on unmated flies in order to more readily facilitate comparisons between males and females. We anticipate that behavioral differences with age between mated and unmated animals (both males and females) could potentially be different and could be the basis for future studies.

Each fly was imaged from above for an hour while contained in a featureless dish with sloped sides to prevent aerial movements, following the approach detailed in [15]. Flies were placed into the arena using aspiration and provided 5 minutes to adapt to their environment before data collection. To reduce the effect of circadian rhythms, all recordings occurred between 10:00 and 17:00 with incubator lights on from 07:00 to 19:00. (We’ve measured the behavioral spaces as a function of when the data was taken and calculated the corresponding projections to quantify how time of day did not have an impact on how the flies behaved. See S1 and S2 Figs). The temperature was kept constant at 25° ±1°C.

Behavioral densities

We created our behavioral densities following the data pipeline outlined in [15]. This approach begins with image analysis (segmentation and alignment), projecting images onto postural eigenmodes, Morlet wavelet transforms [41], and a dimensionally reduced embedding via t-distributed Stochastic Neighbor Embedding [42]. We applied a watershed transform [18] to a Gaussian-smoothed (σ = 1) density containing points from all the flies in each grouping (All flies, all males, all females, 0–2 week old males, 0–2 week old females, etc.) in order to isolate the individual peaks. We defined behavioral epochs as lengths of time lasting at least 0.05s with low speeds in the behavioral densities, again following the approach of [15].

Gaussian-smoothed average curves

For Fig 3D, we applied a Gaussian-smoothed average according to the following equation: (7) Here, t is age, X is the original value of the eigenvector projections, y is the smoothed value of X, N is the number of flies, and σ corresponds to the standard deviation of the projections. For example, Fig 3D is a plot of y vs. t.

Error bars for these plots are generated through a bootstrapping procedure. Specifically, the data ({ti, Xi}) are sampled with replacement, and (7) is now applied to this re-sampled data set. This procedure is repeated 1, 000 times (each independently sampled), and the error bars are the standard deviations of these re-sampled curves at each point in time.

Synchronization parameter

By treating the fruit flies’ postural modes as a phase-locked oscillator, we use the Phaser algorithm [30] to estimate the behaviors’ phases, providing a measure of stereotypy. For each behavior, we use the algorithm to map the individual behavioral bouts to a phase variable between 0 and 2π, providing us with a phase reconstruction of our data that we can compare to the original trajectories (the methodology is the same as in [15]). To ensure the phase-averaged orbits are aligned between individuals and bouts, we calculate the maximum cross-correlation value between orbits for every postural mode separately, which gives our phase offset. After determining which modes contribute to each behavior (We use only modes that have mode-specific synchronization parameters of greater than 0.1 which means some behaviors will have a synchronization parameter of 0 if they don’t have any modes greater than 0.1), we calculate the synchronization parameter for age group κ for each behavior b across all postural modes γ according to: (8) where contains the postural projection time series from every bout of behavior b, is the phase-averaged orbits for the projection data in , is the number of postural modes used, and σ2(x) is the variance of x.

By taking the maximum value across the modes, we quantify our stereotypy for each behavior. This value ranges from 0 to 1, where 0 signifies no stereotypy and 1 signifies full stereotypy. This algorithm requires many bouts of each behavior in order to make the calculation.

Deterministic information bottleneck

The deterministic information bottleneck algorithm is an iterative algorithm that obeys a set of self-consistent equations: (9) (10) (11) Here, xS(n), yS(n + τ), tZ, is a normalizing function, and DKL is the Kullback-Leibler divergence between two probability distributions. For a given |Z| = K number of clusters, inverse temperature β, and random initialization of q(t|x), the equations are iterated until is satisfied, where is the previously defined cost function, . We performed 24 replicates of the solution using a range of β ∈ [0.01, 500] spaced exponentially, K ∈ [2, 30], and τ ∈ [1, 4096]. The optimization is done for each value of β until the convergence criterion is satisfied. The resulting solution is then used as the initial condition for the next value of β.

Power estimation model

We used the model from Nishii (2006) [22] to estimate the power consumption according to the following equations. The swing and stance phase describes the portion of motion where the leg is sweeping forward and when the leg applies pressure to the ground to propel the body forward, respectively.

Specifically, we model the power consumption using the following equations: (12) (13) (14) (15) Here, Hst is the heat dissipation during the stance phase, and Hsw is the heat dissipation during the swing phase. Similarly, Wst and Wsw denote the mechanical work done during the stance and swing phase, respectively. In these equations, n is the number of legs, γ represents the ratio of heat dissipation to mechanical work, and α is the amplitude of the torque required to maintain a bent leg posture. The rest of the parameters are defined in Table 2. We use values to calculate the specific power as a function of velocity, which we called e. We calculate e by summing together the power consumed from the heat and work during the stance and swing phase according to the following equations for , , , : (16) (17) (18) (19) (20) where T is the gait cycle period.

Table 2. Parameters used for locomotion energetics calculations.

Using this model, we can estimate the relative mechanical cost of grooming compared to locomotion by the quantity , since the animal is moving its legs but is no longer having to expend excess energy to propel itself forward during the stance phase. Across all speeds, this ratio is ≈ 10−7, justifying our treatment of all zero-velocity epochs as having the same energetic cost.

Supporting information

S1 Fig. Behavioral maps as a function of the time of day when the data was taken.

(shown for all flies, male flies, female flies, and the 0–2 week old female flies).


S2 Fig. Eigenvector projections as a function of time.

(as calculated in Fig 3D for the maps in S1 Fig).


S3 Fig. Average number of transitions per hour as a function of age.

Each data point is a different animal, and the line is the Gaussian-weighted average (error bars are standard error of the mean for the average).


S4 Fig. Entropy of the behavioral probabilities as a function of age for the males (left) and females (right) with a best fit line to estimate the value included.

Error bars for individual animals are smaller than the symbol size in the plot. The males have a slope of −0.00 ± 0.03 and the females have a slope of −0.01 ± 0.08.


S5 Fig. The third, fourth, and fifth eigenvalue timescales for each sex and age group.

Line thicknesses represent the standard errors of the mean.


S6 Fig. Trade-off curves computed from the deterministic information bottleneck for each sex and age group.


S1 Data. A .mat file containing all of the ages, sequences of states, and state densities for each of the 304 flies analyzed in this study.



  1. 1. Arking R. Biology of aging: observations and principles. Oxford University Press; 2006.
  2. 2. Ridgel AL, Ritzmann RE. Insights into age-related locomotor declines from studies of insects. Ageing Research Reviews. 2005;4(1):23–39. pmid:15619468
  3. 3. Seidler RD, Bernard JA, Burutolu TB, Fling BW, Gordon MT, Gwin JT, et al. Motor control and aging: Links to age-related brain structural, functional, and biochemical effects. Neuroscience & Biobehavioral Reviews. 2010;34(5):721–733. pmid:19850077
  4. 4. Bishop NA, Lu T, Yankner BA. Neural mechanisms of ageing and cognitive decline. Nature. 2010;464(7288):529–535. pmid:20336135
  5. 5. Kirkwood TBL, Austad SN. Why do we age? Nature. 2000;408(6809):233–238. pmid:11089980
  6. 6. Manini TM. Energy expenditure and aging. Ageing Research Reviews. 2010;9(1):1–11. pmid:19698803
  7. 7. Lorenz KZ. The comparative method in studying innate behavior patterns. Society for Experimental Biology. 1950; p. 221–268.
  8. 8. Kaletsky R, Murphy CT. The role of insulin/IGF-like signaling in C. elegans longevity and aging. Disease Models & Mechanisms. 2010;3(7-8):415–419.
  9. 9. Akintola AA, Heemst Dv. Insulin, Aging, and the Brain: Mechanisms and Implications. Frontiers in Endocrinology. 2015;6:13. pmid:25705204
  10. 10. Murphy CT, Hu PJ. Insulin/insulin-like growth factor signaling in C. elegans. WormBook. 2013; p. 1–43. pmid:24395814
  11. 11. Bourg EL. Patterns of movement and ageing in Drosophila melanogaster. Archives of Gerontology and Geriatrics. 1983;2(4):299–306. pmid:6422871
  12. 12. Bourg EL. The rate of living theory. Spontaneous locomotor activity, aging and longevity in Drosophila melanogaster. Experimental Gerontology. 1987;22(5):359–369. pmid:3123269
  13. 13. Fernández JR, Grant MD, Tulli NM, Karkowski LM, McClearn GE. Differences in locomotor activity across the lifespan of Drosophila melanogaster. Experimental Gerontology. 1999;34(5):621–631. pmid:10530788
  14. 14. Privalova V, Szlachcic E, Sobczyk L, Szabla N, Czarnoleski M. Oxygen Dependence of Flight Performance in Ageing Drosophila melanogaster. Biology. 2021;10(4):327. pmid:33919761
  15. 15. Berman GJ, Choi DM, Bialek W, Shaevitz JW. Mapping the stereotyped behaviour of freely moving fruit flies. Journal of The Royal Society Interface. 2014;11(99):20140672. pmid:25142523
  16. 16. Fernández-Moreno MA, Farr CL, Kaguni LS, Garesse R. Drosophila melanogaster as a model system to study mitochondrial biology. In: Mitochondria. Springer; 2007. p. 33–49.
  17. 17. Cande J, Namiki S, Qiu J, Korff W, Card GM, Shaevitz JW, et al. Optogenetic dissection of descending behavioral control in Drosophila. eLife. 2018;7:e34275. pmid:29943729
  18. 18. Meyer F. Topographic distance and watershed lines. Signal Processing. 1994-07;38(1):113–125.
  19. 19. Hernández DG, Rivera C, Cande J, Zhou B, Stern D, Berman GJ. A framework for studying behavioral evolution by reconstructing ancestral repertoires. eLife. 2021;10:e61806. pmid:34473052
  20. 20. Honegger K, de Bivort B. Stochasticity, individuality and behavior. Current Biology. 2018;28(1):R8–R12. pmid:29316423
  21. 21. Ayroles JF, Buchanan SM, O’Leary C, Skutt-Kakaria K, Grenier JK, Clark AG, et al. Behavioral idiosyncrasy reveals genetic control of phenotypic variability. Proceedings of the National Academy of Sciences. 2015;112(21):6706–6711. pmid:25953335
  22. 22. Nishii J. An analytical estimation of the energy cost for legged locomotion. Journal of Theoretical Biology. 2006;238(3):636–645. pmid:16084529
  23. 23. Mendes CS, Bartos I, Akay T, Márka S, Mann RS. Quantification of gait parameters in freely walking wild type and sensory deprived Drosophila melanogaster. eLife. 2013;2:e00231. pmid:23326642
  24. 24. Isakov A, Buchanan SM, Sullivan B, Ramachandran A, Chapman JKS, Lu ES, et al. Recovery of locomotion after injury in Drosophila melanogaster depends on proprioception. Journal of Experimental Biology. 2016;219(11):1760–1771. pmid:26994176
  25. 25. Berman GJ, Bialek W, Shaevitz JW. Predictability and hierarchy in Drosophila behavior. Proceedings of the National Academy of Sciences. 2016;113(42):11943–11948. pmid:27702892
  26. 26. Gauvrit N, Zenil H, Soler-Toscano F, Delahaye JP, Brugger P. Human behavioral complexity peaks at age 25. PLOS Computational Biology. 2017;13(4):e1005408. pmid:28406953
  27. 27. Halberda J, Ly R, Wilmer JB, Naiman DQ, Germine L. Number sense across the lifespan as revealed by a massive Internet-based sample. Proceedings of the National Academy of Sciences. 2012;109(28):11116–11120. pmid:22733748
  28. 28. Bialek W, Nemenman I, Tishby N. Predictability, Complexity, and Learning. Neural Computation. 2001-11;13(11):2409–2463. pmid:11674845
  29. 29. Strouse D, Schwab DJ. The deterministic information bottleneck. Neural computation. 2017;29(6):1611–1630. pmid:28410050
  30. 30. Revzen S, Guckenheimer JM. Estimating the phase of synchronized oscillators. Physical Review E. 2008;78(5):051907. pmid:19113155
  31. 31. Kenyon C. The Plasticity of Aging: Insights from Long-Lived Mutants. Cell. 2005;120(4):449–460. pmid:15734678
  32. 32. Tatar M, Kopelman A, Epstein D, Tu MP, Yin CM, Garofalo RS. A Mutant Drosophila Insulin Receptor Homolog That Extends Life-Span and Impairs Neuroendocrine Function. Science. 2001;292(5514):107–110. pmid:11292875
  33. 33. Broughton S, Partridge L. Insulin/IGF-like signalling, the central nervous system and aging. Biochemical Journal. 2009;418(1):1–12. pmid:19159343
  34. 34. Kenyon C, Chang J, Gensch E, Rudner A, Tabtiang R. A C. elegans mutant that lives twice as long as wild type. Nature. 1993;366(6454):461–464. pmid:8247153
  35. 35. Holzenberger M, Dupont J, Ducos B, Leneuve P, Géloën A, Even PC, et al. IGF-1 receptor regulates lifespan and resistance to oxidative stress in mice. Nature. 2003;421(6919):182–187. pmid:12483226
  36. 36. Moskalev AA, Shaposhnikov MV, Zemskaya NV, Koval LA, Schegoleva EV, Guvatova ZG, et al. Transcriptome Analysis of Long-lived Drosophila melanogaster E(z) Mutants Sheds Light on the Molecular Mechanisms of Longevity. Scientific Reports. 2019;9(1):9151. pmid:31235842
  37. 37. Carey JR, Papadopoulos N, Kouloussis N, Katsoyannos B, Müller HG, Wang JL, et al. Age-specific and lifetime behavior patterns in Drosophila melanogaster and the Mediterranean fruit fly, Ceratitis capitata. Experimental gerontology. 2006;41(1):93–97. pmid:16297586
  38. 38. Marshall JD, Aldarondo DE, Dunn TW, Wang WL, Berman GJ, Ölveczky BP. Continuous Whole-Body 3D Kinematic Recordings across the Rodent Behavioral Repertoire. Neuron. 2021;109(3):420–437.e8. pmid:33340448
  39. 39. Klibaite U, Kislin M, Verpeut JL, Sun X, Shaevitz JW, Wang SSH. Deep Behavioral Phenotyping of Mouse Autism Models using Open-Field Behavior. bioRxiv. 2021; p. 2021.02.16.431500.
  40. 40. Billings JCW, Medda A, Shakil S, Shen X, Kashyap A, Chen S, et al. Instantaneous brain dynamics mapped to a continuous state space. NeuroImage. 2017;162:344–352. pmid:28823826
  41. 41. Goupillaud P, Grossmann A, Morlet J. Cycle-octave and related transforms in seismic signal analysis. Geoexploration. 1984;23(1):85–102.
  42. 42. van der Maaten L, Hinton G. Visualizing data using t-SNE. J Mach Learning Research. 2008;9(2579-2605):85.