Dynamic Organization of Behaviors in a Large Scale Boids Model

Norihiro Maruyama, Daichi Saito, Yasuhiro Hashimoto, and Takashi Ikegami

The Graduate School of Arts and Sciences, University of Tokyo, Tokyo, Japan {maruyama, saito, yasuhiro, ikeg}@sacral.c.u-tokyo.ac.jp http://sacral.c.u-tokyo.ac.jp

Abstract. Simulation of a half million flocks is studied by using a simple boids model originally proposed by Craig Reynolds. It was modeled with a differential equation on the 3D space with a periodic boundary. Flocking is collective behavior of active agents, which is often observed in the real world (e.g. starling is a good example). It is, nevertheless, hard to define flocks (or their boundaries) in a rigorous way. First of all, even in a same swarm, the members are constantly updated, and secondly, flocks sometimes merge or divide dynamically. In order to define individual flocks and to capture the dynamic features of them, We applied a DBSCAN and a non-negative matrix factoriza- tion (NMF) to the boid dataset. Flocking behavior has different kind of individual dynamics depending on the size of flocking. A function of different flocks is discussed with the use of NMF.

Keywords: Flocking · Boids · NMF · Parallel Computing

1 Introduction

Collective behaviors can be qualitatively different by increasing the number of agents, i.e. a colony or group size. In the actual observation, e.g., the individual bees change their behaviors depending on the colony size [9]. Also the fish change their performance of sensing the environmental gradient depending on the school size.[7]. In the previous works [6, 3, 5], we simulated half a million birds ensemble by using a boids model [8] and found that qualitatively different behavior emerges when the total number of individuals exceeds 10,000 or so. Flocks of different sizes and forms interact in a parallel motion. Different types of fluctuation (i.e. density or velocity fluctuation) become dominant in different size flocks; a corre- lation of the local density fluctuation becomes dominant in the larger size flocks and that of the velocity fluctuation dominates in the smaller size flocks. A purpose of this paper is to revisit the collective behavior of the large flock- ing behavior with a more effective simulation algorithm. On simple clustering methods such as DBSCAN or SOM (Self-Organizing Map) , we consider the different velocities of boids, having better clustering results [5]. In this paper, we compare the results of DBSCAN clustering with the results of the Non-negative Matrix factorization (NMF) to study the dynamic modes of flocking behavior. 2 N. Maruyama et al.

2 Simulation Model and Method

2.1 Boids Model The dynamics of boids is described by three simple rules based on Craig Reynold’s original model [8]. We translated it as the differential equation on the 3D space with a periodic boundary condition.

Σj∈Satt xj xi − xj ∆vi = Watt(xi − ) + Wrep(Σj∈Srep ) natt |xi − xj |

Σj∈Sali vj +Wali(vi − ) nali

The position of each boid (i) is updated based on the velocity, vi, deter- ministically and iteratively. The attraction, repulsion, and alignment terms are represented by the first, second, and third terms, respectively. Each rule has an interaction range around each agent, as denoted by Satt, Srep, and Sali, respec- tively. In the equation, the amplitudes of those interactions are given by Watt, Wrep, and Wali, respectively. The interaction ranges, with a 3D circular sector of their angles towards the front, are fixed as π/2, π/2, and π/3, respectively. In or- der to avoid any excess increase or decrease in speed, we bound the amplitude of speed between Vmin and Vmax, which we think as an important parameters. The system is investigated with parameter set on table 1 which is same as our pre- vious work [6]. The parameter values including the density of boids are selected to observe larger flocks.

Parameter Value Parameter Value range of attraction 0.05 [unit] angle of attraction π/2 range of alignment 0.05 [unit] angle of alignment π/3 range of repulsion 0.01 [unit] angle of repulsion π/2 field size 0.4 - 3.2 [unit] number of individuals 2,048 - 524,288 max speed 0.005 [unit/step] min speed 0.001 [unit/step] Watt 0.008 Wali 0.06 Wrep 0.002 initial position randomly distributed initial velocity randomly distributed time step increment 1 density 16,384 [num/unit3] boundary condition periodic Table 1. Parameter values used in this simulation

2.2 Parallelization Unlike the previous works which are based on GPGPU computations [1, 2, 6], we carry on the parallelized simulation with a computer cluster for investigating the dynamics of large scale populations. The advantage of using a computer Dynamic Organization of Flocking Behaviors in a Large Scale Boids Model 3 cluster is its high scalability for the number of agents comparing with GPGPU computation. Initially we simply partitioned the three dimensional simulation space into subspaces, which corresponded to each simulation nodes. Each simulation node calculates agents belonging to its node, then nodes exchange information of the agents leaving/entering with the neighbouring nodes. Since the computer cluster we used has six-dimensional inter-node connections (K-computer), three dimensions is adopted for arranging the simulation space. At one simulation node, a simple algorithm that calculates a distance matrix of all agents needs the order of O(N 2) computation time. But if we assume that there is an upper limit on the local density and the interaction distance between individuals is sufficiently shorter with respect to the size of the space, this computation time can be reduced to O(N). In particular, the simulation space is divided into a grid with the size of about twice as large as the interaction distance, and individuals belonging to each grid are managed as a list. It is only necessary to calculate the distance matrix in this list and its list of the adjacent grid (see below Figure 1).

Fig. 1. Diagram of parallelization methods on a simulation node. 4 N. Maruyama et al.

2.3 A Classification algorithm

We visualize the boids dynamics in the 3D space as in Figure 2.

Fig. 2. 2D projection of result of simulation with N = 32768. ball-like patterns (large black lump) and snake-like (string-like) patterns can be observed. We can recognize string-like swarm connects ball-like swarm by individual fast flowing.

As is seen in this figure, agents are inhomogeneously distributed in the space by taking characteristic shapes. Those flocks are mutually interacting each other and dynamically changing. As is discussed in the previous works [6, 3], the size distribution of different flocks show a power-law behavior and different kinds of fluctuation exist for different flock sizes [5]. However all these analysis depend on how we classify flocks with what types of algorithm we apply. We mainly applied two kinds of clustering algorithm; DBSCAN is a density based clustering algorithm, which (briefly speaking) gath- ers the internal data points that are surrounded by more than k points and the peripheral points that has the internal points in their neighbors but sparsely surrounded. Figure 3 demonstrates an example of classifying the distinct flocks after di- viding all the agents into two classes by their velocity amplitude. As is seen in the figure, we have slow ( a broad peak on the left) and fast boids (a sharp peak on the right) agents. Then we apply DBSCAN to each group to see how different flocks distribute over space, which are displayed on the low column. Dynamic Organization of Flocking Behaviors in a Large Scale Boids Model 5

Fig. 3. Top: Distribution of velocity and velocity fluctuation of whole individuals. Bottom: Result of DBSCAN clustering for fast group and slow group. Different color label different flocks. 6 N. Maruyama et al.

Most unexpected observation here is that fast agents exist on the surface of larger size flocks and also they compose string-like flocks. Flocks are organized temporary and will be generated or collapsed spontaneously. By the simple ob- servation, agents are escaping from large flocks by forming string-like pattens. We thus adopted the following method to extract dynamic mode associated with the spontaneous organization and collapsing of flocking behaviors.

2.4 NMF analysis

To understand when and which type of mode of flock’s dynamics are organized and collapsed, we used non-negative matrix factorization (NMF), which has become a popular decomposition algorithm ([4]). Given a non-negative matrix X (m × n matrix X), NMF finds the non-negative matrix factors W and H such as: X ' WH, In the case of the current analysis, n is the number of individual agents and m is the size of the time frame. Each entry of the matrix is given by magnitude of the agent’s velocity. This matrix can be approximately factorized into the m × r matrix W and the r × n matrix H. Since relatively a few number of basis vectors are used to represent any data vectors, a good approximation can only be achieved if the basis vectors discover the structure that is latent in the data. We here adopted the generalized Kullback-Leibler (KL) divergence to determine the matrix factorization. A critical parameter in NMF is the factorization rank r, which defines the number of dynamic mode used to approximate the target matrix. Using the NMF method and the target matrix, a common way of setting the value of r is to try different values and compute some result quality measures, and then choose the best value for r accordingly. Here we arbitrary choose r that seem to correspond to flocking behaviors. The results with a more sophisticated way of choosing r will be presented at the conference. As we see in this figure (Fig. 4), the extracted modes do not correspond to actual flocking behaviors, partially because no spatial information is taken into account in this analysis. Also it should be noted that the larger flocks have the slower moving agents. So that the agents in a larger flock will not be visible in the second column of this figure. On the other hand, we see that some of the extracted modes correspond to actual flocks in space. For example, in the mode #1 of time step equals to 2400, a chunk of agents is escaping from or coming into the main big one. This phenomena is captured by NMF as the dominant contribution to a system in the first and second column. In the other words, escaping boids from a large but slow flock have faster speed and string-like shape. This picture is consistent with the previous DBSCAN classification. We expect from this figure and also by applying NMF to other time frames, we hypothesize that spontaneous collapse of flocks can be captured by the NMF analysis. Dynamic Organization of Flocking Behaviors in a Large Scale Boids Model 7

Fig. 4. Result of non-negative matrix factorization conducted for the data from time step 1500 to 2500 and r = 64. Top: Visualization of component matrix of velocity extracted by NMF. The image shows the most dominant 16 rows in 64 components. Red is high and blue is low value. Horizontal axis corresponds to time. Components matrix value weighted by the number of agents. Therefore, it can be regarded as representing momentum of the dynamics mode. Middle: 3 top dynamics mode which detected by NMF (corresponds to top 3 rows on top figure). Bottom: 3 visualization of boids at time step = 1700, 2050 and 2400. Red points indicate individuals belong dynamics mode #0, #1 and #2. 8 N. Maruyama et al.

3 DISCUSSION

Large scale collectives can be a source for emergent phenomena [3]. Consider- ing biological organizations (e.g. DNA, cells, organs, bodies,,, ), we expect new structures to emerge for each spatial scale of the order of roughly 3 or 4. Yet the flocks organization is hard to define formally, we tried to define it in the space time entity. NMF analysis in this paper provides one candidate of finding such emergent phenomena. More sophisticated analysis by using NMF will be presented at the conference.

4 Acknowledgements

This study is supported by MEXT as “Challenging Research on Post-K com- puter” - Modeling and Application of Multiple Interaction of Social and Eco- nomic phenomena (Project ID:hp180208) and partially supported by the KAK- ENHI project A “Organization and Realization of based on the Ethological and Life-theoretical Investigations” (17H01249).

References

1. Erra, U., Frola, B., Scarano, V., Couzin, I.: An Efficient GPU Implementation for Large Scale Individual-Based Simulation of Collective Behavior. In: 2009 Interna- tional Workshop on High Performance Computational Systems Biology. pp. 51–58. IEEE (oct 2009). https://doi.org/10.1109/HiBi.2009.11 2. Husselmann, A.V., Hawick, K.A.: Simulating Species Interactions and Com- plex in Multiple Flocks of Boids with GPUS. In: Parallel and Dis- tributed Computing and Systems. ACTAPRESS, Calgary,AB,Canada (dec 2011). https://doi.org/10.2316/P.2011.757-012 3. Ikegami, T., Mototake, Y.I., Kobori, S., Oka, M., Hashimoto, Y.: Life as an emergent phenomenon: studies from a large-scale boid simulation and web data. Philosophical transactions. Series A, Mathematical, physical, and engineering sciences 375(2109), 20160351 (dec 2017). https://doi.org/10.1098/rsta.2016.0351 4. Lee, D.D., Seung, H.S.: Learning the parts of objects by non-negative matrix fac- torization. Nature 401(6755), 788–791 (oct 1999). https://doi.org/10.1038/44565, http://www.nature.com/doifinder/10.1038/44565 5. Maruyama, N., Hashimoto, Y., Mototake, Y., Saito, D., Ikegami, T.: Revisiting Classification of Large Scale Flocking. In: SWARM 2017: The 2nd International Symposium on Swarm Behavior and Bio-Inspired Robotics. pp. 307–310 (2017) 6. Mototake, Y., Ikegami, T.: A Simulation Study of Large Scale Swarms. In: SWARM 2015: The First International Symposium on Swarm Behavior and Bio-Inspired Robotics October 28-30, Kyoto, Japan. pp. 446–450. No. i (2015) 7. Puckett, J.G., Pokhrel, A.R., Giannini, J.A.: Collective gradient sensing in fish schools. Scientific Reports 8(1), 1–11 (2018). https://doi.org/10.1038/s41598-018- 26037-9, http://dx.doi.org/10.1038/s41598-018-26037-9 8. Reynolds, C.W., W., C., Reynolds, W., C.: Flocks, and schools: A distributed behavioral model. In: Proceedings of the 14th annual conference on Computer graph- ics and interactive techniques - SIGGRAPH ’87. vol. 21, pp. 25–34. ACM Press, New York, New York, USA (1987). https://doi.org/10.1145/37401.37406 Dynamic Organization of Flocking Behaviors in a Large Scale Boids Model 9

9. Smith, M.L., Koenig, P.A., Peters, J.M.: The cues of colony size: how honey bees sense that their colony is large enough to begin to invest in reproduction. Journal of Experimental Biology 220(9), 1597–1605 (2017). https://doi.org/10.1242/jeb.150342