An Index for Quantifying Flocking Behavior

One of the classic research topics in adaptive behavior is the collective displacement of groups of organisms such as flocks of birds, schools of fish, herds of mammals, and crowds of people. However, most agent-based simulations of group behavior do not provide a quantitative index for determining the point at which the flock emerges. An index was developed of the aggregation of moving individuals in a flock and an example was provided of how it can be used to quantify the degree to which a group of moving individuals actually forms a flock.

Moving in a coordinated way is common behavior throughout nature. Flocks of birds, schools of fish, herds of mammals, and even crowds of people are systems composed of a certain number of individual entities that coordinate their movements in order to achieve coherent displacement. All these systems share common properties that have been studied using mathematical models (Okubo, 1986;Tanner, Jadbabaie, & Pappas, 2003) and rule-based models (Aoki, 1982;Huth & Wissel, 1994). The latter implement rules that generate complex behavior and use agent-based computer simulation to create an artificial world where virtual agents react in accordance with the signals of the environment and act by following simple low-level rules to achieve an established goal (Maes, 1997). However, for an external observer it is often difficult to discriminate visually when a flock has been formed; an index that quantifies the flocking behavior of a group would be helpful for studying coordinated movements of animals and people, a topic that is common to fields like social psychology and ethology.
In accordance with the framework proposed by the adaptive-behavior approach (Meyer & Guillot, 1991), the complex behavior patterns observed in organisms are the result of those organisms' reaction to changes in the environment. Such reactions are guided by sets of simple low-level rules that result in the emergence of complex higher-level behavior (Beer, 1990;Brooks, 1991;Holland, 1995). In a seminal paper, Reynolds (1987) postulated an explanation for steering in artificial birds (named boids) guided by three rules applied to each individual: (1) each boid attempted to avoid collisions with its neighbors; (2) each boid attempted to stay close to its neighbors; and (3) each boid attempted to match the velocity of its neighbors. These rules were based upon the neighbors' local behavior and did not include centralized coordination, but produced collective motion along a common heading (Werner & Dyer, 1992;Zaera, Cliff, & Bruten, 1996;Camazine, Deneubourg, Franks, Sneyd, Theraulaz, & Bonabeau, 2001).
Based upon Reynolds' approach, agent-based simulation has been used to study the collective displacement patterns of a wide range of organisms, exploring factors such as the relationship between group behavior and lowlevel rules, body characteristics, and the group's environmental setting (Inada, 2001;Oboshi, Kato, Mutoh, & Itoh, 2002;Kunz & Hemelrijk, 2003). This approach is also applied to human displacements to understand and predict pedestrian flows and the movement of crowds of people (Schreckenberg & Sharma, 2002).
However, when flocking behavior is studied using agent-based simulation, flock detection is sometimes carried out merely b y observing the changes in the agents' locations over time on the computer screen. Indicators based on the parallelism of the agents' orientation such as polarity, calculated as an aggregation of the deviation of each agent's orientation from the average orientation, or those based on measures of interagent distance, which can be aggregations of nearest neighbor distance or distance to the flock center, have been used to analyze flock behavior (Kunz & Hemelrijk, 2003;Parrish & Viscido, 2005). Other proposed indicators show properties of flock stability, shape, or trajectory; a general quantitative theory of flocking has even been proposed (Toner & Tu, 1998). However, there is no simple index that integrates different measures and can discriminate between flocking and nonflocking behavior at each time step; such simple index is necessary in agent-based simulations to decide whether a flock has been formed or not (Zaera, et al., 1996). Therefore, to objectively quantify flocking behavior, an index of the degree to which a set of agents actually forms a flock was defined. A moving group as a whole is considered a flock when all the agents have similar headings and the distance between them is low enough; the heading of an agent at time I is defined as the vector connecting its location at t -1 with its location at t. For agents i and j at time t, a composite index is defined as follows: f,,(t) = tl(Aa,,(t)) . Z ( d t l ( t ) ) .

[I]
The index is the product of H, a function of the difference between the agents' headings at t (Aa,,(t)), i.e., the difference (in degrees) between the vectors defining the headings, and Z, a function of their distance at t (d,,(t)): Both functions can yield values of between O and 1. Function H is equal to 1 when the agents' headings are identical, i.e., Aa,(t) = 0", and is equal to O when the two agents face opposite directions, i.e., Aa,(t) = 180". Function Z is the inverse logistic function, where y and 6 are function parameters, and m is the maximum interagent distance that is judged to define them as a group, given the dimensions of the world (y> 0, O < 6 < 1; m > 0); this function tends toward 1 when the distance between the two agents is close to O (in which case the exponential function yields a high value), and it tends toward O when the distance is great (in which case the exponential function yields a value close to 0). Thus, at time t , the aggregation index for agents i and j approaches 1 only when both H and Z approach 1, and approaches O when either H or Z approaches O. The more agents face similar directions and the closer they are, the greater their aggregation index; on the other hand, if the agents have identical headings but are far away from each other, or if they are close to each other but their headings are opposite, their aggregation index is low.
The inverse logistic function is used to ensure that when the distance between agents is either small or great, smooth changes in distance cause smooth changes in function Z. However, when the distance reaches a critical value, a smooth change in distance causes a large change in Z. Fig. 1 shows three inverse logistic functions for specific parameters y=5 (flattest curve), y= 10 and y=2O (steepest curve); for the three curves, 6=0.5, m =2O. Note that Z decreases as the distance increases, and that the sharpest descent occurs for distances of around 6 . m= 10. The greater the y value, the more abrupt the descent. On the other hand, the distance at which the abrupt change occurs can be adjusted by changing the 6 value; e.g., if 6=0.8 and m=2O, the critical distance is 16. Then given m, setting 6 at 0.5 sets the changing point at m/2. Given that extreme y values produce radical discrimination or no discrimination at all, it would seem reasonable to assign it medium-range values.
A global aggregation index or flocking index for all the agents present is defined as the arithmetic mean of the &(t) indices, N being the total number of agents: Values of F(t) range between O and 1; when F(t) = 1, the agents move in a coordinated and compact fashion in the same direction, and when F(t) = 0 , they are scattered and move in a disorderly fashion. Thus, F(t) can be evaluated at each time unit t by computing the distances between the agents and the differences between their headings; values of F(t) are a time series that indicates when the agents move as a flock and whether the flock is maintained over time. If the agents' behavior is governed by some rules that make the flock emerge from initial disorderly movement, then an abrupt increase in F(t) indicates such a phase transition. Inverse logistic function used to calculate index F. It describes the effect of the real distance d between two agents on the Z function. The curves correspond to parameters y= 5 (flattest curve), y= 10 and y=20 (steepest curve); for the three curves, F=0.5, m=20.
Yet a group of agents moving randomly and not in a coordinated way might theoretically result in F(t) > 0. Therefore, to evaluate F(t) appropriately, it is necessary to know the distribution function of the index for specific N, m, y, and 6 values in case the agents have random locations and headings. The distribution function can be estimated by assigning random coordinates and headings to the N agents repeatedly and independently many times (say, 10,000 times), and by calculating F each time; by averaging the Fs, an estimate of their mathematical expectancy (E[F]) can be obtained. However, actual values of F(t) depend o n t h e number of agents (N) and the size of the world in which they move (m); therefore, to compare flocks with different group and world sizes, the F(t) indices must be converted into a common, or standardized, value. Cohen's (1960) kappa coefficient provides a way to compare an observed proportion of agreement with the proportion that is expected under the hypothesis of chance agreement, by calculating the ratio of the difference between observed and expected to the maximum possible difference. As F(t) and E[F] are observed and expected proportions, the same rationale as that used for calculating kappa can be applied in order to calculate the desired standardized index. Thus, the F(t) index can be converted into a kappa-like coefficient: In other words, at each time step, the difference between the obtained F(t) and its expected value in the case of random movement is divided by the maximum possible difference. Therefore, ~~( t ) can be viewed as the degree to which agent interaction actually causes a flock: a flock exists when ~~( t ) > O (i.e., the agents' headings are similar and their distances are shorter than in the random case), and the closer ~~( t ) is to 1, the more defined the flock is (i.e., the more similar the agents' headings are and the shorter the distance between them). When the group movement is completely disorderly, ~~( t ) = 0; although negative values of ~~( t ) are theoretically possible, they are likely to be negligible and due to sample fluctuation.

METHOD
Using agent-based simulation, groups of agents that act according to specific low-level rules of interaction were generated to check if the apparent flocks shown on the computer screen matched the results indicated by ~~( t ) over time, and whether the index distinguishes between flocking and nonflocking behavior, and between different kinds of flocks (i.e., compact, disperse, etc.). An agent-based software, P-FLOCK, written in the Borland C language, was used. It is based on P-SPACE, a program that simulates spatial behavior and has been presented elsewhere (see Quera, Beltran, Solanas, Salafranca, & Herrando, 2000;Quera, Solanas, Salafranca, Beltran, & Herrando, 2000;Beltran, Salas, & Quera, 2006).' In P-FLOCK, agents move on a two-dimensional torus world sized 120 x 90 cells; each cell can only be occupied by one agent at a given time step. Agents have a scope of attention (a circular sector which is defined as an area to which the agent pays attention at time t, so that only the other agents within that area are taken into account) and move according to a gen-'Both P-FLOCK and P-SPACE can be downloaded from ~mw.ub.es/comporta/~cai/l'a~inas/ gcai-Downloads.htm. era1 rule: each agent moves within its local neighborhood of cells to minimize its local dissatisfaction. At each time unit, agent dissatisfaction depends on the discrepancy between the real distances it actually maintains from the other agents and the ideal distances it wants to keep from them. Thus, at each time unit, an agent moves to that location within its current neighborhood for which its dissatisfaction is minimum. Ideal distances change dynamically, and their change is caused by the outcomes of the interactions between the agents.
The model describing how ideal distances change is a set of low-level rules, called the Flock Synthesis Rules. According to this model, agent i initially moves without bearing in mind any other agent ,j, until its real distance from agent j is less than some critical value A. When this value is reached, the Flock Synthesis Rules are activated in agent i with respect to agent ,j; from that moment on, the ideal distance experiences two different kinds of change: smooth and abrupt. A smooth change is caused by agent i adapting to agent j's movements, which may cause the ideal distance to increase or decrease by constant amount of C at each time step; an abrupt change can occur when the ideal distance remains constant during a certain time period B, in which case the ideal distance is increased by a large amount, and later on it will be decreased to the value it was prior to the change. Smooth changes in the ideal distance are governed by discrepancies between what agent i predicts regarding its future real distance to agent j and the actual change in real distance once both agents have moved. Table 1 details how decisions regarding the increase or decrease in the ideal distance are made at each time step; these decisions are made for each agent i with respect to each other agent j if the Flock Synthesis Rules are activated for agent i towards agent j, and if agent ,j is within the scope of attention of agent i (i, j= 1 to N). In a set of simulations, N=20 agents were created and initially assigned random coordinates and headings. The agents' scope of attention was set at 180" and the parameters for calculating the F index were set at Y= 10, 8= 0.5, and m=20. The scope of attention and world settings remained constant for all conditions. Parameters A, B, and C of the Flock Synthesis Rules were systematically varied through three conditions: A = 60, B = 6, C = 0.01; A = 6 , B = 6 , C=0.01; and A = 6 , B=100, C=0.01. These conditions were chosen because previous simulations showed clear differences in the behavior of the agents on the computer screen. The three conditions produced, respectively, a compact flock (the agents remained very close to each other and had approximately the same headings), a scattered flock (the agents remained at greater distances from each other than in the preceding condition but had very similar headings), and no flocking behavior, respectively. The flockrng behavior observed on the computer screen and the F(t) index were DECISION  Smooth change in the ideal distance of agent z with re-z distance to agent j at t+ 1 agents i and , i have moved spect to agent j at t+ 1 Approach E Real distance at t + 1 will be less than at t , Actual approach > predicted Ideal distance decreases; prediction is positively rewarded.
% H because agent i is moving towards agent Actual approach = predicted j's current location at t. Actual approach < predicted

No Change
Real distance at t + 1 will be equal to that Real distance has changed at t , because agent i is not moving.
Real distance remains the same Distancing Real distance at t + 1 will be greater than at Actual distancing > predicted t, because agent i is moving away from Actual distancing = predicted agent j's current location at t.
Actual distancing < predicted Note.-Increases and decreases in the ideal distance are alurays made to C in small, Ideal distance does not change. $ Ideal distance increases; prediction is negatively rewarded.

B
Ideal distance does not change.

2
Ideal distance increases; prediction is negatively rewarded.
constant amounts. C is set in advance for a specific simulation. compared. For each condition program P-FLOCK was run for 20,000 time steps. At each time step of the simulation, the program calculated both F(t) and its corresponding ~~( t ) . from time unit 4,000 onward. Finally, in the third condition (A=6, B = 100, C=O.OI), no flocking behavior was observed on the computer screen, i.e., the agents remained far away from each other and their headings did not appear to be coordinated; accordingly, ~( t ) values remained very close to zero throughout the simulation (see Fig. 2). Snapshots of the group of agents as observed on the screen can be seen in Fig. 3.

RESULTS
A simple and potentially useful index of flocking behavior has been presented. The results provide an overview of its aim and usefulness: the F index (converted into a kappa-like index for ease of interpretation) has proved to be sensitive to the different flocking patterns that can be generated by the model of Flock Synthesis Rules, since it reached nearly the maximum value (around 1) for a compact flock, medium values (around 0.5) for a scattered one, and minimum values (around 0 ) when no flocking behavior was apparent. The index can therefore be effectively used to quantify the aggregation of moving individuals as the degree to which they move along a common heading while keeping the distance between them small. The index can also be useful to compare the data from different studies on flocking behavior.