Using Artificial Neural Networks to Solve the Problem Represented by BOD and DO Indicators

Zbigniew Gomolka 1,*,† ID , Boguslaw Twarog 1,† ID , Ewa Zeslawska 2,† ID , Arkadiusz Lewicki 2,† and Tadeusz Kwater 1,† 1 Department of Computer Engineering, Faculty of Mathematics and Natural Sciences, University of Rzeszow, Pigonia Str. 1, 35-959 Rzeszow, Poland; btwarog@ur.edu.pl (B.T.); tkwater@ur.edu.pl (T.K.) 2 Department of Applied Information, Faculty of Applied Informatics, University of Information Technology and Management, Sucharskiego Str. 2, 35-225 Rzeszow, Poland; ezeslawska@wsiz.rzeszow.pl (E.Z.); alewicki@wsiz.rzeszow.pl (A.L.) * Correspondence: zgomolka@ur.edu.pl; Tel.: +48-17-851-87-55 † These authors contributed equally to this work.


Introduction
Contaminated water, partially or completely polluted as a result of household, industrial, agricultural and other uses is commonly referred to as waste water. The largest part of the pollution in waste water contains detergents, organic matters and oils. There are different approaches for removing these contaminants or eliminating them. We can divide them into two groups of methods: artificial or natural. The first method uses a set of filters: mechanic filters (for precipitation, flocculation, trapping pollutants by organisms and by hyporheic sediment, sorption on mineral and organic particles), chemical filters (for chemical degradation of pollutant, as abiotic oxidation and photo-oxidation) and biochemical filters (biodegradation of pollutants, assimilation). The second method, also referred to as self-purification, is a natural process of rivers, lakes or canals to recover the rate of dissolved oxygen The main river current is fed with lateral inflows, atmospheric precipitation and urban and industrial inflows, which are the most frequent sources of biochemical pollution of the river. When the river becomes contaminated, the only way to reduce the negative impact is to provide oxygen directly to the water, consequently protecting the biological life of the river. The intelligent analytical computing system module continuously monitors two basic BOD and DO water quality indicators. These indicators are crucial for assessing the ecological status of the river water and possible related hazards to living organisms. The results for the DO measurement are immediate, while the measurement of the BOD parameter is difficult to achieve in real time as it is performed in a laboratory environment over a period of 5 to 28 days. The proposed monitoring system utilized mathematical models of the river and performs the estimation of difficult-to-measure variables. In this circumvention, we will utilize the measurement of dissolved oxygen to determine the value of biochemical oxygen demand [23][24][25][26]. In the experimental part of the actual work, the object to which the proposed system is applied is the Wislok river, located in the southeastern part of Poland. Its hydrological profile and actual measurement data have been used to determine the value of control and monitoring parameters implemented by the intelligent analytical computing system.

Mathematical Model of Water Quality
Mathematical biochemical models of levels of water pollution in rivers had various forms depending on their application in order to present their components and dependencies. They are used for the equation of quantitative description. These are (usually differential) equations that link important values like input, output and variable states. Oxygen balance is the basis for water contamination modeling; it is described by two indicators of water quality: BOD and DO. Biochemical oxygen demand equals the amount of oxygen used by aerobic microorganisms over a specific time period and conditions, for oxidation of organic compounds in water or waste-water [27]. This value determines the content of biodegradable organic compounds. Dissolved oxygen is an indicator that has a significant influence on chemical and biochemical processes in water. The indicator is also crucial for organisms that create river ecosystems. Studies conducted by Streeter and Phelps in relation to BOD and DO concentration in rivers are the basis for mathematical modeling of water quality [3]. The equations describe the biochemical decomposition of organic compounds, which runs according to the first order differential equation of physical-chemical reaction kinetics. Dependency for a steady volume of water and contamination takes the form of [19,22,[28][29][30][31][32]: where x 1 = (mg/L)-BOD concentration, t (day)-time, k 1 (1/day)-reaction rate coefficient, and w 1 (mg/(L·day))-intensity of BOD pollution loads. The change of oxygen dissolved in water: where x 2 = (mg/L)-DO concentration, t (time)-time, k 2 (1/day)-rate coefficient of BOD influence DO, k 3 (1/day)-rate coefficient of oxygen absorption from air, x 2N (mg/L)-oxygen content in water saturation, a (mg/L·day)-intensity of oxygen absorption or consumption. In further considerations, to present DO processes in a simpler way, DO deficit is used. Therefore, assuming that x 2 is DO deficit interpreted as: where x 2s represents value x 2 from Equation (2). We get a dependency that describes the change of DO deficit in time: Equations (1) and (4) can be written in the form of vector: where A = −k 1 0 −k 2 −k 3 state matrix, x = col x 1 x 2 -state vector (BOD and DO, respectively), B-control matrix, and w-vector of external extortion and alternatively of controls. A river can be divided into smaller parts, interpreted separately. Taking into consideration longer segments of the river, the outflow from one tank is the inflow of another ( Figure 2). Due to the nature of the phenomena in rivers [4], there is one direction of the transport of state vector, the changes of which are imposed by the processes (self-purification, diffusion). Considering the river divided accordingly into cascade segments where the time of river flow depends on the rate of river flow. The current studies concern observations of a water section moving freely, affected by side inflows. The length of river that results from the rate of flow can be adequately used instead of the time axis.

Models with Distributed Parameters
Conducting an analysis of the state vector x (z, t) dependent on the time and length of the river, Streeter-Phelps Equations (1) and (4) including mass balance are transformed into the first order hyperbolic partial differential equations. BOD-DO mathematical model for i-th river segment is described with the equation [22,33]: with boundary conditions of river flow speed. The model considers the boundary conditions represented by: edge condition, which describes the starting point of the considered segment in the time domain: Matrix M i represents the edge interrelations between single segments, vector w bi refers to the edge disturbances. Control u bi has an impact only on a state vector coordinate x 2 and on locating it at the starting point of the river segment. Initial disturbance concerns the whole segment at a moment t = t 0 : x i (z, t 0 ) = x i0 (z), i = 1, 2, ..., N.
The mathematical model described by the first order hyperbolic partial differential Equation (6) represents a general approach. Using a different interpretation of this model, an equivalent description can be used with the set of Streeter-Phelps equations (description in Section 2.2) [19][20][21][22].

Second Order Distributed Parameter Model
In water environments there are multiple factors that influence the water quality. The aim is to attempt to consider all the conditions that have an impact on the self-purification process. The diffusion is a factor that influences the water condition and is considered regarding spatial conditions such as: length, width and depth. Using the Gauss-Ostrogradsky theorem, the model of diffusion can be written in the form of a second order partial differential equation. The general form of the diffusion equation is: in which x-state vector dependent on the time and spatial parameters, D-isotropic diffusion coefficient, and δ-intensity of production or loss of shifted factor. Based on Equation (9), the river state vector is considered dependent on time, length, width and depth taking into consideration the river self-purification process, the diffusion equation is: where z 1 , z 2 , z 3 describe the coordinates of length, width, depth, A-state matrix. Assuming that the change of diffusion along the variable spatial depth of water is negligibly small against the width and length of body of water in the Equation (10), the last component can be excluded. Completing the Equation (10) with the flow speed, an additional component appears: where V is a diagonal matrix that represents the flow speed in a given segment length. Solving the above equations is possible in variable boundary conditions: where functions f p1 , f p2 , f b are known for particular coordinates.

Ordinary Differential Equations on Characteristics
The function that describes the values of state coordinate x in the space-time field is the solution of hyperbolic partial differential equations. It means that values of this function are available for any length of river and any period of time in this field. Using the idea of this solution and considering a natural flow, a modified interpretation of the mathematical model of the river water pollution described by the Equation (6), which, without losing the model accuracy, utilize the river self-purification process was proposed. Positive values of the diagonal V matrix in Equation (6) causes Streeter-Phelps equations to have common characteristics along which they become ordinary equations. The question comes down to the analysis of river self-purification process along the characteristics (Figure 3) of space-time field concerning the speed of BOD and DO pollution relocation. The levels of water pollution in the river considered along the characteristics in the field z ∈ [0, 1] and t ∈ [t 0 , t k ], t k < ∞ become ordinary differential equations that represent respective characteristics. The description of particular segments leads to the solution of a particular number of space-time field characteristics. The characteristics of ith river segment are defined with dependency: the edge points of which meet the condition: in which z 0i ∈ [0, 1] is the initial coordinate in the moment t 0i . For the same characteristic, the moment t 0i+1 , determines the starting point in i+1-st segment. A set of line segments of the characteristic covers the space-time field, to which further considerations regarding the issues of river state estimation [20,[32][33][34][35] will be related. Measurements continuous in time can be performed at specified control points along the river. The considerations concern a boat drifting freely with the river current. Shifting down a particular river, encountering the located control points, the measurements taken for a given characteristic become discrete in time. Continuous measurements are described with the equation [33,34]: where x 2 -dissolved oxygen, and v p -measurement disturbance with Gaussian distribution. Substituting t = t k , for k = 1, 2, 3, . . . , we obtain a measurement discrete equation: in which the state vector x (t k ) = col x 1 (t k ) x 2 (t k ) , matrix C = 0 1 and measurement disturbances are determined in discrete measurement moments t k .
The equation for i-th river segment can be written in the form of ordinary differential equations on characteristics: with initial condition: x (z i (t 0 ) , t 0 ) = x 0 (z i0 ) for i = 1, 2, 3, . . .. The edge conditions disappear because the characteristic concerns the whole field of considerations for the river [33,34].

River State Estimation with Kalman-Bucy Filter
The problem of state estimation x (t) comes down to the determination of the estimate x (t) of the current state, considering the condition for the minimization of distance between x (t) and its estimate x (t). It is reduced to the solution of differential equation [32][33][34] , where x (t 0 ) = x (t) in which the enhancement filter coordinate K F is determined with the equation: where V is the measurement error covariance, and estimate error covariance matrix P(t) is obtained with a Riccati differential equation: with starting condition P (t 0 ) = P 0 . Matrix W r is the covariance matrix of system disturbances w r that are present in the Equation (19). Therefore, in order to obtain state estimate x (t) first, it is necessary to solve the Riccati Equation (21), next based on its solution to determine the enhancement filter coordinate K F (t) (20) and finally solve the estimates Equation (19). When considering the issue of estimate, "along the characteristics", it is necessary to pay attention to the measurement equations that become discrete in time. This results in the characteristic z i (t) encountering control points in z i1 , z i2 , ..., which correspond with discrete time moments t 1i , t 2i , ..., t mi . As a result, the equation takes the form: in which v pi (t mi ) is Gaussian white noise with zero mean and covariance: where t k -measurement moment, E means the expected value operator, and δ kl -Kronecker function which: The proposed approach allows the mathematical model of river with centered parameters to be described, but the questions that occur here are for the objects with distributed parameters that are represented by time moments t 1i , ..., t mi . In the estimation process that comprises continuous and discrete measurements, two stages can be distinguished: filtration and prediction. The prediction and filtration equations are obtained based on a Kalman-Bucy filter [33,36] in which measurement continuity is included, assuming that: V p (t = t k ) = ∞. In the filtration stage estimates are obtained in moment t k based on the estimates from previous time moment t k−1 and current measurements. This process is described with the following equations: wherex (t k /t k )-estimate in moment t k obtained based on the measurements y (t 0 ) , ..., y (t k ), P (t k /t k )-estimate covariance error, and K F (t k )-enhancement filter coordinate. The prediction is based on finding an estimate prior to the next measurement moment for t ∈ (t k , t k+1 ), taking the estimates obtained in the filtration process for the initial values. The prediction is presented with the equations: wherex (t k /t k ), P (t k /t k )-estimate and covariance of estimation error estimated for t > t k , and W r -disturbance covariance w r [22,32,34]. The results relevantly depend on the accurate determining of Stochastic Processes that include force signals. Practical experience shows that the influence of weather conditions decides on the characteristics of the signals mentioned above. Thus, it is advised to update these characteristics frequently for a more precise determination.

Model of Feed-Forward Neural Network
Artificial neural networks are already well established as a proven data analysis tool. In this section, we briefly review supervised feed-forward neural network with the back-propagation learning strategy. Figure 4 presents the exemplary two-layer ANN regarding typical Matlab (R2013a (8.1.0.604), MathWorks, Natick, MA 01760-2098, United States) environment notation of the input pattern P and output activations A ,respectively. Input signal to the j-th neuron in the first layer: where w 1 (i, j)-an element of W 1 matrix connecting receptor layer with first layer of neurons, i-receptor number, j-neuron number in the input layer, and P(i)-denotes i-th element of input vector. For the sake of simplicity, shifting elements b l are included in the weights matrix. Neurons activation in the first layer is expressed as a 1 (j) = h(e 1 (j)), where h(e 1 (j)) denotes the neuron transfer function in the first layer. Similarly, the input signal to the k-th neuron in the second layer equals is an element of weight matrix W 2 connecting the first and second layer. Per analogy, the activation of neurons in second-output layer is expressed as: Usually, the sigmoid function is assumed to be the transfer function of a particular neuron because of the simple numerical computation complexity of its first derivative: Other differentiable transfer functions like linear, logarithmic, hyperbolic tangent or Gaussian can also be used. The set of weights w 1 (i, j) and w 2 (j, k), usually randomly generated at the beginning of training process, does not provide required network knowledge functionality. The correction of weights in the consecutive steps of training, known also as epochs, stands the classic task for the network trained with supervisor. Such ANN architecture has the error function, also referred to as cost function defined as follows: where q-denotes the number of the consecutive input vectors with appropriate target output vector T q . This equation is referred to as least-square-method and its internal part might be modified according to the class of the considered problem to be solved. The only two requirements that have to be satisfied in general cases: internal expressions are differentiable and its common minimum exists, such that: E → 0 [37]. In recent works [17,18], we have observed that, in general cases, the order of derivatives does not have to be of integer values and this advantage provides fluent modification of neuron transfer function dynamics and its control during the ANN training process. The expected changes of weights under the training procedure are expressed with the equation: where η-denotes the learning rate coefficient, usually in the range 0.1-1.5. At the experimental part, we used the set of scripts from Matlab Neural Network Toolbox (Matlab NNET) library as well as our own scripts with fluent modification neuron features functionality. The modified version of backpropagation algorithm regarding momentum mechanism and reinforcement learning rule also referred to as Quick Propagation (QuickProp) has been utilized as weight changing rule: where ∆w NEW and ∆w OLD denotes weights corrections in consecutive steps. In this circumvention, momentum coefficient value equals m c = 0.1 and does not change during training process, opposite to learning rate coefficient which changes with strategy: η = 1.05 × η-if new computed error decrease its value along training time, η = 0.7 × η-otherwise. With this circumvention, the training process can be accelerated, preserving at the same time the ability of ANN to overcome the local minimum traps in the error function space.

Artificial Neural Networks for Estimation Processes
By using information about the current state of the river and anticipated changes in river pollution the monitoring and control system has been designed ( Figure 5). The purpose of the system is to monitor the quality of water, and, in the event of threats to its lifeforms, respond accordingly by reducing the effects of emerging pollutants. Its primary function is to predict the state of water quality in real time because of the ravages occurring when delayed response to impurities leads to irreversible ecological changes in the river. The monitoring system based on DO measurements and BOD estimation performed by neural networks is able to determine the current values of river pollution indicators. The system also predicts their changes over an assumed time interval. Using this information system generates appropriate controls for water aeration devices in the river. This is a key mechanism to safeguard the life forms of the river and the water quality. Using the Kalman-Bucy filter in the state estimation process requires knowledge of the characteristic features of extortion processes such as disturbances effecting the system and measurements. It usually involves great amounts of work and does not always lead to satisfactory results. Using artificial neural networks is an alternative solution, which will support the execution of filtration process thanks to its properties [8,17,[38][39][40][41]. The studies employed feed-forward artificial neural networks and training based on backpropagation algorithm. Taking into consideration the complexity of questions that result from the measurement comparison of discrete and continuous objects, it is difficult to find one structure of neural network that would generate estimates with satisfactory results. This is the reason why two separate structures of artificial neural networks were used, as in the case of the filtration and prediction process Figure 6. Obviously, these networks cooperate with one another according to the algorithm of estimation that uses the filtration and prediction processes [4,21,22,32,34]. The value of estimates from the previous moment and the value of measurement were given at the system input. In the ANN training process, we trained both network modules with the target values of estimates obtained from the mathematical model. The execution of filtration process is the first stage. The output signal of this part of the system are the estimates values in discrete measurement moments which are the input signals for the second ANN structure in the prediction process. As a result, the estimate values of BOD and DO are obtained, which are given with the feedback loop at the system input. The structure of neural network for the filtration (see Figure 7) stems from the logic of functioning of this process. The BOD and DO state estimate is obtained at the output in discrete measurement moments. The input signals are the state estimates determined before the measurement moments and the measurement signal. Thus, in the input layer, there are three receptors (two state vector coordinates and measurement), and the output layer comprises two neurons that generate estimates in measurement moments. The amount of neurons in the hidden layer and the selection of activation function are the result of experimental studies. The activation function in the hidden layer is sigmoid, and linear in the output layer, in order not to restrict the values of output signals obtained from the network. It is worth mentioning that such network architecture represents one characteristic for one execution of the filtration process. In order to obtain state estimates for multiple characteristics, it is necessary at the network input to give the current measurement and corresponding estimates values connected with a particular characteristic. The prediction process runs interchangeably with the filtration process and executes a task, which is to obtain BOD and DO estimate values obtained in the filtration process. In the river control system [42], this process must closely cooperate with the filtration and deliver information concerning the river condition between conducted measurements. The network architecture is similar to the filtration process, while in the input and output layer, there are only two neurons, and the amount of neurons in the hidden layer can have different values. In the prediction in the hidden layer a sigmoid activation function was used, and linear one was used in the output layer [22,32,34]. During the training of networks, different BOD and DO state values can be used. The neural network diagram in the prediction process is presented in Figure 8.
The quality of estimates obtained in the filtration or prediction processes depends on the process of network training during which the network changes the amount of neurons in the hidden layer. The network training process has a significant influence on the results. When a great variety of cases of model signals are taken into consideration, the generated estimates will correspond to the expectations. The length of the training process affects the estimates obtained from the neural networks. When the network training error is too large, it means that the network was not sufficiently trained, but it is able to generate the estimates burdened with very large errors. In extreme cases the neural network can distort the estimate process against its real state. It concerns large and sudden state changes that can be caused by side inflows of high pollution level. Using the proposed approach, one can obtain the river state estimate with the use of artificial neural networks. Appropriately designed ANN architecture and properly conducted training processes will allow for obtaining a system that will accurately, based on information from control points, estimate the BOD and DO change courses for a particular river segment. The artificial neural networks prepared for the filtration and prediction phase (see Figure 6) are used in the control system shown in Figure 5 in the intelligent filtration and prediction module [17,18,37,38,41,[43][44][45][46][47][48]. The above approach concerns the use of two ANNs working in the system presented in Figure 6 and executing the filtration and prediction process. The creation of an artificial neural network control system which functions parallel to generating of BOD and DO estimates is a slightly different approach. ANN for BOD and DO estimate process is shown in Figure 9. At the input BOD estimate and measurements vector are given similarly like in the case of DO estimate. A two-layer neural network was used with 25 neurons in the hidden layer (Figure 7). In the case of DO, ANN in the hidden layer can have fewer neurons against BOD, e.g., 10 neurons generating correct results.
The whole set of individual learning vectors were split into two complementary sets: a training set 80% and validation set 20%. At the preliminary test stage, a subset of input vectors was randomly chosen from the set of input vectors to avoid data overfitting and maximize the ANN performance. In the main part of the experiment Matlab's default values, i.e., for training 70%, for testing 15% and for validations 15% have been used.  . .

The Influence of Immeasurable State Coordinates on Optimal Object Control
The best system according to the chosen measurement standard is called the optimal system. In order to accurately determine the optimal system, an automated regulation system comprising regulator and object is used (Figure 10), which will be described with simultaneous equations in the form: where x-state vector of constituents x 1 , x 2 , . . . , x n , and u-control value vector of constituents u 1 , u 2 , . . . , u m , being continuous time function ranges. In real systems, the control values are usually limited. Generally, it is assumed that the control values meet restriction in the form: where D u is the set of acceptable control values u ∈ D u The quality indicator representing the optimum criteria, the goal of the function is in the form: Considering a linear object described with the differential Equation (5), we assume the quality indicator as: where P (t)-nonnegative definite matrix of dimensions n × n, and R (t)-positive definite matrix of dimensions m × m. Additionally, we assume that regulation time t r is demanded and the control vector is not additionally restricted. The task will be to determine the control u, executing the differential Equations (5), which minimizes the quality indicators (43). The optimal controlū for the presented task is determined as follows:ū where P (t)-symmetric matrix of dimensions n × n, which constitutes the solution for the Riccati differential equation [22,32,49]. For the mathematical model of the object described with ordinary differential Equation (5), we assume the quadratic coordinate of parameters quality as follows: where T ∈ [t 0 , t k ], t k → ∞, x (t) , u (t)-are, respectively, n and m dimensional vectors of state and control. Matrices A, B,Q, R, are assumed as constants, R > 0. River pollution levels control [25,50] is performed by introducing a particular amount of oxygen directly into the body of water. In order to select a type of control, the information specific to the current real river condition is required; then, the control will be more accurate. DO measurements can be obtained in a quick and easy way, but the obtaining of BOD value indicator is toilsome and requires laboratory conditions (BOD 5 or BOD 20 ), where the indicator index presents the number of days necessary to obtain credible results concerning the water polluted with organic compounds. This is why BOD values are estimated in the estimation process. For the actual considerations concerning the polluted river, we seek the controls described with the dependency: in which: k p1 , k p2 -are the regulator enhancement coordinates, x BOD , x DO -BOD and DO values, x BOD ,x DO -state estimate for BOD and DO [22,32,42,49,51].

Results
Using a river model based on the Streeter-Phelps equations, the kinetics of changes in biochemical oxygen demand and dissolved oxygen deficit has been described. The experimentations for the river described by Equations (1) and (4) has been performed according to the method described in Section 2.2. We consider the contamination state of freely flowing water, which is described by the vector x(z, t). Rivers have the ability to self-clean, i.e., as pollutants increase, the values of BOD and DO decrease with the passage of time. The existence of a large deficit of dissolved oxygen at high BOD values is a natural phenomenon, which in the case of high oxygen demand generates an increase in the DO deficit. During the simulation experiments, among others, two emergency states were adopted that could occur under real conditions (see Table 1). It was assumed that a system that responds appropriately to such critical initial conditions will function properly in the real conditions of the standard levels of pollutions in the river. It was noticed that BOD had a significant influence on DO. An interesting phenomenon can be observed when inflowing pollutants have a value several times greater in mg/L. As a result, the greatest oxygen deficit (the most dangerous conditions for living organisms) can be observed after a few days and a several dozen kilometers away from the pollution inflow (see broken red line, Figure 11). Table 1. Initial values of parameters for the considered river section.

No. BOD (mg/L) DO (mg/L)
A t (Day) v (km/Day) k 1 (Day −1 ) k 2 (Day −1 ) k 3 (Day −1 )  Taking into consideration a long river, it can be conventionally divided, e.g., between large inflows, and the part between them treated as a segment. The presence of large pollution inflows over a short distance causes dangerous conditions in rivers for the lifeforms. The inflows cause a significant and sudden change of BOD and DO values (see Figure 12). The observed changes in BOD and DO values with respect to lateral inflows are summarized in Table 2. Table 2. Selected parameters of the studied river section taking into account the three inflows. Inflow III BOD (mg/L) 30 The largest DO deficit was noted when the third inflow occurred after ten days of observations. The situation presented in Figure 12 shows the conditions of great oxygen deficiency for a long period of time negatively affecting the water quality that can threaten the life of organisms in the water. Analyzing the time courses, it can be observed that the largest oxygen deficit downstream "shifts" with regard to the side inflows. Up to now, the actual state of water in the river described by the vector x(z, t) depends on the length of the considered river section and time. In order to obtain a distribution of BOD and DO values for any pair of independent variables z and t, we must solve the equation for many characteristics taking into account the following boundary conditions: • boundary conditions-at the beginning of the considered river section in the time domain • initial conditions-at the moment t = t 0 along the length of the considered river section.
Hyper-surfaces for BOD and DO, which significantly reflect real river conditions (see Table 3), are the solution for the mathematical model with distributed parameters (6)- (8). Figure 13 presents BOD and DO distributions for steady edge conditions, BOD and DO values decrease over the course of time and length. Table 3. Initial values for the spatial distribution of changes in BOD and DO. A further experiment concerned both the changeable initial and edge conditions occurring in the river. Real river conditions, such as variable initial conditions and occurrence of side pollution inflow variable in time were taken into consideration. The results and pre-assumed initial values of the parameters are shown in Figure 14. Extortions in the form of spikes in BOD and DO values were observed at the initial point of the analyzed river segment and at the time when the side inflow occurred. A sudden change of values remains for a particular period of time, and, after that, the values return to the previous state. In the considered BOD ad DO space-time distribution, the spikes which appear on the "diagonal" decrease, which results from the river self-purification process. The pollution inflow variable in time causes the first pollution spike below the first inflow, which runs parallel to the second spike.

BOD (mg/L) DO (mg/L)
10 v (km/day) 20 Speed has a significant influence on BOD and DO distribution. Carrying out experiment for various values of river speed, a different location of pollution spread against the time axis was observed in Figure 15:    It was observed that the placement of pollution "marks" changes accordingly with the increase of river flow speed. Therefore, the river speed is a crucial factor that causes variable placement of pollutants in rivers. The higher the river speed, the distance of the location of pollution concentration tends to increase. The self-purification process has too little time to reduce these values. The conducted studies showed little impact of the diffusion at equally high speeds of river flows. The diffusion was excluded from further considerations [32,34,[52][53][54].
Using the proposed intelligent filtration and prediction module, a number of experiments were conducted for the investigated river object with two inflows. As a result BOD and DO distribution was obtained, which shows a correct ANN reaction to the introduced estimate value ( Figure 16). As it can be observed, the values of estimates follow the BOD values. The training process has a significant influence on the accordance of estimates according to the expected courses. In extreme cases, the network significantly distorts estimates against their real values. Using artificial neural network in the filtration and prediction phase improved the accuracy of estimation process. Net gives more precise estimates of river state than classical Kalman's filter. It is easy to see from results of experiments that a neural network has also higher resistance to noises, changes of distance between measurement stations and leap changes of pollution indicators' values (inflows). Moreover, applying the neural network allows a solution of knowledge of actual river parameters. It is hard to determine in practice. In addition, by proper selection of learning data on network answers can be improved in a specified range of pollution indicators values ( Figure 17). In Figure 18, plots representing the training, validation and testing data have been presented. The dashed line in each plot represents the perfect result − outputs = targets. The solid line represents the best fit linear regression line between outputs and targets. The R value is an indication of the relationship between the outputs and targets for BOD and DO, respectively. Training data indicates a relatively good fit of the ANN to river model. The validation and test results also show large R values. The scatter plots show the existence of several points badly fitted by ANN. The quality indicator for comparison of the accuracy of estimation by Kalman's filter and artificial neural network was applied as follows: where X,X-state and estimate of river state, n-number of measurements. The mean squared error is the accepted standard indicator for the performance evaluation, which we applied to assess the proposed methods.
The obtained results, shown in the table above, encompasses quality coefficient values for six different configurations of the river model. The results confirm that artificial neural network gives more precise estimates of river state than classical Kalman's filter. The quality indicators of BOD are greater because there is no information from measurements about that pollution indicator. Common analysis of Pearson coefficient (see Figure 19) and J indicator allows the assessment of the quality of the methods used. For DO, the Pearson index has values closer to 1, which implies that both methods achieved a similar performance level. On the other hand, for BOD, the lower values of the J (see Table 4) indicator and the Pearson coefficient clearly indicate the higher efficiency of ANN in relation to the Kalman filter in the estimation process.  The river self-purification ability depends on biological processes that require a particular amount of oxygen. Calculating the control on the basis of DO deficit would appear to be easy and precise. Taking into consideration the character of the river processes, it may turn out to be insufficient as the ignorance of BOD may cause unexpectedly low DO values. A series of conducted studies included various conditions occurring in the river. Figure 20 shows a situation for the control including only DO indicator. The initial values of the parameters used in the experiments are shown in Table 5, where: k F1 -filter gain coordinate for BOD, and k F2 -filter gain coordinate for DO. The values of coefficients k F1 , k F2 (20) and k p1 , k p2 (44) were determined on the basis of Riccati equations for the filter and for the regulator assuming experimentally selected values of elements of the matrices of W r , V and R, P, respectively. These values were determined by means of actual measurements carried out for the Wislok River in years 2011-2015. Modification of the parameter values resulting from the hydrological profile of the river, and the obtained measurement accuracy resulting from the applied measuring devices has a key impact on the final quality of monitoring and control of water quality.

Name Value
In the initial stage, DO deficit has low values and BOD high values. The control system that functions based on DO indicator does not fully react to the pollution as DO level is normal. Over the passage of time as a result of the increase in oxygen deficit caused by high BOD value, the system generates the control, but it may turn out that it is too late for an effective reaction-large deficits of DO still persist. The execution of control considering BOD indicator with a few days delay (laboratory service) is useless. The BOD indicator values in the proposed system are obtained from the estimation process. In order to precisely determine the amount of oxygen that is to be delivered to the body of water, the BOD estimate is used. Moreover, it is worth emphasizing that delivering too small or large amounts of oxygen is disadvantageous. The best solution is to calculate the controls based on BOD and DO indicator. On the basis of the current BOD values, too large of a DO deficit can be determined, and also precisely takes oxygen that must be introduced into the body of river. The conducted simulation studies are presented below.
Introducing the control based on BOD and DO caused the system to react sufficiently early, which prevented the development of unfavorable conditions in the river and allowed the maintenance of DO values close to the assumed level. The experiments were carried out regarding various initial conditions for BOD and DO values and the influence of enhancement coefficients k p1 , k p2 . Figure 21 shows the distribution of DO deficit with control for different values of k p1 i k p2 for initial conditions BOD = 30 (mg/L) and DO = −6 (mg/L). The control occurred in three places due to the occurrence of undesirable biological conditions in the river. Here, we see a significant influence of the value of the gain factor of the regulator. Small amplification values cause a lesser response to the change in DO during the control, leading to increased occurrence of hazardous conditions in the river. The assumptions concerned the occurrence of large DO deficit at low BOD values and also a situation when high BOD values appear in the river at small DO deficit ( Figure 22). The control system in the initial part of river segment based on DO indicator does not react to the appearing pollutants as DO level is normal. By contrast, the system reaction, based on both indicators, is observable at the very beginning of the river segment. As the distance and time pass, the oxygen deficit increases that threatens biological life in the water. When the pollutants inflow, the system reacts and improves the condition of water. The most satisfactory conditions in water are obtained during the use of BOD and DO control.

Conclusions
In the paper, the use of artificial neural networks to solve the problem represented by BOD and DO indicators has been presented. Neural networks were used to solve the problem of monitoring and controlling water quality in the river in real time. The analysis and control process was carried out using two BOD and DO indicators. The difficult-to-measure-in-real-time BOD indicator of water quality was estimated by ANN in real time, enabling monitoring of the river in real conditions. The above studies present a positive situation when the state estimation is used, especially when large amounts of pollutants occur in various places. Traditional process-based modeling methods concerning the biochemically polluted river control can provide less accurate estimations and predictions for water quality parameters represented by BOD and DO indicators. The conducted experiments with the use of ANN proved that the river pollution level control concerning both indicators generates better results than the control with the use of Kalman-Bucy filtering. Data generated by ANN for both indicators minimizes the occurrence of dangerous conditions in the river that can lead to an ecological disaster. Enhancement values are also significant during the control as they positively influence the course of biochemical pollution decomposition. Traditional models need data sets that require a long time to process and a large amount of input data that are often unknown. The use of the Kalman-Bucy filter is associated with the need to know many parameters of the river and especially the covariance of errors. In practice, it is difficult to estimate them, which leads to estimation errors. The determination of these parameters also requires a large amount of calculation. The ANN is a very effective technique that is capable of identifying complex nonlinear relationships between input and output data when compared to classical control technique based on Kalman-Bucy filter. In the paper, two approaches were proposed using ANN for the execution of estimation process. The former represents a separate network system for BOD and DO estimation while the latter concerns two neural networks that function in parallel. In both cases, correct results were achieved, but the second case was more universal. Because of the fact that water quality forecast can be simply affected by external environment, we observed that trained networks sometimes produced results that greatly deviated from the actual values. Therefore, further investigations needs to be conducted in future work to identify a more accurate forecast model. The observation of R coefficient values at consecutive stages of ANN training, validation and testing confirmed the efficient performance of the proposed intelligent filtration and prediction module. The obtained quality of BOD estimation by ANN in comparison to the quality of estimation obtained with the use of Kalman-Bucy filter shows the advantage of the first method. To estimate the ANN reliability level, we also performed network sensitivity tests by perturbing the BOD variable. The experiment has shown that the network output is sensitive to random changes of BOD concentrations. The amount of error increase reached 35% when the BOD concentrations has changed by 15%, while it reached only 6% when the BOD concentrations has changed by 8%. The obtained results of simulation studies allow the formulation of the main conclusion that it is possible to control the river aeration based on the measurements of particular state coordinates and the use of estimation process that completes the "knowledge" concerning unmeasured data. Although the comparison of ANN to the Kalman-Bucy filter shows the advantage of the former, in order to strengthen the objectivity of the quality assessment of the proposed system as a continuation of research, other indicators used in forecasting issues should be taken into account, e.g., the Nash-Sutcliffe efficiency coefficient, the median absolute percentage error, or the Persistence Index, recently proposed in works [11,14]. Another advantage of the proposed method concerns the ability of the system to simulate virtual states of river ecological condition without the risk of disaster in the actual subject. Of course, the ANN performance is limited by the range of the extrapolation effect obtained while learning the neural network. Based on the studies and observations, the authors state that it is possible to increase the accuracy of the adaptive BOD estimation mechanism. This effect can be achieved by extending the estimation error horizon by selecting the appropriate size of the time window. Information about the error rate history in the control system can increase the accuracy of the change in the value of the gain factor. The monitoring and control of a particular river segment with the proposed system will be significantly improved by expanding the monitoring infrastructure to the river inflows. This research work has managed to integrate several analytical and modeling methods that would prove to be useful for various institutions that are directly involved in the management of Wislok river water quality in the Carpathian mountains in the south of Poland.