Animal behaviors often are decomposable into discrete, stereotyped elements, well separated in time. In one model, such behaviors are triggered by specific commands; in the extreme case, the discreteness of behavior is traced to the discreteness of action potentials in the individual command neurons. Here, we use the crawling behavior of the nematode Caenorhabditis elegans to demonstrate the opposite view, in which discreteness, stereotypy, and long timescales emerge from the collective dynamics of the behavior itself. In previous work, we found that as C. elegans crawls, its body moves through a "shape space" in which four dimensions capture approximately 95% of the variance in body shape. Here we show that stochastic dynamics within this shape space predicts transitions between attractors corresponding to abrupt reversals in crawling direction. With no free parameters, our inferred stochastic dynamical system generates reversal timescales and stereotyped trajectories in close agreement with experimental observations. We use the stochastic dynamics to show that the noise amplitude decreases systematically with increasing time away from food, resulting in longer bouts of forward crawling and suggesting that worms can use noise to modify their locomotory behavior.motor behavior | stochastic transitions | adaptation M any organisms, from bacteria to humans, exhibit discrete, stereotyped motor behaviors. A common model is that these behaviors are stereotyped because they are triggered by specific commands, and in some cases we can identify "command neurons" whose activity provides the trigger (1). In the extreme, discreteness and stereotypy of the behavior reduces to the discreteness and stereotypy of the action potentials generated by the command neurons, as with the escape behaviors in fish triggered by spiking of the Mauthner cell (2). But the stereotypy of spikes itself emerges from the continuous dynamics of currents, voltages, and ion channel populations (3, 4). Is it possible that, in more complex systems, stereotypy emerges not from the dynamics of single neurons, but from the dynamics of larger circuits of neurons, perhaps coupled to the mechanics of the behavior itself? Here we explore this question in the context of abrupt reversals in the crawling direction of the nematode Caenorhabditis elegans (5-7).Reversal behaviors of C. elegans are particularly interesting as the underlying neural circuitry includes a nominal command neuron, AVA (8), whose activity is correlated with forward vs. backward crawling (9). On the other hand, AVA is an interneuron in a network, and it is unknown whether the decision to reverse direction can be traced to a single cell. Even when AVA is ablated, reversals occur, although the distribution of times spent in the backward crawling state shifts (7). Further, most neurons in C. elegans do not generate action potentials, so even if a single neuron dominates the decision it is not obvious why the trajectory of a reversal would be stereotyped. As a complement to probing further in...