Abstract
Hierarchy is a candidate organizing principle of ethology, where actions grouped into higher order chunks combine in specific ways to generate adaptive behavior. However, demonstrations of hierarchical organization in behavior have been scarce. Moreover, it remains unclear how such underlying organization allows for behavioral flexibility. Here we uncover the hierarchical and flexible nature of Caenorhabditis elegans behavior. By describing worm locomotion as a sequence of discrete postural templates, we identified chunks containing mutually substitutable postures along the dynamics. We then elucidated the rules governing their interactions. We found that stereotypical roaming can be described by a specific sequence of postural chunks, which exhibit flexibility at the lowest postural level. The same chunks get combined differently to produce dwelling, capturing non-stereotypical actions across timescales. We show that worm foraging is organized hierarchically —a feature not explainable via Markovian dynamics—, and derive a context-free grammar governing its behavior —which is different than a regular grammar, or a hidden Markov chain. In sum, in making the analogy with human language concrete (but not literal) our work demonstrates, in line with the foundational insights of classical ethologists, that spontaneous behavior is orderly flexible. Once more, investigating the humble nematode suggests that everything human has its roots in lower animal behavior.