A software sensor for in-situ monitoring of the 5-day biochemical oxygen demand

Due to the time-consuming procedure for determining the 5-day biochemical oxygen demand (BOD5), the present study developed two software sensors based on artifi cial intelligence techniques. It is aimed to estimate this indicator instantaneously. For this purpose, feed-forward and radial basis function neural networks (FFANN and RBFANN, respectively) were used. FFANN and RBFANN were employed to estimate the maximum values of BOD5 (BOD5(max)) as a function of average, maximum and minimum dissolved oxygen in the Sefi drood River. Also, Levenberg-Marquardt (LM), resilient backpropagation, and scaled conjugate gradient algorithms were used to optimize the FFANN parameters. The results demonstrated that the performance of the LM algorithm in tuning the FFANN was better than the others, in the verifi cation step. Furthermore, the performance of each model was evaluated according to the mean square error, correlation coeffi cient and developed discrepancy ratio. The results showed that the performance of both FFANN and RBFANN models for the prediction of the BOD5(max) were approximately the same.


Introduction
Rivers are one of the main sources of water supply for diverse uses including industry, drinking, recreation and agriculture (Fan et al., 2008).Due to the discharge of municipal-industrial wastewaters and agricultural drainages into rivers, evaluating the quality of these valuable water bodies is essential.In this direction, predicting the water quality parameters (WQP) such as the 5-day biochemical oxygen demand (BOD 5 ), as an indicator of organic load, can provide the proper framework for managers to improve the water quality in the rivers.
Numerical and data-driven models are usually used for the simulation of WQP based on the existing facilities as well as the user's needs.Numerical models have always been a useful tool for the simulation of WQP and were used especially for the simulation of BOD 5 .Ning et al. (2001) discussed pollution prevention actions in the river Kao-Ping in Taiwan.They used QUAL2E, a steady state one-dimensional model that applies a fi nite difference scheme for solving the governing equations on pollutants' transport in rivers.Subsequently, simulation of BOD 5 , dissolved oxygen (DO) and total phosphorous (TP) was carried out by Ning et al. (2001).Simulated results indicated that using economic instruments is required to reduce and control the pollution load of BOD 5 in the river.Park and Lee (2002) compared the performance of two models QUAL2E and QUAL2K (a developed version of QUAL2E that includes some advantages such as the conversion of algae death to BOD 5 and denitrifi cation) for the simulation of BOD 5 in the Nakdong River, Korea.The researchers concluded that the QUAL2K performance was better than the QUAL2E.Fan et al. (2008) combined two models QUAL2K and HEC-RAS (a software developed by the U.S. Army Corps of Engineers) to assess WQP in the Keelung River, Taiwan.They used QUAL2K for the simulation of BOD 5 .HEC-RAS was used for simulating the hydraulic constants of atmospheric reaeration and water level profi le variations.The results showed that the combination of two models provides a good tool for water quality simulation in tidal rivers.Sharma et al. (2015) modelled BOD 5 using QUAL2Kw (a developed version of QUAL2K that uses the genetic algorithm for automatic calibration) and reported that the model performance was satisfactory.
It should be pointed out that data-driven models are more fl exible than numerical ones.Also, due to the proper performance of a set of these models called intelligent techniques, their application for BOD 5 prediction has increased in recent years.

Chaves and Chang (2006) used
The Mining-Geology-Petroleum Engineering Bulletin and the authors ©, 2018, pp.15-23, DOI: 10.1177/rgn.2018.1.3a feed-forward artifi cial neural network (FFANN) to simulate WQP in the Shihmen Reservoir located on the Tahan River in Taiwan.For this purpose, they used the water quality data for 47 days at fi ve points in three different depths.Hydro-meteorological data and WQP were defi ned as input and outputs, respectively.They concluded that FFANN was well capable of predicting WQP.2009) applied the FFANN model to predict BOD 5 and DO in the Gomti River, India.The results revealed that the predicted and measured DO and BOD 5 were in close agreement.The values of R (in case of BOD 5 ) for calibration and verifi cation steps were 0.92 and 0.88, respectively.
The relation between BOD 5 and DO is rather complex.In other words, many other parameters such as toxic substances and algae respiration could greatly infl uence the relationship between BOD 5 and DO.Thus, it is diffi cult to use simple data-driven models such as linear regression to construct a software-sensor for BOD 5 prediction.In the present investigation, two software sensors were applied by ANN models to predict BOD 5 as a function of DO in the Sefi drood River.Due to the little attention to the simulation of BOD 5 with radial basis function neural network (RBFANN), FFANN was also used to simulate the maximum value of BOD 5 (BOD 5(max) ) in the Sefi drood River.Also, this research aimed to compare the performance of FFANN and RB-FANN models for BOD 5 prediction.

Case study and data
For the in-situ measurement of BOD 5 with the aid of FFANN and RBFANN models, the Sefi drood River Basin, located in the northwest of Iran, was selected.The river basin covers an area of 59196 square kilometres, located between the Alborz and the Zagros Mountains.Pollution sources in the Sefi drood River Basin are urban, agricultural and industrial (Noori et al., 2013a and2015).A fi eld study along the river was performed to detect appropriate sampling stations.Firstly, 94 monitoring stations were selected in such a way to cover the whole length of the river and its tributaries (see Figure 1).Then, sampling was carried out for each season throughout a one year period.Dissolved oxygen (DO) was measured in-situ.BOD 5 samples were carried to the laboratory and analysed within 24 hours after collection (APHA, 1995).Thereafter, the data was checked for outliers.
One needs fi ve days to determine BOD 5 using conventional methods whereas in-situ measurement of this parameter would be very signifi cant for water quality managers.Therefore, this study aimed to apply a software-sensor for in-situ measurement of BOD 5(max) as a function of WQP such as DO.To achieve this goal, the minimum, average and maximum values of DO, (DO min , DO avg and DO max ) measured online in four seasons, were used as suggested by Noori et al. ( 2012). Figure 2 shows the correlation matrix between DO parameters and BOD 5(max) .
Generally, Figure 2 indicates a weak correlation between DO and BOD 5(max) .This can be justifi ed by many factors such as discharge of industrial effl uents without proper treatment that cause a negative infl uence on microbial activates (Noori et al., 2013b).In other words, the presence of toxic substances, along with algae respiration due to the eutrophic status in some parts of the river can infl uence microbial activities to various degrees.Based on Figure 2, the largest value of the coeffi cient of determination (R 2 ) is between DO max and BOD 5(max) and the smallest one is between DO min and BOD 5(max) .Considering this correlation matrix, it is not possible to predict BOD 5(max) based on DO because there is no linear relation between the two variables whereas it is clear that a complicated relation exists between them.Therefore, it is diffi cult to provide a software-sensor for modelling BOD 5 as a function of DO by using simple data-driven models such as linear regression.So, it is necessary to use a strong tool such as ANN.
Figure 3 shows the applied methodology in this research for developing a software-sensor based on FFANN and RBFANN models step-by-step to predict BOD 5(max) in the Sefi drood River.According to this fi gure, after the collection of data, inputs (DO min , DO avg and DO max ) and target (BOD 5(max) ) were imported to MAT-LAB software for the application of FFANN and RB-FANN models.The data entered to MATLAB were standardized to be limited in the range [-1, +1].Then,

Feed-forward artifi cial neural network
The FFANN is comparable to the natural nervous system.It has neurons as processing elements and links which represent the connections among the neurons (Dogan et al., 2007).Every link has a weight parameter associated with itself (Maier and Dandy, 2000).The neurons are located in layers and each layer has a specifi c transfer function.FFANN consists of an input-layer, an output-layer, and several hidden layers, but one hidden-layer is enough to estimate each complex parameter (Noori et al., 2010b;Singh and Gupta, 2014).Figure 4 shows an applied FFANN model in which DO min , DO avg and DO max are as inputs and BOD 5(max) is the target.ANN was applied to the data set collected from 94 sample points.The inputs were standardized to be limited in a range between -1 and 1 (Basant et al., 2010) and were divided into three categories: training, validation and verifi cation.The laboratory data set from the fi rst to 65 th station, 66 th to 80 th station, and 81 st to the 94 th were selected as training, validation, and verifi cation sets, respectively.Also, to optimize the network weights, Levenberg-Marquardt (LM), scaled conjugate gradient The backpropagation algorithm is used for training the perceptron network.This supervised learning algorithm is carried out through backpropagation, a generalization of the least mean squares algorithm in the linear perceptron (Singh et al., 2009).The error (e) in outputnode j in the n th data point can be calculated by Equation 1 as follows: (1) where: t -the target values, y -the output values.
The weights of the nodes are based on the corrections which minimize the error in the entire output, given by Equation 2.
(2) Using gradient descent (GD), the change in each weight (∆w) is written by Equation 3(3) where: the output of the previous neuron, σ -the learning rate.The calculation of derivative counts on the induced local fi eld γ j .For an output-node, the derivative is calculated as Equation 4.
(4) where: -the derivative of the transfer function.
The analysis is more diffi cult for the change in weights to a hidden-node, but it is shown as Equation 5.
(5) This counts on the change in weights of the k th nodes, which represents the output-layer.
The linear and sigmoidal transfer functions are very popular in the application of ANN models.In some investigations, a sigmoidal transfer function was used in place of a linear function in the output-layer of FFANN (Nilsson et al., 2006;Sahoo and Ray, 2006).This can limit the outputs of FFANN to a small range (Haykin, 1994).In the present study, for the FFANN model with one hidden-layer, the transfer functions of the hiddenlayer and output-layer were selected as tangent-sigmoid and linear functions.To achieve the best architecture, the number of the hidden-layer neurons was identifi ed using the trial-error procedure.

Radial basis function artifi cial neural network
The RBFANN was fi rstly introduced by Lowe and Broomhead (1988) for the application to problems of supervised learning (Orr, 1996).This network has a faster learning process in comparison to other neural networks (Han et al., 2012).The basic RBFANN structure contains three layers (input, output and hidden layers).The hidden-layer functions transfer the nonlinear input-space to the linear hidden-space (Liu et al., 2004;Singh et al., 2013).In this study, to construct a software-sensor for the online prediction of BOD 5 (max) using a RBFANN model, input vectors DO min , DO avg and DO max were selected (see Figure 5).
A basic RBFANN with one output and k hidden-layer nodes is represented by Equation 6 where: x -the input of RBFANN, -the connecting weights between k th hidden-node and the output-layer, -the of the k th hidden-node which usually based on Gaussian function as Equation 7. (7) where: -the centre vector of the k th hidden-node, -the Euclidean distance between x and , -the width of the k th hidden-node.The RBFANN training process involves determining the centre vectors of the nodes in the hidden-layer, the width of the hidden-layer nodes, and the connecting weights between the two layers (hidden and output layers).
The RBFANN, compared to the FFANN, needs more neurons but its design and training process are faster.In this research, the newrb function was used in the MAT-LAB environment to design and tune the RBFANN model for BOD 5(max) estimation.This function creates a RBFANN that includes one neuron the fi rst time.Neurons are added to the network until the sum of the squared error reaches the error goal or the number of the hidden-layer neurons reaches the maximum number (Demuth and Beale, 2004).

Models' evaluation
To estimate the performance of FFANN and RB-FANN models, three statistical indices; R, MSE, and DDR were used.R denotes the strength and the direction of a linear relationship between the measured and predicted values.R values range from -1 to +1.The (+) and (-) signs are used for positive and negative linear correlation, respectively.If the observed and predicted values have a strong positive linear correlation, R is close to +1.When the correlation is greater than 0.8, it means that there is a strong fi t between the observed and predicted values.R can be represented by Equation 8.

Results of feed-forward artifi cial neural network
In this study, the unknown network parameters, i.e. weights and biases, were optimized in the model using LM, SCG, and RP algorithms, respectively.The results revealed that the best FFANN performance was achieved by the application of 20 neurons in the hidden-layer of the network.The results for the application of each training algorithm based on statistical characteristics, i.e.MSE and R, have been shown in Table 1.  1, it is observed that the tuned model by LM algorithm includes more desirable R and MSE values during both the calibration (training and validation) and verifi cation steps.Therefore, it can be noticed that LM performance is better than SCG and RP algorithms.Besides, Figure 6 shows a scatter diagram of the predicted BOD 5(max) vs measured ones during both calibration-verifi cation steps.The results of the predicted BOD 5(max) vs the measured ones and also an error diagram for the FFANN model in each station can be seen in Figure 7.This fi gure shows that the FFANN model tuned by the LM algorithm worked well during both the calibration-verifi cation steps.However, the error diagram illustrates that the FFANN model in some stations was faced with high error values that infl uence the application of this model as a management tool for BOD 5 monitoring in Sefi drood River.In Figure 7, the two red lines indicate the range of acceptable error which is less than 10%.This fi gure shows that the error for approximately 25% of the points for FFANN model is out of this range.

Results of radial basis function artifi cial neural network
In RBFANN the width of the hidden nodes was optimized through trial and error.The maximum number of the hidden-layer neurons was selected with consideration of the inputs.Finally, the width value and the maximum hidden-layer's neurons were considered within ranges 0 to 4 and 5 to 30, respectively.The RBFANN weights were updated depending on the GD approach.The obtained results by the trial and error procedure specifi ed that the best RBFANN performance was in the application of 20 neurons in the hidden-layer of the network and considering the width of the hidden nodes equal to 2. MSE and R indices for the calibration-verifi cation steps of RBFANN model have been shown in Table 1.This table shows that the tuned model by RBFANN includes proper R and MSE values during the calibration-verifi cation steps.Also, the scatter and trend diagrams of the predicted BOD 5(max) vs measured ones for RBFANN model have been shown in Figure 6.Moreover, the error diagram (see Figure 7) clearly shows the poor performance of the RBFANN model in some points so that the error of 23% of the points is more than 10%.However, a visual inspection of the results indicates that the tuned models by RBFANN and FFANN have approximately the same performance.To have a better evaluation regarding the performance of FFANN and RBFANN models, the Q DDR via standardized DDR values for FFANN and RBFNN in the verifi cation step have been shown in Figure 8.Based on this fi gure, the tendency to the centre line in RBFANN is as same as that in FFANN model.Besides, the maximum of Q DDR for the both models is close to 0.4.Therefore, the DDR analysis reveals that the performance of RBFANN is practically same as the FFANN model.
However, in comparison with previous studies, it can be found that the applied FFANN and RBFANN models in this research have a good performance for BOD  2013) tuned a FFANN model with R equal to 0.94 for the prediction of BOD 5 .Noted although there are some studies that aimed to predict BOD 5 using FFANN, an application of the RBFANN model, which in this case, is rare.Thus, this study aimed to investigate the RBFANN performance for BOD 5 prediction in rivers.Also, artifi cial intelligence techniques such as FFANN and RBFANN models are sensitive to the case study and selection of inputs.So the models' performance is highly infl uenced by the selected inputs.
In this regard, this study aimed to tune a model whereas faced with some fi nancial constraints.Therefore, only the main effective parameter on BOD 5 variations, i.e.DO was measured and other effective parameters such as nutrients, industrial effl uents and fl ow discharge were ignored.By considering the facts, the obtained results are acceptable and could be applied to understanding the pollution trends in the Sefi drood River.

Conclusions
This study aimed to estimate the BOD 5(max) as a function of DO min , DO avg and DO max in the Sefi drood River Basin, Iran, using FFANN and RBFANN models.The performance of the tuned models was assessed through R, MSE, and DDR indices.Calibration-verifi cation results specifi ed that FFANN and RBFANN models worked well and predicted BOD 5(max) with R values close to 0.89 and 0.90 in the verifi cation step, respectively.For FFANN, it was observed that the tuned model by the LM algorithm resulted in more desirable R and MSE values.In addition, R and MSE values for RBFANN and FFANN models were approximately acceptable.According to DDR analysis, the results demonstrated that the performance of both models was approximately the same and the maximum values of Q DDR were practically the same for both networks.However, because of insuffi cient data about some effective parameters on BOD 5 such as algae respiration and toxic substances, both the tuned models did not have excellent performance in some stations.Therefore, it is recommended that the models are again tuned using more data if the decision makers aim to apply the results for management of water quality in the Sefi drood River.

References
Dogan et al. (2007) applied FFANN to estimate the BOD 5 concentration in the Melen-River, Turkey.Inputs (including chemical oxygen demand (COD), temperature, DO, water fl ow, chlorophyll-a, ammonia, nitrite and nitrate) were measured at 11 sites in the Melen-River during 2001-2002.A comparison of the modelled values with the measured ones showed that the FFANN model performed well for the BOD 5 prediction with a correlation coeffi cient (R) equal to 0.93.Singh et al. (

Figure 1 :
Figure 1: The Sefi drood River Basin and sampling points

Figure 2 :Figure 3 :
Figure 2: The correlation matrix between DO and BOD 5(max) parameters (SCG) and resilient backpropagation (RP), training functions were used.LM and SCG have a good effi cacy and RP training function has a high speed in training procedure.Therefore, these functions have been utilized in the present research.The SCG, against the LM algorithm, avoids the time-consuming calculation of the The Mining-Geology-Petroleum Engineering Bulletin and the authors ©, 2018, pp.15-23, DOI: 10.1177/rgn.2018.1.3Hessian matrix in the modelling process.It is the main advantage of this algorithm.Also, SCG merges between two approaches: the model-trust region and the conjugate gradient (CG).More information on SCG, LM and RP algorithms can be found in Noori et al. (2009a; 2010a; 2010b).

Figure 4 :Figure 5 :
Figure 4: The applied three-layer FFANN in this study values, p -observed values, n-the number of values.In statistics, MSE estimates the quality of a model for predicting values.MSE values close to zero are better.It is calculated by Equation 9 (Dogan et al., 2016)(9)In addition, the DDR statistic that introduces a graphical view for the models' performance is calculated as shown in Equation 10.(10) DDR values must be standardized and then, the normalized value of DDR (Q DDR ) is calculated using the Gaussian function.Finally, Q DDR via standardized DDR values must be illustrated.In the obtained fi gure, more tendencies to the centre line and also, a bigger value of the maximum Q DDR indicates more accuracy.More information on DDR can be found in Noori et al. (2010a).

Figure 7 :Figure 6 :
Figure 7: The predicted BOD 5(max) vs measured ones and the error diagrams for FFANN and RBFANN models in stations 5(max) prediction.Regarding the FFANN model, Onkal-Engin et al. (2005) tuned a FFANN model with R equal to 0.93 for the prediction of BOD 5 .Singh et al. (2009) calibrated different FFANN models to predict BOD 5 .They reported that the models had a good performance with R ranged from 0.70 to 0.85 between the measured and the modelled BOD 5 .Also, the R value for the presented FFANN model by Dogan et al. (2007) was 0.93.In another work, Noori et al. (

Figure 8 :
Figure 8: Q DDR via standardized DDR values for FFANN and RBFNN in testing step