In this section, we present how to analyze the meso-level dynamics of a swarm-based algorithm using the interaction network. We select the PSO algorithm because of its simplicity and extensive use in several applications.

Particle Swarm Optimization (PSO) is a population-based optimization method that relies on the interactions of individuals sharing the best positions they found during the search process (Kennedy and Eberhart 1995). The method—inspired by the social behavior in flocks of birds—consists of a population of simple reactive agents (particles) that explore the search space by locally perceiving the environment and interacting among themselves to improve their solutions.

In the standard definition of the PSO, each particle *i* consists of four vectors in a *d*-dimensional search space: its current position \(\vec {x_{i}}(t)\), its best position found so far \(\vec {p}_{i}(t)\), its velocity \(\vec {v}_{i}(t)\), and the best position found by its neighbors \(\vec {n}_{i}(t)\) (Bratton and Kennedy 2007). The position of each particle represents a candidate solution to a *d*-dimensional continuous optimization problem, and the swarm moves through the problem search space seeking better solutions. To enable this capability, all particles change their positions, at each iteration *t*, according to their velocities \(\vec {v}_{i}(t)\) which are updated based on the personal best position \(\vec {p}_{i}(t)\) and the social best position \(\vec {n}_{i}(t)\). Researchers use different ways to update the position of the particles, but the update equation generally aims to maintain the coherence of the particles through an inertia term and adjust the trajectory using cognitive and social information. In our study, we use the so-called constricted PSO (Clerc and Kennedy 2002).

The particles in the swarm only interact with a subset of the swarm. The swarm topology defines the infrastructure through which particles communicate and thus enables the particles to retrieve information from other particles (i.e., their neighbors). At each iteration *t*, each particle *i* seeks for its best neighbor *n*_{i}(*t*) in its neighborhood (i.e., the one with the best solution so far). The topology influences the social interaction within the swarm and has been shown to impact the swarm performance (Mendes 2004; Bratton and Kennedy 2007). Clerc proposed a somewhat different definition of swarm topology—the so-called *graph of influence*—which explicitly includes the social information and presents directed edges (Clerc 2010). Regardless of definition, however, the swarm topology only refers to the structure for the potential exchange of information and neglects effective interaction among particles.

In the particle-swarm context, exploration and exploitation refer to the ability of individuals to broadly explore the whole search space or focus on a particular area (Kennedy and Eberhart 2001). An exploration–exploitation imbalance often leads to a poorly explored search space. To better understand this imbalance, researchers study the diversity and the dynamics of the swarm. The literature often focuses on the *spatial* diversity (Shi and Eberhart 2008; Olorunda and Engelbrecht 2008; Shi and Eberhart 2009), analyzing the outcomes of social interaction such as the positions or velocities of the particles in the search space. These approaches have succeeded in developing novel mechanisms to improve the performance of the algorithm. Yet, with these approaches, we fail to understand the *underlying social interaction* driving the swarms to undesired states (e.g., lack of diversity, premature convergence) that new mechanisms try to avoid.

Still, a few works have attempted to analyze the particles’ interactions in order to examine the swarm behavior. Some of these efforts analyzed the impact of the infrastructure of the swarm communication on the swarm performance (Mendes et al. 2004; Mendes 2004; Wen-Bo et al. 2016). Though these studies neglected the actual interactions between particles, they showed that bounding social interaction influences the swarm behavior. Oliveira et al. proposed to examine the actual interactions among particles in order to assess the swarm (Oliveira et al. 2013). They proposed the analysis of the swarm using a network in which the nodes (particles) are connected if they share information in a given iteration and later extended the concept to capture historical information (Oliveira et al. 2014, 2015, 2017). Later on, Pluhacek et al. provided visualizations of the interactions in the swarm (Pluhacek et al. 2016).

In the next subsections, we define the *interaction network***I** to assess the swarm using the methods developed by Oliveira et al. (2016). With this definition, we can uncover the interplay of swarm dynamics, swarm performance, and social interaction.

### A network for the particle swarm optimization

To examine a swarm system from the meso-level perspective of the swarm social interaction, we need to build the network to capture the structure and dynamics of the social influence exerted among individuals. In the case of the PSO algorithm, social interaction occurs when a particle *i* updates its position based on the position of a particle *j*. This happens when *j* is the best neighbor of *i* at a given iteration; that is, *n*_{i}(*t*)=*j*.

Here we use a simple (yet powerful) definition of interaction network **I**(*t*) in which the weight of an edge (*i*,*j*) is the number of times the particle *i* was the best neighbor of the particle *j* or vice-versa until the iteration *t* (Oliveira et al. 2014). We use a time window *t*_{w} to control the recency of the analysis, thus the interaction network at iteration *t* with window *t*_{w} is defined as the following:

$$ \mathbf{I}_{ij}(t) = \sum_{t'=t-t_{w}+1}^{t}\left[\delta_{i,n_{j}(t')} + \delta_{j,n_{i}(t')}\right], $$

(1)

with *t*≥*t*_{w}≥1 and where *δ*_{i,j} is Kronecker delta. In this definition, nodes (i.e., particles) are connected by an edge with weight equals to the number of times two particles shared information in at most *t*_{w} iterations before the iteration *t* (Oliveira et al. 2014). The time window *t*_{w} tunes the frequency–recency balance in the analysis. High *t*_{w} makes the network dominated by most frequent interactions; low *t*_{w} only includes most recent interactions, and when *t*_{w}=1 we have instantaneous interactions.

Note that the definition of an interaction network for a swarm system depends on the rules that promote social interaction in the system. Here we pinpointed that, in PSO, social interaction between *i* and *j* occurs when the particle *i* updates its velocity \(\vec {v_{i}}\) using the position of a particle *j*. This definition of **I** is a simple one that includes only the occurrence of social interaction between particles. More complex definitions may include edge direction or other aspects of the algorithm, such as the social constant *c*_{2} or the realizations of random numbers. Nevertheless, with this simple definition, we can already better understand the swarm (Oliveira et al. 2013; 2014; 2015; Oliveira et al. 2016; Oliveira et al. 2017). Other swarm systems, however, have different rules and distinct forms of social interaction.

### Examining the social interaction with **I**

The formation of structures in the interaction network arises from the way information flows within the swarm, which, in turn, alters the dynamics of the swarm. The existence of well-connected nodes in **I** indicates frequent information flows in the swarm. The constant interaction among specific individuals leads to their respective nodes in the interaction network to be clustered. To capture these clusters, we can gradually remove the edges of **I** according to their weight; the components that emerge during this network destruction represent the information flows within the swarm (see Fig. 6).

Note that the pace at which these components appear relates to the swarm dynamics. A slow increase suggests an exploration search mode in which individuals share information among distinct groups and thus create social interaction with various levels of tie strength. A rapid growth suggests, however, an exploitation search mode in which individuals interact with a few same sources and thus create a center of information with similar levels of tie strength.

With the definition in Eq. (1), we can now examine the search mode in the PSO algorithm. For instance, we analyze **I** of swarms using different topology parameters—that are known to lead the swarm to behave differently—while solving the same problem. As shown in Fig. 7a, with the global topology, the particle swarm presents exploitation behavior, whereas the ring topology leads the system to explore different information sources. Note that this analysis differs from the typical analysis of the relationship between fitness and topology structure (Mendes et al. 2004; Mendes 2004; Engelbrecht 2013). Here we focus on the way particles interact during the swarm search when using different structures: the communication topology affects the diversity of the *social interaction* in the swarm.

To investigate the swarm ability to maintain different frequent information flows, we can analyze the network destruction while varying *t*_{w} to include frequency and recency in the analysis of the flows. Figure 7b depicts the number of components that emerge when edges are removed from **I** with increasing time windows. The interaction network of a particle swarm with global topology seems to be destroyed at the same pace in both perspectives of frequency (i.e., high *t*_{w}) and recency (i.e., low *t*_{w}). The interactions of the particles within this topology promote a lack of diversity in the information flows in short and long terms.

This diversity regards to the ability of the swarm to have a diverse flow of information—a perspective different from *spatial* diversity in which *d*-dimensional properties of particles are compared to particular definitions of swarm center (Shi and Eberhart 2008). Note that the lack of diversity in the information flow can decrease the spatial diversity in a swarm. The absence of multiple information flows leads to particles retrieving information from a few sources and drives particles to move towards the same region of the search space; lack of interaction diversity pushes individuals to the same direction.

To quantify interaction diversity, we measure the destruction pace of interaction networks with different time windows. For a given time window *t*_{w}, the area under the destruction curve \(A_{t_{w}}\) can be seen as a measure of diversity in the information flow. High values of \(A_{t_{w}}\) indicate fast destruction, whereas low values imply slow destruction. Hence, we can define the interaction diversity ID (previously called communication diversity (Oliveira et al. 2016)) as the mean diversity over a set of time windows *T*, as the following:

$$ \text{ID}(t) = 1 - \frac{1}{|S||T|}\sum_{t'_{w}\in T}A_{t_{w}=t'_{w}}(t), $$

(2)

where |*S*| is the number of particles in the swarm. Thus, swarms exhibiting high ID (i.e., low values for \(A_{t_{w}}\)) have the ability to have diverse information flows, while low values for ID imply swarms with only few information flows (i.e., high value for \(A_{t_{w}}\)). The ideal set *T* would be one taking into account all time windows (i.e., from *t*_{w}=1 until *t*_{w}=*t*). This procedure, however, can be computationally expensive because of the vast number of possible time windows; instead, we use a subset of time windows.

#### Experimental design

To investigate the extent to which the interaction diversity assesses the swarm at each iteration, we systematically examined the swarm using different topologies that lead the swarm to behave differently. In this study, we use *k*-regular networks (i.e., graphs in which nodes have *k* links) as the swarm topologies. The *k*-regular is a simple network model that enable us to create topologies with intermediate connectivity between ring (*k*=2) and global (*k*=*N*), the two most used swarm topologies. To create a diverse set of topologies, we employ different connected *k*-regular graphs as the swarm communication topology with *k* ranging from 2 to 100. Here we consider a distinct group of four benchmark functions *F*_{2}, *F*_{6}, *F*_{14}, and *F*_{19} from the CEC’2010 (Tang et al. 2010) which require different balances of exploration/exploitation (Oliveira et al. 2017). In all experiments, the number of dimensions to 1000 and, when applicable, the degree of non-separability *m* to 50; also, we set the swarm size to 100 particles.

We analyze the relationship between ID and fitness improvement over time; thus we define fitness improvement *f*_{Δ}(*t*) at iteration *t* as the speed at which the fitness *f*_{g}(*t*) of the swarm changes between the two immediate iterations *t* and *t*−1 as follows: \(f_{\Delta }(t) = \frac {f_{g}(t) - f_{g}(t-1)}{f_{g}(t-1)}\), where *f*_{g}(*t*) is the global best fitness of the swarm at iteration *t*. To compare the social interaction in similar scenarios in the simulations, we set as stopping criterion either a maximum number of iterations *t*_{max}=10,000 is reached or the swarm has converged at iteration *t*_{s}. We define that a swarm converged at iteration *t*_{s} if the global best fitness does not improve, that is, if *f*_{Δ}(*t*)<10^{−5}, until iteration *t*_{s}+*δ* with *δ*=500. In this sense, we ensure that the swarm either converged or reached the maximum number of 10,000 iterations. For each considered swarm topology, we run a PSO implementation 30 times while measuring ID and *f*_{Δ} at each iteration in each execution.

#### Results

We analyze the impact of the infrastructure of communication (i.e., topology) on the diversity of the information flows within a swarm. We found that *k*-regular topologies promote higher diversity as *k* decreases when solving the same problem (Fig. 8a). With less connected topologies, swarms exhibit greater interaction diversity than with more connected ones. Given previous studies, this is an expected result: short topological distances lead to fast information flow, which decreases the diversity (Bratton and Kennedy 2007). Our results revealed that the interaction diversity in the swarm depends on the problem; the same topology leads to distinct levels of diversity when optimizing different functions. Though the topology bounds the interactions among particles, the swarm organizes the information flows to optimize a function.

Indeed, swarm intelligence systems have the capability to self-organize during the optimization process. To assess the relationship between swarm search and interaction diversity, we examine the pace of *f*_{Δ} at which a swarm improves and the interaction diversity at each iteration. We find that ID exhibits a non-trivial relationship with *f*_{Δ}, as seen in Fig. 8b for the function *F*_{2}. The average *f*_{Δ} increases with the average ID until reaches a maximum pace after which *f*_{Δ} decreases with ID. The increase of diversity in the social interaction of the swarm leads to faster swarm pace only until a certain level of diversity; then the swarm starts to slow down—swarm dynamics that impact the overall swarm performance, as seen in Fig. 8c. We also find a non-trivial association between *k*-regular topologies and the best fitness found at the end of the optimization process. From global to 30-regular topologies, the fitness decreases from 8.06×10^{3} and improves down to 6.77×10^{3}, then deteriorates up to 1.01×10^{4}.

#### Discussion

Our results demonstrate the capability of interaction diversity, ID, to explain the behavior of the swarm during the optimization process in the Particle Swarm Optimization technique. ID enables us to identify changes in the way information flows within the swarm regardless of the type of problem and perhaps even variations of PSO (e.g., with our without local search). The leverage capability of the proposed approach brings the possibility to identify imbalances during the search process and to understand the flow of information within the swarm. For example, more than using this approach to select which is the best topology for a particular problem (Engelbrecht 2013), one can propose adaptive mechanisms to adjust the search mode during the search process. Furthermore, note that the Interaction Diversity is a general measure to assess swarm-based systems because it does not consider peculiarities associated with the swarm metaphor. The approach is defined over the structure of the network—the *interaction space*—which is entirely based on the swarm social interaction. This approach can also help researchers to perform parametric analyses; due to the lack of analytic tools, parametric studies tend to consider simplified versions of the algorithm (Clerc and Kennedy 2002).