# Using an Artificial _Physarum polycephalum_ Colony for Threshold Image Segmentation
## 4 Algorithm Steps of APPCA
### Step 2: Expansion
Third, the free-learning hyphae allow the artificial _Physarum polycephalum_ colony to randomly produce a new generation of hyphae completely unrelated to the existing hyphae in each iteration. Because the search is completely random, free learning helps to maintain a certain level of global search ability in each iteration, avoiding premature convergence to the local optimal solution. The population size is decided by the possibility \(p_{f}\) of free learning, that is, a rand-segmented image of the free-learning population \(x^{m}_{free}(Ite)\). \[x^{m}_{free}(Ite)=Random(Ite)(m=1,2,3,\ldots,S\times p_{f}) \tag{17}\]  
Considering the original population size \(S\), the social-learning population size \(S\), and the free-learning population size \(Sp_{f}\), the total population size is \((2+p_{f})S\) after the expansion operation. There is  
\[x^{k}(Ite)=\Big{\{}x^{k}_{self}(Ite),x^{k}_{social}(Ite)\text{ or }x^{l}_{social}(Ite),x^{m}_{free}(Ite) \Big{\}} \tag{18}\]  
\[x(Ite)=\Big{\{}x^{k}(Ite)\Big{|}k=1,2,3,\ldots,S\Big{\}}. \tag{19}\]  
By the aiding of more hyphae population, all pixels will be arranged into the feasible solutions by the artificial _Physarum polycephalum_ colony algorithm, where the optimal scheduling solutions may be generated by the fitness in the contraction stage and different hyphae can obtain different fitness. Now, the pseudo-code of expansion is provided and the algorithm performance is analyzed. Assuming the scale of the threshold image segmentation includes a total of \(HV\) pixels, and the population size of the _Physarum polycephalum_ colony algorithm includes the maximum number \(M\) of _Physarum polycephalum_ and the maximum number \(S\) of hyphae in each _Physarum polycephalum_, there is the expansion algorithm in Algorithm 1. ```
1: Input: the original image, \(H\), \(V\), grayscale \(L\)
2: Define: the fitness function in Equation (5)
3: Initialization: the APPC, \(M\), \(S\), \(p_{s}\), \(p_{f}\)
4: Calculate: randomly generate hyphae \(\Big{\{}x^{k}(1)\Big{\}}\)
5: Initialization: \(T_{max}\), \(Ite\_{max}\), \(e_{th}\)
6: For \(Ite=1\):Ite\(\_{max}\)
7: For \(P_{\text{physarum polycephalum}}\)\(m=1:M\)
8: For hyphae \(k=1:S\)
9: Random select a pixel
10: Self-learning
11: Social learning by \(p_{s}\)
12: Free learning by \(p_{f}\)
13: To integrate the three parts of the expansion population
14: End for
15: To update the _Physarum polycephalum_ colony by Equation (18)
16: End for
17: To update the _Physarum polycephalum_ colony by Equation (19)
18: Return the solutions to threshold image segmentation
19: //contraction algorithm
20: End for
21: //Output the optimal segmented image As we can see from Algorithm 1, there is a triple-loop, so the time complexity of the expansion algorithm is \(O(Ite\_maxMSHV)\), and the space complexity is \(O(MSHV)\). In the triple-loop of expansion, the APPC has \(M\) of _Physarum polycephalum_ and each has \(S\) hyphae. The APPC will search for a total of \(HV\) pixels and select the best segmented image with the highest fitness. The APPC expansion algorithm seems to have good search capabilities, but the computation seems too time-consuming. Now, it is necessary to improve the expansion algorithm with a triple-loop in Algorithm 1. Since the _Physarum polycephalum_ colony has a strong ability to learn from each other, it is unnecessary to investigate which each _Physarum polycephalum_ hypha comes from. In this way, one loop can be directly reduced, greatly improving the algorithm's computational performance and search efficiency. The improved expansion of APPC is shown in Algorithm 2. The problem scale and the _Physarum polycephalum_ colony are the same as in Algorithm 1, where there are a total of \(HV\) pixels and the maximum number \(S\) of hyphae. The maximum number \(M\) of _Physarum polycephalum_ is neglected.