Artificial neural networks to control chlorine dosing in a water treatment plant

Artificial neural networks in the multivariable control of chlorine dosing in the postchlorination stage in a water treatment plant in the Greater São Paulo, Brazil, are analyzed. The plant has constant fluctuations in chlorine demand caused by natural influences related to raw water from surface source. Modeling and computer simulation were implemented in MATLAB/Simulink environment, according to the physical and operational characteristics of the water treatment plant. Moreover, a Proportional-Integral (PI) controller was incorporated to provide better stability. Simulation results showed improved stability of free residual chlorine when compared to method currently employed, i.e. Proportional-Integral-Derivative (PID) controller that would reduce chlorine consumption in water treatment process.

State-of-the-art technology has made the use of equipment for the automatic control of dosage increasingly present, such as dosers with electronic drives, online tools for measuring physical and chemical parameters of water, Programmable Logic Controllers (PLCs) and Supervisory Control and Data Acquisition (Scada) (Liu et al., 2013;Dubey, Agarwal, Gupta, Dohare, & Upadhyaya, 2017).Due to technological improvement in automation equipments, the implementation of Computational Intelligence resources becomes useful to solve complex problems in non-linear processes (Santos, Librantz, Dias, & Rodrigues, 2017).
According to Kulkarni and Chellam (2010), the use of Artificial Neural Networks for the disinfection process may enhance over time microbial inactivation prediction and other physicochemical water parameters, such as temperature and pH, when compared to traditional methods of determination.Chlorine dosage produces free residual chlorine in treated water and ensures sanitization of the distribution network (Fisher, Kastl, Sathasivan & Jegatheesan, 2011).Several studies determined the free residual chlorine rates throughout the distribution network as a prediction of rates in the network, after a specific period.Predicted rate was calculated from physical and chemical parameters of previous periods forwarded during the training of artificial neural networks (Rodriguez & Sérodes, 1996;Rodriguez, West, Powell & Sérodes, 1997).Alternative studies on measurement and management of free residual chlorine have been performed, such as decentralized monitoring in a distribution system to investigate the possibility of reducing residual rates (Soyupak et al., 2011;Chang, Gao, Wu, & Yuan, 2011;Islam, Sadiq, & Rodriguez, 2013;Ammar, Abid, El-Bindary & El-Sonbati, 2014;Babaei, Tabesh, & Nazif, 2015).
Current analysis proposes a multivariable control for post-chlorination dosage system in a WTP using artificial neural networks applied to the disinfection process to reduce free residual chlorine variations of treated water in the water tank and, consequently, in the main water distribution.
The disinfection process is an important step for water and effluent treatment, frequently using chlorine as a chemical agent (Fisher et al., 2011).The system requires a multivariable control which presents several negative issues, such as temperature variation and level reservoir variation dynamics causing a nonlinear behavior.The proposed control system predicts changes in WTP flows and compensating system, free residual chlorine of the filtered water and clearing system to achieve a setpoint rate at the output of the treated water tank.

Artificial neural networks
The main goal of artificial intelligence techniques is the development of computational solution, or algorithms, capable of performing cognitive tasks.In other words, intelligent systems are used in a range of applications wherein human knowledge, or a knowledge base of an environment, is available (Singh & Gupta, 2012;Gour & Gour, 2014).
The performance of the artificial neural network is measured by the mean squared error (MSE) and mean absolute error (MAE), respectively shown in Equation 1 and 2 (Ayodele & Auta, 2012;Zenooz et al., 2017): where: t i is the desired rate; y i is the rate obtained at the ANN output; N is number of samples.
The Levenberg-Marquardt (LM) algorithm has been used in current paper for neural network training.According to Hagan and Menhaj (1994), although LM is much higher for each computational iteration, it is greatly applicable due to its increased efficiency.In addition, LM is very efficient with training networks with a few hundred weights.In current assay, neural network structure has less than one hundred weights, since the hidden layer varied between 10 to 16 neurons and the ANN model had six inputs.It should be noted that LM algorithm is an approximation to Newton's method while back propagation is the steepest descent algorithm (Hagan & Menhaj, 1994).Thus, in function ( ), which should be minimized with respect to parameter , the Newton's method is given by Equation 3: On the other hand, the Gauss-Newton method may be written Equation 4: where: ( ) is the Jacobian matrix and ( ) is a vector of network errors.According to modifications in the Gauss-Newton method, LM algorithm is given by Equation 5: Moreover, according to Hagan and Menhaj (1994), when scalar parameter μ is large, the algorithm becomes gradient descent; when μ is small, the algorithm becomes Gauss-Newton.In this paper, μ = 0.001 has been used as a starting point.

Problem description
The WTP under study is located in the metropolitan region of São Paulo and has a nominal production flow rate of approximately 0.9 m 3 s -1 .This amount may be reduced during periodic maintenance of equipment or according to consumption demand.
Further, the physicochemical parameters of raw water of the water source (river) change course, especially during the rainy season, and cause fluctuations in the rates of free residual chlorine (FRC) during treatment up to the post-chlorination stage.Figure 1 illustrates the setup process that involves post-chlorination in the WTP under analysis.
Figure 1 demonstrates the water compensating system intended to complement the treated water tank of the WTP with water from another production system located in another city of the Greater São Paulo to attend to the pumping flow of the high lift pump.The flow of treated water from the compensating system varies between 0.0 and 0.4 m 3 s -1 and has a free residual chlorine (FRC) rate of approximately 1.1 mg L -1 The amount of free residual chlorine in the reservoir outlet is designed to control the dosage of post-chlorination so that water is distributed with free chlorine residual of 2.5 ± 0.2 mg L -1 (set-point).The filtered water flow may vary between 0.0 and 0.9 m 3 s -1 according to the WTP´s production flow, with free residual chlorine of approximately 1.5 mg L -1 .
Mathematical modeling and implementation with artificial neural networks Dieu, Garrett Jr., Ahmad, and Young (1995) proposed a single variable Proportional-Integral-Derivative (PID) chlorine control dosage, with all the required devices, such as online analyzer free residual chlorine, PLCs and chlorine dosers, demonstrating a control loop similar to that used in WTP under analysis.Since the WTP postchlorination dosage has several variables that directly impact the FRC rate in the treated water, the use of the traditional PID controller is restricted, as reported by Escobar and Trierweiler (2013).The use of Computational Intelligence resources becomes favorable to understand the flow signals from processes that directly impact dosage, set-point and critical measurement points of free residual chlorine.Thus, the modeling of the proposed system includes six input variables: (i) Set-point output of the reservoir (SP FRC ) in mg L -1 ; (ii) FRC output of treated water tank (FRC RES ) in mg L -1 ; (iii) FRC output of WTP (FRC WTP ) in mg L -1 ; (iv) WTP's production flow rate (FLOW WTP ) in m 3 s -1 ; (v) Compensating system flow rate (FLOW SC ) in m 3 s -1 ; (vi) Dosage error.The set-point rate (SP WTP ) at the output of the artificial neural network merely provides reference employed in the control to have the required free residual chlorine required in the WTP's treated water output and consequently achieve limits determined by set-point at the output of the treated water reservoir.Dosage output corresponds to the chlorine mass effective rate that chlorine dosers apply at the post-chlorination point.
Data set was normalized with limits between -1 and 1 for use with a tangent hyperbolic activation function.Stopping criteria for training the neural networks comprised the desired mean squared error and/or the maximum number of 500 epochs.Levenberg-Marquardt training algorithm was employed and the number of neurons in the hidden layer varied between 10 and 16 neurons.Table 1 shows the parameters used for neural network training.The neural networks database for training and validation has 15325 and 2700 records, respectively.Control based on artificial neural networks was developed and simulated with all the variables that comprise the WTP post-chlorination system under study so that the disturbances may be observed and corrected by control.Figure 2   As previously mentioned, the foreseen entries were filtered water flow rate, compensating system flow rate, FRC output of treated water tank (FRC RES ), FRC output of WTP (FRC WTP ), set-point output of the reservoir (SP FRC ) and error (Dosage error).Implemented dosage variables (Dosage) and WTP setpoint output (SP WTP ) were implemented at the exit.The variable FRC filtered water (FRC FW ) was inserted to simulate FRC that reached the high lift suction pump referring to previous dosage chlorine processes.Figure 2 shows the modeling diagram for simulation, with all input and output variables.FRC calculation block, tagged 'Calculation block' in Figure 2, is shown in Equation 6, and the error calculation regarding Dosage input error is shown in Equation 7: where: FRC TW is FRC dosed by control in mg L -1 ; D is chlorine dosage in kg s -1 and Q FIL is WTP filtered water flow rate in m 3 s -1 .
where: Error is error calculated in mg L -1 ; SP WTP is FRC setpoint in WTP treated water output; FRC WTP is FRC in WTP treated water output; k is constant gain; i is the lower limit of the integrator; j is the upper limit of the integrator.
Figure 3 demonstrates the proposed model for closed-loop control using ANN and PI controller.

Results and discussion
Training with neural network topologies was carried out with 10-16 neurons in the hidden layer to detect the best performance.Table 2 shows the mean squared errors for the proposed topologies, calculated according to Equation 1.According to Table 2, the topology with 15 neurons in the hidden layer had the lowest mean squared error among the neurons tested, with 96 epochs, with processing time of 12.6 s.
Generalizations of artificial neural network in relation to the desired value or required to control chlorine dosage were verified at the validation stage.Figure 4a shows a comparison of the required dosage and the general rate of the artificial neural network, while Figure 4b illustrates the referential rate required of residual free chlorine at the WTP output and distributed by the artificial neural network.Figures 4a and b show a strong correlation between ANN outputs and the desired rates.As a result, it seems that the training step and the selected data were adequate.In the simulation stage, the free residual chlorine rates in WTP output under study and the corresponding set-point (SP WTP ) to this point were observed so that any changes in the flow rate of the water compensating system are compensated to keep the output free residual chlorine in the water tank within the operationally treated limits.
Further, Figure 5a and b illustrate the simulated behavior with the parameters of Scenario 1.
Without the compensating system in this simulation, there is no need to change the set-point (SP WTP ); rates near the set-point (SP RES ) remain. Figure 5a shows stability of set-point (SP WTP ) and small variations of free residual chlorine in treated water at the WTP output, opposite control action due to variations submitted the dosage step prior chlorine, or FRC filtered water at 1.5 mg L -1 , with variations ± 0.35 mg L -1 used in the simulation.Figure 5b illustrates the error between the set-point (SP WTP ) and the free residual chlorine in the WTP output, between -0.00271 and 0.00046 mg L -1 .Maximum and minimum rates are lower than the operational limits ± 0.20 mg L - 1 applied to the set-point.
Figure 6a and b show simulation results in Scenario 2. The difference in this simulation is the use of water compensating system in the postchlorination dosage system.The same WTP characteristics in Scenario 1 were considered in this simulation, except for the inclusion of water in the compensating system of the treated water tank.Consequently, the set-point (SP WTP ) was modified to keep free residual chlorine in the output within operational limits.Scenario 2 required adjustment of chlorine dosage due to variations in the above required processes of dosage chlorine and changes on the set-point (SP WTP ).However, free residual chlorine in the WTP output accompanied the set-point (SP WTP ) satisfactorily before the disturbances to which the model was submitted.The error between these two quantities ranged between -0.00291 and 0.00074 mg L -1 .
Figure 7a and b give results from Scenario 3, corresponding to the control flow behavior with the production of the reduced WTP.Comparing Figure 6a and 7a, results show the variation in the amplitude of set-point (SP WTP ), similar to Scenario 2. However, a greater range, caused by WTP flow decrease, has been reported in the simulation, coupled to the permanence of the same flow within the water compensation system.The latter is necessary to control the free residual chlorine at the reservoir output, according to plan.
Similar to Scenario 2, the control changed chlorine dosage so that free residual chlorine at the output of WTP was kept near the set-point (SP WTP ) at the given instant.Figure 7b shows that error variation between the two magnitudes remained between -0.00399 and 0.00095 mg L -1 .Control would generally establish chloride concentration in the post-chlorination appropriate to the various setpoint rates (SP WTP ) with each simulated scenario.The above reveals that the compensating system is a major disturbance to the system and becomes more critical in reducing WTP flow.In the three proposed scenarios, mean absolute error (MAE) between setpoint (SP WTP ) and the free output WTP´s residual chlorine were calculated, according to Equation 2. MAEs are shown in Table 3.

Scenario
Mean Absolute Error (MAE) 1 0.00029 mg L -1 2 0.00032 mg L -1 3 0.00038 mg L -1 current WTP 0.083 mg L -1 When MAE for simulated scenarios is compared with WTP under analysis, 0.083 mg L -1 , it is possible to obtain a reduction of 200 times by employing the proposed control.Furthermore, a reduction may be obtained in the consumption of chlorine used in the post-chlorination between the current situation and the proposed 2400 kg of chemical product during a 1-year period.Pastre et al. (2002) suggested maintaining free residual chlorine in the reservoir output between 0.8 and 1.2 mg L -1 , or to a specific rate of the set-point and the operational limits ± 0.20 mg L -1 , as used in WTP study, merely differentiating the set-point at each location.However, the model proposed in this article resulted in lower ranges, which favor the reduction of operating limits currently used in WTP.Furthermore, the proposed system reduces the manual interference in case of abrupt changes in flow rates to maintain free residual chlorine within the operational limits.

Conclusion
In current study, a multivariate post-chlorination dosage control system employing an artificial neural network was used.The three scenarios for the simulation are considered adequate for WTP operating, reducing potentially the limits of current control, especially when compared to conventional PID control and, consequently, contributing to reduce operational costs.Moreover, it should be underscored that there is no technological limitations in the current automation system on the plant to implement proposed control system.Further research may include reservoir detention time and temperature parameters to the proposed model.

Figure 1 .
Figure 1.Schematic diagram of the process that involves post-chlorination in the WTP under analysis.
® for the simulations.

Figure 2 .
Figure 2. Diagram of the computing environment MATLAB/Simulink® for the process simulation.

Figure 3 .
Figure 3. Proposed model for closed-loop control using ANN and PI (proportional and integral) controller.

Figure 4 .
Figure 4. Correlation between (a) desired dosage value and ANN output; (b) desired SPWTP (set-point in the water treatment plant) value and ANN output.

Figure 5 .
Figure 5. (a) Control behavior of the free residual chlorine set-point for the scenario 1; (b) error rate calculated between the simulated and measured set-point in the scenario 1.

Figure 6 .
Figure 6.(a) Control behavior of the free residual chlorine set-point for the scenario 2; (b) error rate calculated between the simulated and measured set-point in the scenario 2.

Figure 7 .
Figure 7. (a) Control behavior of the free residual chlorine set-point for the scenario 3; (b) error rate calculated between the simulated and measured set-point in the scenario 3.

Table 1 .
Levenberg-Marquardt parameters used for neural network training.

Table 2 .
Errors rates with different neurons numbers obtained during neural network learning step.

Table 3 .
Mean absolute error (MAE) obtained for different scenarios.