1 Introduction

Group dynamics is a topic of interest in both the field of sociology (Forsyth 2009; Lewin 1947; Hamilton et al. 2007; Perc et al. 2013) and that of biology (Krause and Ruxton 2002; Giraldeau and Caraco 2000; Couzin et al. 2002; Nowak et al. 2010). Several factors are considered to support the existence of groups: Social hunters see their feeding efficiency increase as groups can prey on larger animals (Schoener 1971; Krebs 1973) and can resist the competition of other groups (Puurtinen and Mappes 2009). Groups also come with antipredatory advantages as individuals see their chance of survival increase (Bertram 1978; Elgar 1989). Moreover, close contact with other individuals also increases reproductive opportunities (Bertram 1978) and information exchange (Valone 1989; Kurland and Beckerman 1985).

The question that motivates this work is: Can collective sensing lead to the emergence of groups in a population of individualistic agents, without making any assumption about the individual behavior? Collective sensing is an emergent phenomenon present in nature (Berdahl et al. 2013), and it refers to the ability of a group to sense what is beyond the capabilities of the individual. The additional information about the environment, conveyed through collective behavior, provides individuals with an evolutionary advantage (Elgar 1989; Seeley 2009; Hein et al. 2015; Torney et al. 2011; Bhattacharya and Vicsek 2014). Information plays a key role in nature: It enabled the evolution of complexity in nature (Szathmáry and Smith 1995), and it shapes individual behavior (Vergassola et al. 2007), group behavior (Skyrms 2010) and collective intelligence (Garnier et al. 2007). This paper argues that information can be responsible for the existence of groups. The information considered in this work is about food location, but it is also suitable for other interpretations, e.g., mating opportunities, suitable nest locations (Berdahl et al. 2013). For example, bird assemblages, e.g., communal roosts, are believed to have evolved as information exchanges (Ward and Zahavi 1973). The approach taken in this work is based on simulation and is general across species.

An agent-based simulation environment is used to model a population of agents which perform a foraging task in a patchy environment with hidden resources. Agents compete for the same limited resources, and their fitness depends on their foraging strategy. Two foraging strategies are compared: random walk, an individualistic strategy that ignores other agents, and gregariousness, which attracts agents toward crowded areas. Experiments show that gregarious agents have an evolutionary advantage over random walkers if food sources are rare, as it increases the foraging competition between agents, but collective sensing makes up for this disadvantage by increasing the efficiency of finding resources. The success of gregarious agents is compromised for high population densities as larger groups increase the rate of resource consumption, thus making exploration more successful than exploitation of known resources. Moreover, it has been shown that gregariousness can emerge from a population of individualistic agents as an evolutionary response to a reduction in resource availability [see also (Kurland and Beckerman 1985)]. The main result of this work is to show and explain how evolution and collective sensing interact so that gregariousness, and hence groups, emerges from a population of randomly initialized agents. Initially, evolution selects agents that forage for resources for longer periods. This individual behavior produces a pattern in the collective behavior that correlates to food location. Agents who are able to exploit this pattern through collective sensing, i.e., gregarious agents, gain an evolutionary advantage; therefore, groups form.

The contribution of this work can be summarized as follows: (i) It unifies and expands on the results of previous work in a framework that combines evolution and social learning via neural networks (Hein et al. 2015; Torney et al. 2011); (ii) it quantifies the effect of environmental conditions on the evolutionary fitness of different foraging strategies; (iii) it identifies environmental conditions under which a gregarious population can invade an individualistic population; (iv) it validates previous work by showing that, in a limited region of the parameter space, gregariousness is the evolutionary-fittest strategy; and (v) it shows empirically that groups can emerge from a randomly initialized population as a result of interactions between natural selection and collective sensing.

The article is structured as follows. In Sect. 2 this work is situated within the agent-based modeling literature. The experiments are described in Sect. 3, while the model is described in Sect. 4. Section 5 comments on the results and their implications, which are summarized and discussed in Sect. 6.

2 Literature review

Literature on agent-based modeling of group and societal issues spans over decades. Many agent-based models of society concentrate on the problem of cooperation (Helbing and Yu 2009) or coordination (Mäs et al. 2010). This work considers instead a simpler scenario where agents cannot actively communicate; thus, neither cooperation nor coordination is possible. A foraging task is modeled, where agents compete for the same pool of resources.

This work relaxes many common assumptions in the literature:

  • Environmental factors that favor groups, e.g., (Bowles and Gintis 2004; Montanier and Bredeche 2013; Torney et al. 2011). Cooperation cannot be achieved as agents are unable to communicate. Moreover, agents compete for the same resources and there are no advantages in being part of a group.

  • Kin selection, e.g., (Smith 1964; Hales 2000; Hammond and Axelrod 2006; Helbing and Yu 2008). Agents do not have any visible characteristic that make them recognizable as members of a group, e.g., Green Beard (Dawkins 1976), so they cannot develop mechanisms that favor kin.

  • Limited dispersal, e.g., (Hamilton 1964; Nowak and May 1992; Santos et al. 2006; Grund et al. 2013). Agents are randomly placed, and there is no mechanism that explicitly keeps offspring near their parents. Of course, this could still happen as a result of specific environmental settings, e.g., an offspring is born in a patch with food. Similarly, food is created randomly in the grid, so a new food source is not likely to be created near a depleted one.

  • Learning agents, e.g., (Axelrod et al. 2002; Németh and Takács 2007; Duan and Stanley 2010). Agent behavior is fully determined by their genetic characteristics.

Moreover, agents have bounded rationality (Simon 1982) as they have to cope with an imperfect perceptual system. Nevertheless, the conclusions are the same as other work on collective sensing, in that collective sensing is shown to evolve from a population of individualistic agents (Hein et al. 2015) if resources are scarce (Torney et al. 2011).

Table 1 Comparison of parameter values across experiments

The current work reproduces previous results in a general framework, where agent behavior is determined by a neural network, that does not make any assumption about the agent’s behavior. Previous work combined neural networks and evolutionary simulations, but the focus there was on individual learning (Hinton and Nowlan 1987; Gruau and Whitley 1993; Batali and Grundy 1996; Red’ko and Prokhorov 2010). Another body of literature looks at interactions between neural networks, in particular the emergence of language (Sukhbaatar et al. 2016; Lazaridou et al. 2016; Foerster et al. 2016) and cooperation (Tampuu et al. 2017), but evolution was not part of these studies. In the proposed model, gregarious behavior is not defined by the value of a parameter but is instead a region in a \(N \times M\)-dimensional parameter space, where N is the number of perceptions and M the number of actions. Moreover, agents are not able to emit any signal, instead evolving the capacity to respond to inadvertent social information (ISI) (Danchin 2004). Despite the generality of the model, gregariousness emerges as the evolutionary-fittest strategy under some environmental conditions, thus validating the previous results in a specific area of the parameter space.

3 Experimental setting

This section describes the goal and the design of the experiments, while results are presented and discussed in Sect. 4. Table 1 compares how the model parameters vary across these experiments. “Appendix” section describes how to reproduce the results.

The first experiment compares the efficiency of the two competing foraging strategies, random walk and gregariousness, and investigates how it changes for different parameter configurations. Each agent in the population is instructed to play one strategy, and strategies are compared by computing the average fitness, that is, the number of successful foraging actions at the end of the simulation, of individuals implementing that strategy. All simulations start with a population of the same size, and a fraction of it is initialized with the gregariousness strategy, which is obtained by initializing the weights of the neural network such that weights connecting the input and the movement action in the same direction are larger than the other weights. This configuration of weights ensures that at a large input in one direction corresponds to a large output at the corresponding movement action. If the input vector includes more than one large value, the winning action is determined by noise. The validity of this initialization is verified by means of a suit of tests, developed with the goal of classifying agent behavior in a linear scale from random walk to gregariousness strategy Burtsev and Turchin (2006). Each test presents the agent with a predetermined perception vector and records the chosen action. The action of foraging is tested by placing the agent in a location with food and no agents in sight; the action of moving north is tested by placing the agent in a location without food and with another agent to their north, and so on for the remaining movement actions. All tests are performed on all agents in the population, and the frequency of choosing the appropriate action is recorded: A high score in all tests means that the population behaves gregariously, while random walk scores close to 25% on all movement actions.

The second experiment looks at the evolution of competing foraging strategies. The experiment is set up as before, but agents reproduce with a probability proportional to their fitness and die with a probability proportional to their age (see Table 2). During every reproduction, the neural weights of the offspring are initialized with a mutated version of the parent’s weights. Mutations allow the behavior to drift away from the predefined strategies and adapt over time to the environment and to the competition. The evolution of the behavior of the two sub-populations is investigated in different environmental situations by means of the test suite described above.

Table 2 Description of constants in the simulation

The last experiment tests whether a population of randomly initialized agents can evolve gregariousness in response to a change in the environment. The population is initialized randomly, and a strategy is allowed to evolve. The strategy of the population is measured, as in the previous experiment, by testing the behavior of each agent at each timestep. The experiment is divided into two phases: In the first phase, the resources are abundant, while in the second phase they become scarce. The two phases are delimited by an event denominated famine, after which the quantity of the resources decreases gradually from the high value to the low value.

4 Methods

The effect of collective sensing in group formation is investigated by means of an agent-based evolutionary model (Epstein 1999). Simulation is a suitable tool and preferable over mathematical models for studying processes generated by individual interactions, as it allows for capturing their dynamics (Healy and Boudon 1967).

A population of agents performs a foraging task in a patchy environment (Bennati et al. 2017), which is modeled on previous work (Beauchamp 2000; Hamblin and Giraldeau 2009). The environment is a square grid with periodic boundary conditions in which a fixed number of patches contain a random positive quantity of food units. Food quantity is sampled from a uniform distribution with a mean of 100. This allows several agents to forage from the same resource for a short time. The total number of food sources is governed by a model parameter: Whenever a food source is exhausted, a new one is spawned at a random location.

Fig. 1
figure 1

Diagram of the neural network driving the agent behavior. Each link between a perception and an action represents a weight

Agent behavior is driven by a neural network which connects each perceptual input to each of the possible actions (see Fig. 1). Given a perception vector, the score of each action is the sum of all input values, multiplied by the corresponding weight that connects each input to the action, and by random noise. The action with the highest score is executed. If several actions obtain a similar score, the choice of one action over another is determined by a combination of noise, small differences in the input values and/or small differences in the weights. Behavior is selected by the evolutionary process among a vast set of alternatives, i.e., any of all possible mappings from any input vector to an action. The use of neural networks as controllers removes the need for modeling assumptions, e.g., a social parameter, which might limit the space of the possible behaviors. Agents are initially placed at random locations at the start of the experiment. At every timestep agents play their turn one after the other, in a random order: Each agent perceives the environment and executes one action. Randomization of the order of play is important as agents compete for the same rivalrous resources, i.e., food consumed by an agent is not available for other agents. Agents’ actions are either those of movement or of foraging: Agents can spend an action moving of one patch in any direction; alternatively, each agent can forage one unit of food from the current patch. Foraging is successful if the current patch contains at least one food unit, which is then consumed and removed from the patch. Foraging from a patch that does not contain any food produces a foraging failure. Fitness is defined as the number of successful foraging actions during an agent’s lifetime; thus, fitness measures the quality of the individual foraging strategy. For simplicity, we assume that energy is never consumed; thus, fitness is equivalent to energy.

Agents reproduce with a probability proportional to their energy. Reproduction spawns a new agent in the same patch, and energy is equally split between parent and offspring. The offspring’s behavior is determined by a mutated version of the parent’s weights. Mutations increase or decrease the original weights by a small random value. Agents are removed from the game with a probability proportional to their age. Both reproduction and death are modeled with a roulette wheel algorithm with stochastic acceptance [as in (Torney et al. 2011)].

Agents perceive the quantity of food and agents present in their surroundings. The perception of food is limited to only the current patch, while agents can be perceived within a given distance. This assumption is often verified in nature (Kurland 1973; Klein and Klein 1973; Kurland and Beckerman 1985) and is also a prerequisite for collective sensing. The perception mechanism does not distinguish the number of agents in each visible patch, and it aggregates instead the number of agents by angular direction (Strandburg-Peshkin et al. 2013). For simplicity, the field of view is subdivided into four areas corresponding to the cardinal directions and a parameter called “field of view” determines how far agents can see: A higher value implies that each of the four areas contains more patches; therefore, perception is more coarse-grained. A higher number of agents in one area correspond to a higher input signal: The more crowded the surrounding patches are, the higher the input signals; thus, if the population grows large, as in the evolutionary simulations, it becomes more difficult to perceive the signal carried by collective sensing. For this reason, it is assumed that the perceptual system can distinguish whether an agent is foraging or moving (Rosa Salva et al. 2014), and that agents are considered only if they are foraging (Bhattacharya and Vicsek 2014). This allows the supporting of larger populations in the environment. This assumption does not change the results qualitatively: Fig. 2 confirms that gregarious agents have higher fitness than random walkers, also when this assumption is relaxed (Bennati et al. 2016).

Fig. 2
figure 2

a Parameters of the simulation: field of view 4, 20 food sources, 10% gregarious agents, b parameters of the simulation: field of view 4, population size 20, 10% gregarious agents, c parameters of the simulation: population size 20, 20 food sources, 10% gregarious agents. Gregarious agents have an evolutionary advantage also when relaxing the assumption in their perception

Collective sensing allows individuals to perceive an invisible signal (food location) by means of a visible proxy signal (group dynamics); thus, the proxy signal must be visible where the other signal is not. In this case, the proxy signal is the location of other agents, as a higher concentration of agents correlates to the presence of a food source, under the assumption that agents remain on food sources [cf. position-dependent diffusion (Schnitzer 1993)]. Interestingly, this signal does not correlate with food availability. In fact the stronger the signal the more agents there will be foraging in a patch and the faster the food resource gets depleted.

5 Results

In the first experiment two foraging strategies, gregariousness and random walk, are compared. The fitness of a strategy is measured by the average number of resource units foraged by all agents implementing such a strategy. The main result is that gregariousness can be a more efficient strategy than random walk.

Fig. 3
figure 3

Average fitness for increasing population size. Initial size of the gregarious subpopulation: 50% (left) and 10% (right). Error bars represent 0.95 confidence intervals. Parameters of the simulation: field of view 4 and 50 food sources

If food sources are rare, gregarious agents have a higher evolutionary fitness than random walkers, which decreases with population size (see Fig. 3) as there is higher competition for resources. Abundance of food reduces the advantage of gregarious strategy over random walk, until it eventually disappears (see Fig. 4).

Fig. 4
figure 4

Average fitness for increasing number of resources. Initial size of the gregarious subpopulation: 50% (left) and 10% (right). Error bars represent 0.95 confidence intervals. Parameters of the simulation: population of size 20 and field of view 4

The gregariousness strategy allows agents to exploit information about the behavior of other agents to find sources of food. Whenever an agent finds a food source and exploits it, gregarious agents start converging and eventually exploit the same resource. This behavior leads agents to concentrate on food locations; thus, the fewer the food locations the more crowded they are. Large groups of agents in one patch produce a strong signal, which gregarious agents can exploit to their advantage. Gregarious agents compete with each other for the same resources, while random walkers explore the environment for new resources; therefore, a larger number of gregarious agents increase competition, hence reducing their average fitness (see Fig. 3). After an agent finds a new resource, it can exploit it exclusively until another agent reaches the same position; the longer an agent can exploit a resource exclusively, the higher the benefit from exploring the environment. Therefore exploration, i.e., random walk, becomes advantageous if food is abundant because the probability of randomly finding a new food resource increases.

Fig. 5
figure 5

Average fitness for increasing field of view. Initial size of the gregarious subpopulation: 50% (left) and 10% (right). Error bars represent 0.95 confidence intervals. Parameters of the simulation: population of size 20 and 50 food sources

The effect of the field of view of agents on their performance is shown in Fig. 5. Gregarious agents see their fitness decrease with an increasing field of view, an effect of the perception system’s design which aggregates the contents of multiple cells in a region. The more agents are in the field of view, the more difficult it becomes to distinguish whether the region contains a crowded location or many locations with few agents. This effect can be reduced with a more sophisticated perception system which is able to distinguish counts at the patch level.

Fig. 6
figure 6

Average population size over time. Dotted lines represent 0.95 confidence intervals. Parameters of the simulation: field of view 1 and 20 food sources

The second experiment repeats the comparison of two foraging strategies in an evolutionary setting, where agents can die and reproduce. Figure 6 shows the change in size of the two groups over the course of the simulation.

Fig. 7
figure 7

Evolution of strategy over time. Each line represents the frequency at which one action is executed according to the gregarious strategy: For example a value of 80% for action “left” indicates that action “left” is executed 80% of the time in a situation where gregarious strategy would dictate “left.” Left: Gregarious agents keep their behavior consistent with the gregarious strategy; right: Random walkers start with a random walk (each movement action is executed approximately 25% of the time) but rapidly adopt a gregarious behavior. Error bars represent 0.95 confidence intervals. Parameters of the simulation: initial population of size 20 and 50 food sources, field of view 1

This effect is explained by the evolution of the individual behaviors: Gregarious agents keep their behavior constant for the entire simulation (see Fig. 7 left), while random walkers adapt their behavior until they adopt the gregarious strategy (see Fig. 7 right). The whole population adopts the gregarious strategy at around time 10,000, which confirms that gregariousness is the evolutionary-fittest strategy.

Fig. 8
figure 8

Strategy evolution of random walkers over time. Average individual behavior over 24 different population. Parameters of the simulation: initial population of size 10 and 150 food sources. At timestep 20,000 the number of food resources is reduced to 5

In the third experiment a population of randomly initialized agents is let evolve in a variable environment. The strategy adopted by the population is evaluated by testing the behavior of each agent at every timestep (see Fig. 8). The simulation starts with abundant resources; agents are quickly selected on the basis of their ability to forage, but their movement is largely independent from the perceptual stimuli. At one point during the simulation, signaled by the red vertical line, the number of resources drops and the population rapidly adopts gregarious behavior in response to this change in the environment. One possible interpretation for this result is that some agents learn gregarious behavior at the beginning of the simulation, but the selective pressure is not enough to remove other less efficient strategies from the population until resources become scarce. Another interpretation is that selective pressure is high enough to remove inefficient strategies from the start; therefore, random walk is indeed the most efficient strategy when the resources are abundant. In order to distinguish between these two interpretations, it is necessary to measure the efficiency of a strategy; the frequency of foraging failures is chosen as a measure for strategy efficiency. The frequency of foraging failures approaches zero after 10,000 timesteps, which means that efficient strategies are selected at the beginning, supporting the second interpretation (see Fig. 9). This implies that, in a collective sensing scenario, gregariousness is the evolutionary-fittest strategy when food sources are rare, while random walk is the fittest strategy otherwise.

Fig. 9
figure 9

Inefficiency of foraging strategy. The graph shows the change over time in the frequency of inefficient actions, i.e., foraging failures, performed by the agents

This result validates previous work on collective sensing by showing that groups do indeed emerge from a population of individualistic agents without any assumption about their behavior, but only if resources are scarce. Moreover, it shows that evolution favors from the start strategies that produce a low number of foraging failures, thus creating a correlation between the location of agents and resources. Without evolution selecting for efficient strategies, collective sensing would not be able to track the location of food; therefore, gregarious behavior would not provide an evolutionary advantage.

6 Conclusion

This paper studies the role of collective sensing in the formation of groups in a population of individualistic agents. An agent-based model of a foraging task is used to study the evolution of foraging strategies in a patchy environment with limited resources. Agent behavior is determined by a neural network which translates perceptual inputs into actions, without any explicit model about the environment and the interactions between agents. The generality of results is increased by the relaxation of many common assumptions in the literature, thanks to a simple environment and the use of neural networks.

Two different foraging strategies are compared: random walk and gregarious behavior, i.e., moving toward other agents. Results show that gregarious behavior provides an evolutionary advantage at the individual level through collective sensing at the group level. Depending on the characteristics of the environment, and specifically in the case of scarce resources, this advantage can overcome the competition caused by sharing resources and groups can spontaneously form in a population of individualistic agents. Moreover, it is shown that the evolutionary-fittest strategy is random walk if resources are abundant and gregarious behavior if resources are scarce. This result, caused by the interaction between evolution and collective sensing, validates and unifies previous work on collective sensing under a general framework that combines evolution and social learning via neural networks.

The framework introduced in this paper is relevant to the literature about collective sensing as it reproduces results from different models, without requiring the assumption of a “social” parameter. A region in the space of environmental parameters is identified that invalidates these results, thus calling for further investigation about the effect of the environment on the previous models. A mechanism is individuated, i.e., there is a sudden decrease of resource availability which could have triggered the creation of gregarious behavior in a population of solitary individuals. The results presented in this paper may be of interest to the fields of biology and social sciences, as they introduce collective sensing as another mechanism that supports the existence of groups. Finally, a similar effect of resource availability on the efficiency of gregarious behavior could appear in other scenarios in which gregarious behavior is present, such as financial markets (Devenow and Welch 1996), product choice (Huang and Chen 2006) and forecasts (Cote and Sanders 1997).