# An Enhanced Distributed Data Aggregation Method in the Internet of Things
## 3 Proposed Method (LA-RPL)
### Data Aggregation Scheme Based on Learning Automata
If operation \(\alpha_{i}\) is selected in the \(n^{th}\) step; then, in the \((n+1)^{th}\) step we have:  
The favorable response from the environment is  
\[P_{i,j}(k+1)=\left\{ \begin{array}{ll}P_{i,j}(k)+\alpha\Big{(}1-P_{i,j}(k) \Big{)},&\ i=j\\ P_{i,j}(k)(1-\alpha),&\forall j\
eq i\end{array} \right. \tag{2}\]  
The unfavorable response from the environment is  
\[P_{i,j}(k+1)=\left\{ \begin{array}{ll}P_{i,j}(k)+(1-\beta),&\ i=j\\ \frac{\beta}{\tau-1}+P_{i,j}(k)(1-\beta),&\forall j=i\end{array} \right. \tag{3}\]  
It is worth stating that set \(\alpha\) includes the outputs (i.e., the operations) of automata. In other words, the automata selects and applies one operation among all \(r\) operations existing in this set in each step. Note that the input set \(\beta\) determines the inputs of the automata [42]. Having created the network graph, network nodes execute the proposed objective function OF2. Each parent node starts either aggregating data or instantly sending data in a recent time slot. The act of  
Figure 8: Stochastic Learning Automata [41]. data aggregation is performed by each parent node such that the next-step action is selected according to the environmental received feedback. Note that the proposed system acts in a distributed manner; such that if a parent node in lower layers aggregates some packets, such packets are not aggregated in higher layers, to avoid the multi-step aggregation and the resultant unacceptable imposed delay on data packets. In order for data aggregation mechanism to perform efficiently, each sensor node is equipped with learning automata. Learning automata is a decision-making system selecting an existing operation in the upcoming round according to the environmental received feedback. Learning automata includes two phases: selecting phase, and learning phase. In the selecting phase, based on the environment feedback, decisions are made concerning the upcoming rounds toward improving the current status about previous steps [43]. 1. **Selecting Phase:** All of the sensor nodes have an aggregation label (_lbl_indicator_), which is initialized to 0 at the beginning. When a sensor node plays the role as an aggregator, the value of this label changes to 1. In the routing procedure proceeding data reception, each node acts as an aggregator with probability \(P_{Agg}\) and, accordingly, acts as an ordinary node with probability \(1-P_{Agg}\) to prepare and send the received data toward the root node. Upon the activation of _lbl_indicator_ (i.e., changing the value to 1), the node waits for t seconds to receive more data packets. Note that t is a constant value for all of the nodes acting as an aggregator. After the passage of t seconds, all the received data is aggregated into a single data packet, by means of the function \(F\) (Aggregation). Afterwards, this single packet is routed. At the beginning, all nodes have the same \(P_{Agg}\). However, through the repetitions of the algorithm and the reception of reinforcement signals from the environment, this probability changes. 2. **Learning Phase:** In the learning phase, a learning automata employed in the internet of things network as a distributed factor. Each node, as a learning agent, is equipped with learning automata comprising two different operations. The concepts and parameters of such a learning automata are as follows: * **Agent:** Each sensor node acting as an independent learner is known as an agent. In other words, the action of learning agent has no effect on other learning agents. * **Action:** Each agent can act as an aggregator or an ordinary node. * **Reinforcement Signal (RS):** The number of data packets received by node \(j\) during time duration \(t\) (also known as _input degree_). \[Rate_{j}=P_{AN}+P_{AM}\] (4) where \(P_{AN}\) is the number of data packets aggregated by previous nodes throughout the routing, and \(P_{AM}\) is the number of data packets not being aggregated by previous nodes throughout the routing. \[RS=1-\frac{1}{Rate\ j}\] (5) If \(S>\)_Threshold_\(\delta\), then node \(j\) is rewarded.