# Kernel Clustering with a Differential Harmony Search Algorithm for Scheme Classification
## 3 Dhs-Kfc
### Differential Harmony Search Algorithm
#### 3.1.3 Implementation of DHS  
The DHS algorithm consists of five steps, as follows:  
1. Initialize the algorithm parameters
2. This step specifies parameters, including harmony memory size (_hms_), harmony memory considering rate (_hmcr_), pitch adjustment rate (par), fetch width (_fw_), and memory keep iteration (_sc_).
3. Initialize the harmony memory  
This step is consistent with the basic harmony search algorithm. New random vectors (\(\mathbf{x}^{1},\ldots,\mathbf{x}^{hms}\)), as many as _hms_, are generated following Equation (15):  
\[x_{i}^{j}=(UB_{i}-LB_{i})\cdot U(0,1)+LB_{i},i=1,2,\ldots,D \tag{15}\]  
Then each vector will be evaluated by the objective function and stored in the HM.  
Step 3 Improvising a new harmony  
In this step, a new random vector \(x^{\prime}=(x^{\prime}_{1},x^{\prime}_{2},\ldots,x^{\prime}_{D})\) is generated considering the self-adaptive solution generation strategy. The procedure is shown in Algorithm 2.  
```
for\(i=1,\cdots,n\)do if\((U(0,1)<\mathit{hmcr})\) then \(x^{\prime}_{i}=x^{j}_{i}\), where \(j\sim U(1,\mathit{hms})\) if\((U(0,1)<\mathit{per})\) then \(\mathit{shift}=U(-1,1)\times\mathit{fw}\times(UB_{i}-LB_{i})\) if\((U(0,1)<\frac{1}{N}\Big{|}\big{|}U(0,1)<\mathit{cr})\) then \(x^{\prime}_{i}=x^{best}_{i}+\mathit{shift}\) else \(x^{\prime}_{i}=x^{\prime}_{i}+\mathit{shift}\) end if end if else \(x^{\prime}_{i}=LB_{i}+U(0,1)\times(UB_{i}-LB_{i})\) end if end for
```  
**Algorithm 2** **Improvisation of a New Harmony of DHS  
Step 4 Update the harmony memory  
If the vector generated in Step 3 is better than the worst vector in HM, replace the worst vector with the generated vector.  
If the vector in HM remains unchanged for several iterations (\(\mathit{sc}=20\)), replace it with a new vector generated, following Equation (14), if the new vector is better.  
The procedure of step 4 is shown in Algorithm 3.  
```
if\((f(x^{\prime})<f(\mathbf{x}^{\mathit{worst}}))\) then  Replace \(\mathbf{x}^{\mathit{worst}}\) with \(\mathbf{x}^{\prime}\)  Set \(flag(\mathit{worst})=0\) end if for\(r=1,\cdots,\mathit{hms}\) do \(flag(r)=flag(r)+1\) if\((flag(r)>\mathit{sc})\) then  for\(i=1,\cdots,n\)do  if\((U(0,1)<\frac{1}{N}\Big{|}\big{|}U(0,1)<\mathit{cr})\) then \(\mathit{shift}=U(-1,1)\times\big{(}x^{r1}_{i}-x^{r2}_{i}\big{)},\forall r1,r2=1,2,\cdots,\mathit{hms}\) and \(r1\
eq r2\) \(x^{\prime\prime}_{i}=x^{\prime}_{i}+\mathit{shift}\) else \(x^{\prime\prime}_{i}=x^{\prime}_{i}\) end if end for if\((f(\mathbf{x}^{\prime})<f(\mathbf{x}^{\prime}))\) then  Replace \(\mathbf{x}^{\prime}\) with \(\mathbf{x}^{\prime}\)  end if end if end for
```  
**Algorithm 3** **Update the Harmony Memory**  
```
if\((f(x^{\prime})<f(\mathbf{x}^{\mathit{worst}}))\) then  Replace \(\mathbf{x}^{\mathit{worst}}\) with \(\mathbf{x}^{\prime}\)  Set \(flag(\mathit{worst})=0\) end if for\(r=1,\cdots,\mathit{hms}\) do \(flag(r)=flag(r)+1\) if\((flag(r)>\mathit{sc})\) then  for\(i=1,\cdots,n\)do  if\((U(0,1)<\frac{1}{N}\Big{|}\big{|}U(0,1)<\mathit{cr})\) then \(\mathit{shift}=U(-1,1)\times\big{(}x^{r1}_{i}-x^{r2}_{i}\big{)},\forall r1,r2=1,2,\cdots,\mathit{hms}\) and \(r1\
eq r2\) \(x^{\prime\prime}_{i}=x^{\prime}_{i}+\mathit{shift}\) else \(x^{\prime\prime}_{i}=x^{\prime}_{i}\) end if end for if\((f(\mathbf{x}^{\prime})<f(\mathbf{x}^{\prime}))\) then  Replace \(\mathbf{x}^{\prime}\) with \(\mathbf{x}^{\prime}\)  end if end if end for
```  
**Algorithm 4** **Update the Harmony Memory**  
Step 5: Check the stop criterion  
Repeat Step 3 to Step 4 until the termination criterion is satisfied. In this paper, the termination criterion is the maximum number of evaluations.