# Detecting IoT Anomalies Using Fuzzy Subspace Clustering Algorithms
## 3 Proposed Methods
### Fuzzy C-Means (FCM) Algorithm [41]  
A large class of the FCM algorithms is based on the minimization of fuzzy \(c\)-means functional formulated as follows.  
\[\mathbf{J}(\mathbf{X};\mathbf{U},\mathbf{V})=\sum_{i=}^{c}\sum_{k=1}^{N}(\mathbf{\mu}_{ik})^{m}\|\bm {x}_{k}-\mathbf{v}_{i}\|_{A}^{2} \tag{9}\]  
where \(U=[\mu_{ik}]\in F_{\ell k}\) (fuzzy partition of \(X\)) and \(V=[v_{1}\), \(v_{2}\),..., \(v_{c}]\), \(v_{i}\in R^{n}\), a vector of cluster's mean, which need to be computed.  
\(\mathbf{D}_{ikA}^{2}=\left\|\mathbf{x}_{k}-\mathbf{v}_{i}\right\|_{A}^{2}=\left(\mathbf{x}_{k}- \mathbf{v}_{i}\right)^{T}\!\!\mathbf{A}(\mathbf{x}_{k}-\mathbf{v}_{i})\) is the squared inner-product norm, and \(m\in[1,\infty]\) decides the resulting cluster's fuzziness. Equation (9) measures the total variance of \(x_{k}\) from \(v_{i}\).  
The minimization of (9) is a non-linear optimization problem and can be solved by various methods like [PERSON]'s iteration method. The first-order conditions of stationary points through [PERSON]'s iteration method is known as the fuzzy \(c\)-means algorithm (FCM) (Algorithm 2) [41].  
The stationary points of (9) can be obtained by adjoining constraints to \(J\) with [PERSON]'s multipliers [41].  
\[\mathbf{J}(\mathbf{X};\mathbf{U},\mathbf{V},\mathbf{\lambda})=\sum_{i=}^{c}\sum_{k=1}^{N}\left(\bm {\mu}_{ik}\right)^{m}\mathbf{D}_{ikA}^{2}+\sum_{k=}^{N}\lambda_{k}\left[\sum_{i=1 }^{c}\mathbf{\mu}_{ik}-\mathbf{1}\right] \tag{10}\]  
By setting the partial derivatives of \(J\) with respect to \(U\), \(V\) and \(\lambda\) are 0, if \(\mathbf{D}_{ikA}^{2}>\mathbf{0}\)\(\forall\)\(i,k\) and \(m>1\), then (\(U\), \(V\)) \(\in F_{\ell k}\times R^{c\times n}\) will minimize only if  
\[\mathbf{\mu}_{ik}=\frac{\mathbf{1}}{\left(\mathbf{D}_{ikA}/\mathbf{D}_{jkA}\right)^{2/(m-1)}} \text{, }1\leq i\leq c\text{, }1\leq k\leq N \tag{11}\]  
and  
\[\mathbf{v}_{i}=\frac{\sum_{k=1}^{N}(\mathbf{\mu}_{ik})^{m}\mathbf{x}_{k}}{\sum_{k=1}^{N}( \mathbf{\mu}_{ik})^{m}}\text{, }1\leq i\leq c \tag{12}\]  
The above solutions, (11) and (12), also satisfy (8) and are the first-order necessary conditions for the existence of stationary points of the objective function (9).  
```
Given dataset \(X\), choose the number of cluster \(c\), (\(l<c<N\)), weighting exponent \(m>1\), terminating threshold \(\phi>0\), and \(A\) (norm-inducing matrix). Initialize \(U=U^{(0)}\)// \(U^{(0)}\in F_{\ell k}\) for each \(j=1\), \(2\),....... step 1 compute cluster mean \(\mathbf{v}_{i}^{(j)}=\frac{\sum_{k=1}^{N}\left(\mathbf{\mu}_{ik}^{(j-1)}\right)^{m}\mathbf{ x}_{k}}{\sum_{k=1}^{N}\left(\mathbf{\mu}_{ik}^{(j-1)}\right)^{m}}\), \(i=1\), \(2\),..., \(c\) step 2 compute \(\mathbf{D}_{ikA}^{2}=\left(\mathbf{x}_{k}-\mathbf{v}_{i}^{(j)}\right)^{T}\mathbf{A}\left(\mathbf{x} _{k}-\mathbf{v}_{i}^{(j)}\right)\), \(i=1\), \(2\),..., \(c\), \(k=1\), \(2\),..., \(N\) step 3 for \(k=1\), \(2\),..., \(N\)// update partition matrix if \(D_{ikA}>0\), for all \(i=1\), \(2\),..., \(c\) \(\mathbf{\mu}_{ik}^{(j)}=\frac{1}{\sum_{k=1}^{N}\left(\mathbf{\mu}_{ik}\right)^{2/(m-1)}}\), else \(\mathbf{\mu}_{ik}^{(j)}=0\) if \(D_{ikA}>0\), \(\mathbf{\mu}_{ik}^{(j)}\mathbf{c}\)[0,1] with \(\sum_{i=1}^{c}\mathbf{\mu}_{ik}^{(j)}=1\) until \(\mid U^{(j)}\cup U^{(j-1)}\mid 1\mid<\phi\)
```  
**Algorithm 2** (FCM)