# An Optimal and Stable Algorithm for Clustering Numerical Data
## 2 Preliminaries
### k-AMH Clustering Framework
#### 2.2.1 k-AMH Algorithm for Categorical Clustering  
As mentioned above, the k-AMH algorithm [17] for categorical clustering is the original k-AMH algorithm. Beginning with predefined \(k\) clusters, \(k\) seeding is initialized, the objects are tested individually, and the objects are replaced in succession to obtain the final objects as the centers of the clusters. Let \(X=\{X_{1},X_{2},\ldots,X_{n}\}\) be a set of \(n\) categorical objects and \(H=\{H_{1},H_{2},\ldots,H_{k}\}\in X\) be a set of objects at the centers of clusters, better known as medoids. To partition \(X\) into \(C\), the k-AMH framework generally requires the following steps:  
Step 1--First, initialize the number of clusters, \(k\).  
Step 2--Randomly select \(H\) from \(X\) as the center of the clusters (better known as medoids).  
Step 3--Replace the medoids, \(H\), by testing each one until \(X_{n}\). The updates are complete when the objective function is maximized as Equation (14) and subject to Equations (15)-(21).  
\[F(W,Q)^{r}>F(W,Q)^{t},r\
eq t;\forall t,1\leq t\leq(n-k) \tag{14}\]  
where \(r\) is the current cost function.  
\(F(W,Q)\) is maximized and defined in Equation (15):  
\[F(W,Q)=\sum_{l=1}^{k}\sum_{i=1}^{n}w_{li}^{\psi}q_{li} \tag{15}\]  
where \(w_{li}\in W\) is a \((k\times n)\) matrix and \(q_{li}\in Q\) is another \((k\times n)\) matrix containing the dominant weighting value.  
The \(w_{li}\) describes the degree of fuzziness of the object, which contains values from 0 to 1, as described in Equation (16).  
\[w_{li}=\begin{cases}1,&ifX_{i}=H_{l}\\ 0,&ifX_{i}=H_{\
u},v\
eq l\\ \frac{1}{\sum_{v=1}^{k}\left[\frac{d_{sim}(X_{i},H_{l})}{d_{sim}^{2}(X_{i},H_{l })}\right]^{\frac{1}{k-1}}}&ifX_{i}\
eq H_{l}\;and\;X_{l}\
eq H_{\
u},1\leq v \leq k\end{cases} \tag{16}\]  
where \(k(\leq n)\) is a predefined number of clusters, \(H\) is the medoid such that \(H=\{H_{1},H_{2},\ldots,H_{k}\}\in X,\psi\in[1,\infty)\) is a weighting exponent that is typically greater than 1.0, and \(d_{sim}(X_{i},H_{l})\) is the dissimilarity measure calculated between object \(X_{i}\) and medoid \(H_{l}\), as described in Equation (17):  
\[d_{sim}(X_{i},H_{l})=\sum_{j=1}^{m}\gamma(x_{ij},h_{lj}), \tag{17}\]  
where \(m\) is the number of attributes and subject to the following conditions,  
\[\gamma(x_{j},h_{j})=\begin{cases}0,&x_{j}=h_{j}\\ 1,&x_{j}\
eq h_{j}\end{cases} \tag{18}\]  
The \(q_{li}\) assigns a value of 1.0 or 0.5, known as the dominant weighting value, as described in Equation (19):  
\[q_{li}=\begin{cases}1.0,&ifw_{li}^{\psi}=max^{w_{li}^{\psi},1\leq l\leq k}\\ 0.5,&Otherwise\end{cases} \tag{19}\]  
which is subject to the following Equations (20) and (21),  
\[1.5\leq\sum_{i=1}^{k}q_{li}\leq k,1\leq i\leq n \tag{20}\]  
\[0.5<\sum_{i=1}^{n}q_{li}<n,1\leq l\leq k \tag{21}\]  
Step 4--Assign \(X\) to \(C\) when the final \(H\) is obtained.  
Thus, the procedure above can be formalized in the form of pseudocode as Algorithm 2.  
Input: dataset \(X\), number of clusters \(k\), and weighting exponent \(\psi\)  
Output: Set of clusters \(C=\{C_{1},C_{2},\ldots,C_{k}\}\)
```
1:Select \(H_{l}\) randomly from \(X\), where \(1\leq l\leq k\)
2:for each \(H_{l}\)do
3:for each \(X_{i}\)do
4: Calculate \(F(W,Q)\) as Equation (15)
5:if\(F(W,Q)\) is maximized then
6: Replace \(H_{l}\) with \(X_{i}\) as Equation (14)
7:endif
8:endfor
9:endfor
10: Assign \(X_{i}\) to \(C_{l}\) for all \(l\), \(1\leq l\leq k\) and \(i\), \(1\leq i\leq n\)
11:Output results
```
**Algorithm 2** k-AMH (\(X,k,\psi\)).