**3. Architectural detail**

The fundamental part of the WQMCM framework is that individual networks learn their environment to predict the impact of events elsewhere in the catchment on their own zone of influence. The predicted drainage information can be beneficial for adjusting management strategy in a farm or in a stream network accordingly, by adopting drainage reuse, disposal, or treatment. For managing agricultural reuse, the overall architectural detail comprises of various modules encompassing drainage, farm, and stream networks, as illustrated in **Figure 3**. For enabling forecasting of drainage dynamics expected as a result of an event in a neighboring farm, two key modules are developed in the drainage network: neighbor linking model, and drainage and pollutant dynamics module. The neighbor linking model uses neighbor event information and sensed drainage data to link the impactful neighbors. The predictive module further comprises individual models to predict *Q*, *t*1, *t*d, and *TON*. The predicted drainage information is used by decision support models in farm and stream network to enable decision making about its reuse or disposal. Furthermore, this information is further used to adjust sampling rate of the sensors, to capture the approaching drainage flow, at the predicted response time.

It has been emphasized in this chapter that due to inevitable drainage and nutrient losses despite adopting BMPs, it is important to enable mechanism for their reutilization. Therefore, a simplified decision support model is developed just as an example to illustrate

**Figure 3.**

*Block diagram of the WQMCM framework architecture.*

*Water Sustainability through Drainage Reuse in Agriculture – A Case for Collaborative Wireless... DOI: http://dx.doi.org/10.5772/intechopen.106486*

the utilization of predicted information for enabling reuse mechanism. The modules of drainage network and farm network blocks are briefly introduced. **Figures 4** and **5** found illustrates the functional flow of these modules for both the blocks.

#### **Figure 4.**

*Functional stages of the drainage network modules, under the WQMCM framework, such as "Learning," "Training," and "Testing."*

#### **Figure 5.**

*Functional stages of a decision support model at a farm network, which intends to reuse drainage water, under the WQMCM framework.*

#### **3.1 Neighbor linking model**

The main purpose of this module in the drainage network is to identify the farm networks that drain into this drainage network. These links are identified over a period of time using a learning process. Firstly, dislocated networks (e.g., located at lower altitudes of the catchment) are filtered out using network location in the shared information packet by the neighbors. Secondly, for the filtered neighbors, training dataset is acquired over a period of time, as respective event information is received from these individual neighbors. Training data consists of (i) the event information packets that were received that particular day, for example, at time *t*, and (ii) the sensed values of the received drainage and nutrients at the drainage bay at time *t + x.* Here, *x* refers to the time it takes for drainage to appear in the drainage bay from the time event information is received, and *t* is ranged between 00 hrs and (*x*-1) hrs.

For each set of the acquired training data for a particular neighbor, a linear regression model is used to identify the relationship between the sensed drainage and the received event details. This process divides the neighbors, which sent information over the learning phase, into two lists: linked neighbors and un-linked neighbors. Later, for the linked neighbors, sufficient training data are acquired to provide for the development of the predictive models. **Figure 4** illustrates the mechanism of the neighbor linking model in the learning stage section.

#### **3.2 Drainage hydrograph and nutrient dynamics predictive models**

Once training dataset is acquired for the linked neighbors, the next step is to develop the models for predicting the drainage hydrograph and nutrient dynamics. Constraints on network nodes (battery life, computing power, availability of sensors, etc.) require a simplified underlying physical model, and a simple machine learning model based on fewer and, ideally, real-time field parameters acquired autonomously and shareable

#### *Water Sustainability through Drainage Reuse in Agriculture – A Case for Collaborative Wireless... DOI: http://dx.doi.org/10.5772/intechopen.106486*

across neighboring farms. Ideally, the model should be based on minimal training samples so that the model can be implementable soon after the deployment of the network. Such models are local in the sense of being valid for a given site (farm in this case). Once developed at the gateway, these models are deployed on the relevant node associated with the particular farm. This facilitates distributed computing where individual nodes of the drainage network, deployed at the outlets of farms, run the learned predictive models for forecasting drainage from those farms. These models can then generate expected drainage hydrograph and nutrients dynamics, which are transmitted to the gateway for further action regarding transmission to neighboring networks.

These models intrinsically self-calibrate because the evolving record of the observations allows them to adapt to the latest condition. This creates portability from one season to the next and from one climate regime to the next. With new data regarding a farm, the models are calibrated at the gateway and re-deployed at the relevant node. However, it is important that a model must maintain a balance between the complexity of the model and the predictive accuracy of the model.

Existing state-of-the-art predictive models are used as a basis to derive lowcomplexity models for *Q*, *t*1, *t*d, and *TON.* A machine learning algorithm, M5 tree, is then used to train the individual models as shown in the training stage of **Figure 4**. Once the models are trained with acceptable prediction performance, the drainage network progresses to the testing stage. In the testing stage, neighbor event information is firstly interpreted using developed neighbor linking lists and then used to predict drainage dynamics using the predictive models, in case of a linked neighbor as illustrated in the testing stage of **Figure 4**. As mentioned earlier, the model accuracy can be continuously improved by learning the evolving instances in the testing stage.

The algorithmic flow of these stages for a drainage network is illustrated using a flow diagram in **Figure 6**. When information is received at the data sink of the drainage network by either a drainage network sensor or a neighbor farm, firstly it is checked whether the network is in the learning stage or not. In such a case, the information is passed on to the neighbor linking model. If the model is in testing stage, then in case the received data packet is from a neighbor, it is checked if the neighbor ID is in the linked neighbor list. If it is an already linked neighbor, then the relevant trained predictive models for that particular neighbor are used to predict the event values. Otherwise, it is determined if the neighbor is an un-linked neighbor, in which case the event packet information is disregarded. In case the received data packet is from the drainage sensor, then the data within the packet are linked with the relevant neighbor information and saved for improving the models later.

#### **3.3 Decision support model (for drainage reuse in a farm)**

For the decision support model, the challenge lies in designing a model which takes into account local field conditions, predicted dynamics, and expert knowledge. Unlike the predictive models in the drainage network, this model essentially runs on the gateway of the farm network. The model complexity can substantially vary depending upon the requirements set by the farmer. For example, the farmer may want the model to advice on the possible repercussions of drainage reuse on crop. Furthermore, in case the available drainage is not enough or high in N, the model may also advise on mixing drainage and freshwater for irrigation to fulfill its requirements or to disregard the excess nutrients in the drainage which the farm may not want to reuse. These complexities are highly scenario dependent and require sufficient expert knowledge and data to address. In this chapter, a simplified decision support model is

#### **Figure 6.**

*Basic algorithm running at a sensor node of a drainage network under WQMCM framework.*

developed as an example to demonstrate the utilization of predicted information for enabling the reuse mechanism.

**Figure 6** illustrates the functional stages of the development and use of the decision model for drainage reuse in a farm. In the training stage, expert knowledge and machine learning algorithms are used to implement simplified models for drainage and nutrient reuse. Once the model is trained, predicted drainage information received from a drainage network, and local field conditions and climatic data are used to classify the usability of the drainage water and nutrients (as shown in the testing stage of **Figure 6**).
