# Artificial Neural Network-Based Mechanism to Detect Security Threats in Wireless Sensor Networks
## 4 Proposed Methodology
### Training
#### 4.1.1 Feed-Forward  
A vector of input values and the intended output value are sent to the system in a feed-forward configuration. The input vector of our proposed technique has the format [5, 5, 4, 1, 1, 0, 0, 0], where [5, 5, 4, 1] indicates the number of packets the node has received and sent, the node's energy consumption information, and the node's trust value respectively mentioned in Table 2. The leftover values of the input vector, i.e., [1, 0, 0, 0] correspond to the desired output, which is \"normal node\" for the provided vector. The process of choosing initial weights and bias values is a significant problem, as these values aid in producing the intended results. This input vector is then forwarded to the hidden layer through connected weights. All implementation of the back-propagation algorithm can be found in [36].  
\[IH_{k}=\sum_{d=1}^{4}\sum_{m=n}^{p}X_{l}W_{m}+b_{k} \tag{1}\]  
In the above Equation (1), \"\(IH_{k}\)\" stands for the scalar product of each input value times its linked weight and the total bias associated with each hidden layer neuron. The initial values of each variable in Equation (8) are as follows: \(k\) = [1-3]: \(n\) = 1, 5, 9, 13: \(p\) = 4, 8, 12, 16. The output of every node in the hidden layer is determined using the following sigmoid activation function:  
\[OH_{k}=\
icefrac{{1}}{{\left(1+e^{-IH_{k}}\right)}} \tag{2}\]  
In Equation (2), the output of each neuron in the hidden layer is denoted by \"\(OH_{k}\)\", and \"\(IH_{k}\)\" is calculated in Equation (1). The result of Equation (2) for each hidden layer node will be used as input to each output layer node. The same process will be repeated to obtain the results from output layer nodes using Equations (3) and (4), as follows:  
\[IO_{k}=\sum_{l=1}^{3}\sum_{m=n}^{p}OH_{l}W_{m}+b_{k} \tag{3}\]  
\[Out_{k}=\
icefrac{{1}}{{\left(1+e^{-(IO_{k})}\right)}} \tag{4}\]  
where \"\(Out_{k}\)\" is the output of each output layer node for the input supplied by the hidden layer nodes \"\(OH\)\" and \"\(IO_{k}\)\" is the sum of the bias associated with each output layer neuron and the scalar product of each input value received from the hidden layer times its linked weight. The variables in Equations (3) and (4) could have the values \(k\) = [1-4], \(n\) = 1, 4, 7, 10, and \(p\) = 3, 6, 9, 12.  
The final stage in the suggested mechanism's feed-forward training is to use the following equation to determine the error between the calculated output (\(AO\)) and the desired output (\(DO\)):  
\[E=\frac{1}{2}\text{$\sum_{i=1}^{4}(DO_{i}-AO_{i})^{2}$} \tag{5}\]  
During the various experiments performed for the identification of optimal error values, it was found that the system produced accurate results when the weights of connection and bias values were updated with the error value of 0.20. The first feed-forward mechanism for input vector [5, 5, 3, 1] is described in Figure 4.  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Attack Type** & **Input Vector Parameter for ANN** \\ \hline \multirow{4}{*}{Black-hole attack, gray-hole attack and wormhole attack} & Number of packets received by the node \\  & Number of packets sent by the node \\ \cline{1-1}  & Energy-consumption details \\ \cline{1-1}  & Trust value of the node in the network \\ \hline \hline \end{tabular}
\end{table}
Table 2: Input vector parameters.