## 3 Methods
### Learning from the Expert Template  
In this section, a distributed flocking control strategy is generated by imitative learning from the centralized expert template. In order to improve the swarm robustness, the centralized APF strategy is utilized based on fixed and fully connected topology to achieve the balanced distribution of graph importance. To give full play to the performance of the centralized APF strategy, this paper chooses to execute the strategy in a small-scale swarm and assumes that each individual can access to global information in real-time, which means that the communication topology is fixed and fully connected. According to the demonstration of [44], in this case, the centralized APF strategy can realize velocity consistency and collision avoidance while ensuring the global lowest potential energy. First, the relative potential energy function between the robot \(v_{i}\) and \(v_{j}\) is defined as:  
\[U(\mathbf{r}_{i},\mathbf{r}_{j})=\frac{d_{best}}{\|\mathbf{r}_{ij}\|}+\log\| \mathbf{r}_{ij}\|, \tag{14}\]  
where the position vector of \(v_{i}\) and \(v_{j}\) is denoted as \(\mathbf{r}_{i}\) and \(\mathbf{r}_{j}\), the relative position vector is denoted as \(\mathbf{r}_{ij}=\mathbf{r}_{i}-\mathbf{r}_{j}\). Obviously, when \(\|\mathbf{r}_{ij}\|\to 0\) or \(\|\mathbf{r}_{ij}\|\rightarrow\infty\), and the potential energy \(U(\mathbf{r}_{i},\mathbf{r}_{j})\rightarrow\infty\). When \(\|\mathbf{r}_{ij}\|=d_{best}\), the relative potential energy between the robot \(v_{i}\) and \(v_{j}\) reaches the minimum value. Therefore, the value of \(d_{best}\) represents the ideal distance between robots, and by adjusting the value of \(d_{best}\), the shrinkage or expansion of the swarm can be realized. The gradient of the relative potential energy is the interaction force between robots. Thus, the centralized APF strategy is defined as:  
\[\mathbf{u}_{i}^{*}=-\sum_{j=1}^{N}(\mathbf{v}_{i}-\mathbf{v}_{j})-\sum_{j=1}^{ N}\
abla_{\mathbf{r}_{i}}U(\mathbf{r}_{i},\mathbf{r}_{j}). \tag{15}\]The control law consists of two parts, a sum of relative velocity vectors to achieve velocity consistency and a gradient of relative potential energy defining the interaction forces between robots to maintain swarm connectivity and avoid collisions. We design comparative experiments to verify the effectiveness of this strategy for improving swarm robustness, and the related experimental results are shown in Section 4.2.1. Meanwhile, the distributed APF strategy is defined as:  
\[\mathbf{u}_{i}^{d}=-\sum_{v_{j}\in\mathcal{N}^{d}(v_{i})}(\mathbf{v}_{i}- \mathbf{v}_{j})-\sum_{v_{j}\in\mathcal{N}^{d}(v_{i})}\
abla_{\mathbf{r}_{i}}U (\mathbf{r}_{i},\mathbf{r}_{j}). \tag{16}\]  
Unlike the centralized APF strategy (15), the reference data in Equation (16) only come from neighboring nodes that can achieve direct communication, so Equation (16) is a typical distributed strategy. The distributed APF strategy is used as a benchmark for evaluating distributed learning strategies in Section 4. According to the goal to realize swarm consistency, the robot observations are designed as follows:  
\[\mathbf{x}_{i}=\left[\sum_{v_{j}\in\mathcal{N}^{d}(v_{i})}\mathbf{r}_{ij}, \sum_{v_{j}\in\mathcal{N}^{d}(v_{i})}(\mathbf{v}_{i}-\mathbf{v}_{j}),\sum_{v_{ j}\in\mathcal{N}^{d}(v_{i})}\frac{\mathbf{r}_{ij}}{\|\mathbf{r}_{ij}\|^{2}}, \sum_{v_{j}\in\mathcal{N}^{d}(v_{i})}\frac{\mathbf{r}_{ij}}{\|\mathbf{r}_{ij }\|^{3}}\right], \tag{17}\]  
where the first two items respectively represent the vector sum of the relative position and relative velocity of robot \(v_{i}\) and its neighbors, and the latter two items are related to the gradient of the potential energy function defined by Equation (14). The expert template is denoted as \(\mathcal{T}\).