# Clustered Distributed Learning Exploiting Node Centrality and Residual Energy (CINE) in WSNs
## 3 CINE Solution
### Distributed Learning and Gossiping  
In this section, we detail the protocol executed by WSN nodes to perform distributed learning and gossiping.  
We assume that all of the network nodes have the capability to set the transmission power to:  
* The low power TX mode, used when a node (either a CH or a simple CM) communicates with other nodes of the same cluster;
* The high power TX mode, used when a CH node communicates with other CH nodes in the CH-network.  
Cluster heads perform model training using their own data. The _fitness_ of the ML model is evaluated through an appropriate _loss_ function hl (The choice of a specific loss function is out of the scope of this work. In the literature, several loss functions have been introduced for different application scenarios. A comprehensive overview is available in [34]).The loss for a specific node \(j\) is indicated as \(L_{j}\).  
Upon estimating its model loss on the completion of a training execution, each cluster head communicates this value across the CH-network. Based on this dissemination, all of the CHs know the loss functions of the others. Thus, before starting a new competition, the CH declaring the lowest loss function value will transmit its model parameters to its one-hop neighbors in the CH-network using the high power TX mode.  
Upon receiving the model issued by a generic CH \(j\), the \(k\)-th cluster head will use the received model parameters, \(\mathbf{w}_{j}\), to update its own model, \(\mathbf{w}_{k}\), as follows:  
\[\mathbf{w}_{k}=\alpha\cdot\mathbf{w}_{j}+(1-\alpha)\cdot\mathbf{w}_{k} \tag{1}\]  
where \(\alpha\) is a weight parameter that allows one to characterize the trust the CH node has in the other CHs. Then, the CHs retrain the model obtained applying Equation (1) using the data that are locally available.  
In order to preserve the energy consumption inside each cluster, cluster members are not required to execute the training, although they can in principle; they only perform inference. More specifically, the CH of cluster \(\mathcal{Q}\) takes care of training the model that is transmitted and used for inference by the other cluster members to be broadcast to all of the cluster members of cluster \(\mathcal{Q}\), together with the value of its corresponding loss \(L_{\mathcal{Q}}\).  
Upon receiving the weight model from the CH, the CMs will estimate their loss based on the updated model using their own data. A cluster member of cluster \(\mathcal{Q}\) that obtains a loss higher then the value contained in the message transmitted by the CH, \(L_{\mathcal{Q}}\), plus a given threshold, \(\sigma_{TH}\), will send a chunk of its data to the CH for retraining. The CH will retrain the model using the received data chunk. In this way, the updated model will be efficient and will also be representative of the data of other CMs.  
The execution of the above set of operations is denoted as _protocol iteration_. After each iteration, the involved CH will broadcast its updated loss value throughout the CH-network so that all of the other CHs can compare it to their own loss values.