## 4 Evaluation
### Accuracy  
The second factor to consider when evaluating the TFNN algorithm is recognition accuracy. As demonstrated in Algorithm 3, the TFNN algorithm performs federated kNN among the nodes in the network. At the local node level, the accuracy of each node's kNN can achieve performance better than the Bayes error rate. Formula (7) shows the theoretical minimum error, which represents the best performance that any classifier can achieve when the underlying probability distribution of the class is known; \(E\) for kNN can be estimated as follows:  
\[E=\int\min_{c\in\mathbb{C}}P(C=c|X=x)P(X=x)dx \tag{8}\]  
Formula (7) shows the integral sum over the entire input space, where \(C\) is the set of possible classes, \(P(C=c\mid X=x)\) is the posterior probability of class \(c\) given the feature vector \(x\), and \(P(X\mid x)\) is the probability density function of the feature vector \(x\). Furthermore, Formula (7) demonstrates that the error rate does not exceed twice that of the Bayesian optimal classifier. ```
1:Network Initialization
2:\(N\leftarrow\{n_{1},n_{2},n_{3},\ldots n_{k}\}\)
3:(_CH,CLUSTER\()\leftarrow\) ((\(ch_{1}\), cluster\({}_{1}\)),(\(ch_{2}\), cluster\({}_{2}\)),(\(ch_{3}\), cluster\({}_{3}\)), \(\ldots\), (\(ch_{j}\), cluster\({}_{j}\)))
4:% Autonomously partition the network by forming \(j\) non-overlapping clusters and elect a cluster head (\(ch_{i}\)) for each cluster (\(cluster_{i}\)) using LEACH
5:cluster\({}_{i}\subseteq N\), where \(cluster_{i}\cap cluster_{k}=\phi\) for all \(1\leqslant i\
eq k\leqslant j\)
6:Base-Station Aggregation
7:% each cluster aggregates the local kNN results of nodes associated with the cluster
8:for every cluster head \(ch_{i}\in\text{CH}\)do
9:\(\tilde{y}_{i}^{ch_{i}}\leftarrow\text{ClusterHead\_Update}(ch_{i}P_{i})\)
10:endfor
11:\(\tilde{y}_{i}\leftarrow\text{argmax}\sum_{m}^{i=1}\delta(c,\tilde{y}^{ch_{i}})\)
12:
13:ClusterHead_Update(\(ch\),P)
14:for each node \(n_{i}\in\text{cluster}_{i}\)do
15:\(\tilde{y}^{j}\) = NodeKNN(\(P\)) % return the winning class label
16:endfor
17:return \(\text{argmax}_{c}\sum_{j=1}^{m}\delta(c,\tilde{y}^{j})\)
```  
**Algorithm 3** Tiny federated nearest neighbor (TFNN) algorithm. TFNN employs majority voting to aggregate local classifications and determine a global label for the event pattern. Each node \(n\) in cluster \(i\) has an individual accuracy \(p\), where \(0\subseteq p\leqq 1\). In this majority voting system, an event pattern is classified when more than half of the nodes assign the correct label. Consequently, the accuracy \(A\) of the majority voting can be calculated as follows:  
\[A=\sum_{n=1}^{k}\left( \begin{array}{c}n\\ k\end{array} \right)*p^{k}*(1-p)^{(n-k)} \tag{9}\]  
where \(k\) is the number of nodes with the correct class label, and n is the total number of nodes. In majority voting, the condition \(k>\dfrac{n}{2}\) must be met. The term \(\left( \begin{array}{c}n\\ k\end{array} \right)\) represents the binomial coefficient, which calculates the number of ways to choose \(k\) nodes with correct votes from \(n\) voting nodes. Consequently, the error of the majority vote (\(E\)) can be calculated as follows:  
\[E=1-A=\sum_{n=1}^{k}\left( \begin{array}{c}n\\ k\end{array} \right)*p^{n-k}*(1-p)^{k} \tag{10}\]  
Formulas (8) and (9) facilitate the calculation of the accuracy and error of the majority vote based on the individual voting accuracy \(p\) of each node and the total number of voting nodes \(n\). These formulas apply under the assumption of two label classes, meaning that nodes can either vote for \(0\) or \(1\). For multi-class majority voting, we consider a scenario with \(c\) classes, where \(c>2\). The accuracy \(A\) of the majority voting can be expressed as follows:  
\[A=\sum_{k_{1}+k_{2}:\ldots+k_{c}=n}^{k}\left( \begin{array}{c}n\\ k_{1},k_{2},\ldots,k_{c}\end{array}