# Proposed Fuzzy-NN Algorithm with LoRa Communication Protocol for Clustered Irrigation Systems
## 3 Irrigation Systems Algorithms
### Proposed FITRA Algorithm Supporting the OWS Architecture
In this case, the \(a_{i}\) value represents a sensor correctly placed to a class close or far from the average value \(<\overline{a}>_{C|N|D}\) for each class accordingly. Category 2: \(0.1<\overline{a}>_{C|N|D}>|a_{i}|,|a_{i}|>4\cdot<\overline{a}>_{C|N|D}\). This is an erroneous sensor value case where the value \(a_{i}\) is close to the threshold value _Athress_ or too far away from the threshold value, but the mean value of \(a_{i}\) values in that class are not close to the threshold value. In that case sensor \(i\) measurement is set as an erroneous measurement. The \(i\) sensor value is removed from the next round calculation process and \(<\overline{a}>\) is re-calculated for that class. **FITRA NN Step 2:** With the assumption that all sensors fall into Category 1, that is, all sensors are correctly classified and with the use of \(a_{i}\) values as input, the back propagation process initiates based on the training data set. Since \(a_{i}\) values are greater than 1, there are normalized with the mean class \(a_{C},a_{N},a_{D}\) values, giving a normalized ci value calculated as: \(c_{i}=\frac{a_{i}}{c2-}\), where \(0.1\leq c_{i}\leq 4\). For the forward NN pass the \(p_{i}\) values of the hidden layer perceptrons are calculated as:  
\[p_{j}=\sum_{j=1}^{3}w_{j}\bar{r}_{j} \tag{10}\]  
And then the results are squashed using the logistic function: \(p_{j}^{\prime}=\frac{1}{1+e^{-\bar{r}_{j}}}\). The same process is repeated for the output layer neurons: \(\left\{ \begin{array}{l}S_{0}=\frac{1}{1+e^{-\frac{(\sum_{j=1}^{3}p_{j}^{ \prime}/p_{j}^{\prime})}{p_{j}^{\prime}}}}\\ Sc=\frac{1}{1+e^{-\frac{(\sum_{j=1}^{3}p_{j}^{\prime}/p_{j}^{\prime})}{p_{j}^ {\prime}}}}\end{array} \right.\), where So is the metric value of the valve set to be open while \(S_{c}\) is the metric value of the valve set to be closed. The max (\(S_{o}\),\(S_{c}\)) signifies whether the actuator should be set to \"on\" or \"off\" position accordingly. The total error and errors for \(S_{o}\) and \(S_{c}\) for the backward pass are calculated using Equation (11):  
\[\left\{ \begin{array}{l}E_{S_{o}}=\frac{1}{2}(S_{o}-U)^{2}\\ E_{S_{C}}=\frac{1}{2}(S_{C}-U)^{2}\end{array} \right.,E_{tot}=E_{S_{o}}+E_{S_{C}} \tag{11}\]  
where \(U\) is the value taken for FITRA fuzzy process Equation (5). If \(E_{tot}\leq 0.05\) then the back-propagation calculation process terminates and the weights w, w\({}^{\prime}\) and w\({}^{\prime\prime}\) are used for the forward pass neural network process. **FITRA error correction state:** In FITRA NN state, another error assessment mechanism is used on a daily basis (similar to PTC algorithm). This mechanism records the total daily watering time DTw and compares it with the average daily watering time DavTw, as calculated from the training DavTw dataset. If \(\mid\)DTw\(-\)DavTw \(\mid\) > 0.05, then the NN training dataset is considered to be erroneous for this season, the NN state is abandoned and the fuzzy state is initiated for the following day. Moreover, in such case an appropriate message is set at the AS web interface in order for the farmer to re-train theneural network.