# Performance Comparison of ANFIS Models by Input Space Partitioning Methods
## 3 Fuzzy Rule Generation Method According to Input Space Partitioning Method
### Scatter Partitioning Method
#### 3.2.3 Context-Based Fuzzy C-Means (CFCM) Clustering  
Context-based fuzzy C-means (CFCM) clustering is a method proposed by [PERSON] (2008) to partition clusters by creating clusters to maintain characteristics of patterns related to the similarity of output variables as well as the data of input spaces. A typical clustering method does not take into account the pattern of output variables, but only clusters are created using the Euclidean distance between the cluster center and the input data. On the other hand, since the CFCM clustering method generates the clusters considering not only the patterns of the input data but also the patterns of the output variables, the space can be more accurately divided than in the conventional clustering method. Figure 6 shows the difference between the FCM clustering method and the CFCM clustering method. When there is data in the input space, FCM clustering method creates two clusters because it assigns the initial center value and creates clusters using only Euclidean distance between center and data. On the other hand, the CFCM clustering method considering the output variable pattern generates three clusters considering that the data in the input space have black and white characteristics. Figure 5: Fuzzy C-means clustering method: (a) number of clusters = 2 and (b) number of clusters = 3. In the CFCM clustering method, the user needs to set the number of contexts and the number of clusters. As a simple example, if the number of contexts is set to six and the number of clusters to three, the number of fuzzy rules is 18. The reason is that \(6\times 3=18\) because clusters are created in each context. Figure 7 shows the CFCM clustering method in which clusters are created by setting the number of contexts (P) and the number of clusters (C) to six and three, respectively. (a) Shows the context of each triangle, and in (b), the red dot represents the data and the black dot represents the center of the cluster. Next, we explain the procedure and pseudocode of the CFCM clustering method. * **Step 1:** Let \(m\) (\(1<m<\infty\)) and the number of clusters \(c\) (\(2\leq c\leq n\)) be set. * **Step 2:** Set the initial partitioning matrix \(U\) and the threshold \(\varepsilon\), and choose the number of iterations. \[U\big{(}[u_{ij}]\;i=1,\;\ldots,\;c,\;j=1,\;\ldots,\;n\big{)}\] (15)
* **Step 3:** Compute the center of each cluster \(c_{i}\) (\(i=1,\;2,\;\ldots,\;c\)) using the membership matrix \(U\) and Equation (16). \[c_{i}=\frac{\sum_{j=1}^{n}u_{ij}^{m}x_{j}}{\sum_{j=1}^{n}u_{ij}^{m}}\] (16)
* **Step 4:** The partitioning matrix \(U\) is updated using the center value of the cluster \(c\) and Equation (17). \[u_{ij}=\frac{f_{j}}{\sum_{k=1}^{c}\left(\frac{d_{ij}}{d_{ij}}\right)^{\frac{2}{ (m-1)}}}\] (17) Here, \(f_{j}\) represents the inclusion degree of \(x_{j}\) in the generated cluster. In other words, the linguistic form defined in the output variable is expressed as a fuzzy set \(A,\;\{A:B\rightarrow[0,\;1]\}\) and computed by a fuzzy equalization algorithm. Then, \(f_{j}=A\big{(}y_{j}\big{)},\;i=1,\;2,\;\ldots,\;n\) can be represented by the membership value of \(y_{j}\) in \(A\). * **Step 5:** If \(\|J^{r}-J^{r+1}\|\;\leq\;\varepsilon\) is satisfied, the above procedure is stopped. If not, proceed from Step 3 again. \[J=\sum_{j=1}^{n}\sum_{i=1}^{c}u_{ij}^{m}\|x_{j}-c_{i}\|^{2}\] (18)  
Figure 6: Difference between FCM (fuzzy c-means) clustering method and CFCM (context-based fuzzy c-means) clustering method. The CFCM clustering method described above is applied to the ANFIS model as follows. The data in the input space of layer 1 is divided into input space through CFCM clustering method which considers the pattern of output variable and outputs the belonging value. In layer 2, we take the value belonging to the previous layer, output the weights multiplied by the rule, and express the ratio of the impulse force in layer 3 as the normalized value.