Computers and Chemical Engineering

During the last years, machine learning-based control and optimization systems are playing an important role in the operation of wastewater treatment plants in terms of reduced operational costs and improved eﬄuent quality. In this paper, a machine learning-based control strategy is proposed for optimizing both the consumption and the number of regulation violations of a biological wastewater treatment plant. The methodology proposed in this study uses neural networks as a soft-sensor for on-line prediction of the eﬄuent quality and as an identiﬁcation model of the plant dynamics, all under a neuro-genetic optimum model-based control approach. The complete scheme was tested on a simulation model of the activated sludge process of a large-scale municipal wastewater treatment plant running under the GPS-X simulation frame and validated with operational gathered data, showing optimal control performance by minimizing operational costs while satisfying the eﬄuent requirements, thus reducing the investment in expensive sensor devices.


Introduction
Water management is currently facing a major challenge. Europe has the responsibility to meet the objectives set by the 20 0 0/60/EC Water Framework Directive of the European Parliament and to ensure the protection of water while promoting its sustainable use to safeguard the availability of this precious longterm natural resource ( The European Commission, 2015 ). Wastewater generated by human activity is currently a serious problem and one of the most important sources of pollution for watercourses and aquifers. The increasing volumes of wastewater with high pollutant loads that our society produces, requires extensive and intensive wastewater treatments.
Technologically advanced alternatives to solve the purification problems are available on the market, and with their implementation it would be possible to curb the appearance of pollutant discharges and their consequences, as well as facilitating their prevention. Santin et al (2017) described the application of effective treatments in costs of both operation and maintenance to improve * Corresponding Author.

E-mail addresses:
ffernander@uma.es (J. Fernandez de Canete), pabsazhua@uma.es (P. del Saz-Orozco), jmgomez@uma.es (J. Gómez-de-Gabriel), roberto.baratti@dimcm.unica.it (R. Baratti), aruano@ualg.pt (A. Ruano). water qualit. Additionally, the efficiency of a water treatment plant is strongly linked to the energy consumption of plant actuators, mainly pumping costs and the cost of the sensory system and laboratory analysis necessary for plant state monitoring. Therefore, an optimized treatment at a global level would entail a huge reduction in operating costs, and a notable reduction in levels of effluent pollution ( Hreiz et al., 2015a ;Kim et al., 2105 ;Asadi et al., 2016 ;Zhu and Anderson, 2017 ).
Currently, advanced control and optimization systems are playing a fundamental role in the operation of wastewater treatment plants, as they allow efficient plant management ( Hreiz et al., 2015 b). The active sludge process is one of the most used technologies for the removal of organic pollutants, nitrogen and phosphorus in wastewater ( Van Haandel, 2012 ) and can be considered as a complex dynamic system characterized by a non-linear behaviour, uncertainty in process parameters, external disturbances due to atmospheric phenomena, and a multivariate I/O structure ( Makinia, 2010 ).
On-line monitoring and control of active sludge process effluent variables such as chemical oxygen demand and total nitrogen, are difficult to perform, since either they are usually determined off-line under uncertainty or they require expensive sensors, which implies a strong operational restriction ( Akına and Ugurlu, 2005 ). Using software sensors allows the estimation of these off-line primary variables through the use of on-line secondary variables ( Haimi et al., 2013 ). In addition, on-line control strategies that take into account the dynamic behaviour of the activated sludge process should also consider optimizating control operation to reduce the energy consumption associated with aeration and pumping processes ( Gernaey et al., 2014 ). Several studies have investigated this problem when applied to an active sludge process using dynamic optimization methods ( Fikar et al.,20 05 ;Mulas,20 06 ), or model-based predictive control schemes (Bryds et al., 2008 ;Piotrowski et al, 2008 ;Han and Qiao, 2014 ).
Machine learning-based methodologies, defined as a set of algorithms that allow performing tasks of identification, control, and plant optimization based on a set of registered operational data represented with multiple levels of abstraction are increasingly in use. For this purpose, they make use of connectionist structures of artificial neural networks (ANN) with multiple layers ( Haykin, 2008 ). On the other hand, genetic algorithms (GAs) are used both for optimizing the structure of large neural networks and extracting characteristics that can be used for the tasks of identification and optimal control ( Lamos-Sweeney, 2012 ).
Neural networks have been successfully applied for the prediction and control of wastewater treatment plants ( Baruch and Mariaca-Gaspar, 2009 ) and different adaptive schemes have been used as software sensors, either based on neural networks ( Dogan et al, 2008 ;Fernandez de Canete et al., 2016 ) or hybrid schemes ( Noori et al., 2013 ) to estimate effluent characteristics. Genetic algorithms are heuristic search algorithms that derive their behaviour from evolutionary processes in nature and perform complex nonlinear optimization tasks such as non-convex problems, non-continuous objective functions, etc. GAs have been successfully applied in the field of biological wastewater treatment for optimization and control ( Holenda et al., 2007 ;Duzinkiewicz et al., 2009 ;Piotrowski, 2016 ).
The combination of hybrid GA systems with neural networks facilitates the search for the optimum in comparison to the local and global search optimization methods such as sequential quadratic programming, or reduced generalized gradient ( Hreiz et al., 2015 b). Bagheri et al. (2015) developed hybrid artificial neural network-GA models to predict the sludge volume index (SVI) accurately, where genetic algorithms were used to optimize weights and thresholds of the neural network models. A method to increase the efficiency of water treatment plants which adjusts operating requirements based on the nature of the water was presented in De (2019) , preventing the unnecessary waste of plant resources. Nevertheless, to our best knowledge, there are hardly any works where neural networks and GAs are applied together for the optimum control of wastewater treatment plants.
Despite the good results obtained using these adaptive estimation and control structures applied to the control of biological reactors, it is necessary to highlight their lack of application to wastewater plants in real-time since most of these applications are based on simulation models using an unusually low, and unrealistic, sampling time ( Fang et al., 2011 ;Qiao et al., 2013 ).
In this paper, a machine learning approach was applied both to predicting effluent variables and modelling a nonlinear wastewater process using neural networks. These neural models, combined with a genetic algorithm-based scheme, were effectively used for the optimum control of an activated sludge process-simulation model running under GPS-X framework using a function involving aeration, pumping and disposal costs. The proposed neurogenetic control strategy optimized both the consumption and the number of regulations violations during plant operation while the sampling-time selection would enable its application to real-time wastewater plants monitoring and advanced control. This paper is organized as follows: In Section 2 , the activated sludge process is described together with the activated sludge pro-cess simulation model under GPS-X. Both the neural network soft estimation and the neural identification structure are detailed in Section 3 , together with the derivation of the objective cost function used for the neurogenetic control and its corresponding design. The performance of both the neural plant model and the neural soft estimator for chemical oxygen demand (COD), total nitrogen (TN) and total suspended solids (TSS) applied to the referred activated sludge plant model are shown in Section 4 , where the performance of the neurogenetic controller under dry, rainy and stormy conditions is also shown with promising results. A discussion section is included, detailing the advantages and limitations of the proposed approach and comparisons with other alternate solutions and a final summary is also described in Section 5 to explain the motivation followed here. Finally, future works will be presented in Section 6 .

Wastewater process description
The wastewater plant under study treats an average 20,0 0 0 m 3 /d influent flow rate, whose wastewater treatment line consists of bar screening, grit removal, pre-aeration, primary sedimentation, activated sludge bioreactors, secondary sedimentation and a chlorine disinfection unit. The sludge treatment is achieved using an anaerobic digester. The removal of nitrogen and organic matter is accomplished in the activated sludge process by employing a 80 0 0 m 3 bioreactor consisting of an anoxic denitrification sector followed by aerobic nitrification with airflow supplied with fine-pore diffusers. The microbiological population is maintained through both internal recirculation of sludge removed from the aerobic basin and external recirculation of settleable sludge withdrawn from a 60 0 0 m 3 secondary settler. The quality of the wastewater entering the bioreactor and the process operation are monitored mainly by laboratory measurements, such as chemical oxygen demand (COD), total nitrogen (TN) and total suspended solids (TSS).
The activated sludge process of the WWPT under study is represented by a BSM1-type activated sludge process model ( Alex et al., 2008 ) to describe the removal of organic and nitrogen compounds in the bioreactor and the double exponential settling model ( Takacs et al., 1991 ) for the secondary clarifier. According to the sensor layout of the bioreactor ( Fig. 1 ), two anoxic denitrification ( d ) areas representing the 40% of the total volume and three aerated nitrification ( n ) areas representing the 60% of the total volume are included. It should be highlighted that oxygen is provided to both anoxic and aerobic zones so that we should consider two slightly aerated tanks in series with three aerated tanks. Fig. 2 shows a GPS-X 6.0 computer simulation model of the BSM1 process (Hydromantis 2016 ).
In this work, we assume the accessibility to the most commonly used sensors and analysers. The wastewater plant considered is assumed to be equipped with on-line sensors to measure the flow rate Q in and ammonia NH + 4 in in the influent, while dissolved oxygen O 2 and dissolved nitrate N O 3 sensors and alkalinity ALK analysers are arranged in each tank, with additional on-line sensors to measure ammonia NH + 4 out and alkalinity AL K out in the effluent. The bioreactor operation include the pumping of external recycle flowrate Q r , waste sludge flowrate Q w and constant internal recycle flowrate Q A , while fine-pore air diffusers generate an airflow rate Q a to be distributed by the basins. Additionally, off-line laboratory measurements of COD , T N and T SS concentrations were also taken both for the influent and effluent streams. Table 1 shows a list of measurement, control and disturbance variables involved into the BSM-1 WWTP operation.
Following Alex et al. (2108), the influent dynamics are generated considering a whole year after a stabilization period of 244  days. The average influent loads considered for the plant under study in these conditions are reported in Table 2 .
The steady-state and dynamic simulations of the process were realised in the GPS-X 6.0 modelling environment (Hydromantis, 2016 ), which uses a graphical user interface to facilitate dynamic modelling and simulation.

Neural soft-sensor, identification model and controller
The complete controlled system is composed of a neural network identification model of the process and a control scheme based on a genetic algorithm that uses the effluent values of COD, TN and TSS as input variables to get the quasi-optimal control law subjected to ASP operational constraints. It uses a neural soft-sensor estimator for both determining and monitoring these COD, TN and TSS effluent primary variables from secondary variable measurements ( Fig. 3 ).
The control strategy presented in this paper is based on a decision-making process using neural networks combined with GA. For each situation (the current and past states), the control scheme tries to reach the optimal decision (control action) according to the different possible scenarios (dynamic system modelled by a neural network) and the objective (goal), while assuring no violation of effluent constraints.
To make the design of both, the estimators and the neural model, as part of the neurogenetic control, specific tools were used in MATLAB code for dealing with the modelling and multivariable control of plants. The connection between the monitoring system and the MATLAB neurogenetic controller was realized through the MATLAB-GPS-X 6.0 interface.   Table 3 Effluent contraint conditions for the WWPT plant.

Chemical Oxygen Demand Effluent
C OD e f f out ≤ 100 gC OD/ m 3 Effluent Total Suspended Solids T SS e f f out ≤ 30 gSS/ m 3 Effluent Total Nitrogen T N e f f out ≤ 18 gN/ m 3 Effluent Ammonia NH This section is divided as follows. First, the neural soft-sensor estimator is presented, the main details of the neural identification model follow, and the complete control strategy is described last.

Neural soft-sensor
The use of software sensors to infer hard-to-measure primary variables from easy-to-measure secondary variables ( Han et al., 2018 ) is a common solution to overcome the drawbacks in the acquisition and maintenance cost of expensive TN and TSS online sensors ( Van der Broeke et al., 2014) or in the use of offline measured variables, such as COD . Furthermore, legal restrictions are set precisely for the maximum values of these primary variables regarding effluent concentrations. In our study, the constraints corresponding to these which are refrenced in the BSM1 report ( Alex et al., 2008 ) and listed in Table 3 .
A neural network-based soft-sensor was developed relating the wastewater plant concentrations ( COD, TN, and TSS at the effluent stream) with sampled values of secondary variables that could be measured on-line in a reliable, accurate and non-expensive way. The set of secondary variables were chosen among those provided by a sensory system that was assumed to be physically installed at the wastewater plant, and was also present in the GPS-X simulation model.
The neural soft-sensor is defined properly using a vector of in- where N N s is the soft-sensor function, θ s ∈ R θs is a vector of parameters (weights and biases) to be learned from operational data, T p is the estimation sampling interval, T s is the plant sampling interval and t is the actual time. The structure of the neural soft estimator is illustrated in Fig. 3 as part of the neurogenetic control structure.
To select the most suitable secondary variables for our control purposes, a multivariate statistical technique based on the PCA methodology reported in ( Zamprogna et al., 2005 ) was applied. The methodology is based on a so-called sensitivity matrix, which measures the degree of sensitivity of each secondary variable with respect to the primary variables. This matrix is normalized and using a PCA approach the directions (in this case meaning the secondary variables) with a higher sensitivity to the primary variables are selected.
To determine the order of the lag space that should be considered for each secondary variable, the proposed methodology by He and Asada (1993) was followed, resulting in a value of 20 lags for each secondary variable. Once the lag space was determined, specific past samples of each of the secondary variables of the set mentioned above were selected using the sensitivity matrix terms defined as the partial derivative of the different lagged variables with respect to the variables to be estimated.
After applying the selection method, the inputs to the neural soft estimation network turned out to be a subset of the delayed values of secondary variables . 5 sampled at T s = 15 min, whereas the outputs were given by ˆ estimations. These values were computed one-step ahead using a larger sampling interval of T p = 4 h = 16 T s , according to the off-line measurement procedure usually accomplished over the effluent stream in the full-scale plant. The I/O structure of the neural soft estimator is illustrated in Fig. 4 . Specific tools were used in MATLAB code to deal with the design, training, and validation of the neural estimator whose details are reported in Fernandez de Canete et al. (2016) .

Neural identification model
The goal of the identification model of the plant was to predict the dynamic behaviour of the WWTP plant by relating the evolution of the secondary variables to their current and past values together with the control input variables. The neural identification model is defined properly using a first vector of inputs x i ∈ R N x i of dimensionality N x i selected among the secondary variables, a second vector of inputs u i ∈ R N u i of dimensionality N u i corresponding to control inputs to the plant, and a vector of outputs ˆ y j ∈ R N y j of dimensionality N y j defining the estimations of a subset of secondary variables (excluded influent and effluent variables), all related by where N N I, j is the set of the identification model functions (one neural network j for each estimated secondary variable, j = 1 , . . . , N y j ), θ I, j ∈ R θ I, j is a vector of parameters (weights and biases) to be learned from operational data for each j . The structure of the multiple neural identification model is illustrated in Fig. 3 as part of the neurogenetic control structure. Therefore, the outputs of the multiple output neural identification model (predictions of O 2 and N O 3 concentrations, NH + 4 and alkalinity in tanks) were used in inferring the primary variables COD, TN and TSS using the neural software sensor described previously, while the input variables of the neural identification model were chosen among the secondary variables of the plant at previous time steps together with the output signals of the actuators (the airflow rates both in the anoxic and aerobic areas and the recirculation and sludge excess flowrates). Fig. 3 shows the neural identification structure as part of the neurogenetic control scheme.
The input layer dimension was selected using the multivariate statistical approach based on PCA, as was described formerly for the neural network soft-sensor estimator. The procedure is defined as follows. Due to the characteristics of the wastewater treatment process, up to 45 previous time steps, with sampling T s = 15 min, of each of the sensor measurements are considered as possible inputs for the identification network. In this way, if a similar notation as in the previous section is used, the secondary variables set would be . . 5 , whereas the output variables set would be the estimation of the referred secondary variables ˆ that are, in turn, a subset of inputs to the inference soft-sensor. The variable selection process is similar to the one in the previous section and the I/O structure of the neural identification model is shown in Fig. 5 .

Neurogenetic controller
Once the inference soft-sensor and the dynamic identification model of the plant were developed and validated, the next stage in the controller design consisted of developing the control subsystem. This subsystem is responsible for calculating the action that must be applied to the different actuators, so the system evolves following the desired path, taking into account a specific cost function.
For a given plant state history and control action, the evolution of the system will be forecasted using the dynamical model of the plant. Therefore, this subsystem should estimate a control action that minimizes the cost function while reducing the number of constraint violations. Thus, the future output of the system can be predicted depending on the control inputs and the plant state evolution through a nonlinear function.
In this way, the optimization problem for controlling the wastewater treatment process can be stated as a problem of finding the input that minimizes the norm of the cost function, multiplied by a weighting matrix between the reference command to follow and the neural network model output, considering as input and the past and current states of the wastewater plant.
As for the control strategy proposed in this paper, the control action will be estimated following an optimization schema based on genetic algorithms (GA). These methods are based on the genetic processes of biological organisms. Natural populations evolve according to the survival of the fittest principles. So the individuals that are better adapted to the environment tend to have relatively a higher number of offspring so that the genes from these highly adapted individuals spread to an increasing number of individuals in each successive generation. It should also be taken into consid-eration that the string characteristics from different ancestors can sometimes produce offspring that are even better adapted to the environment. In this way, species evolve to become better suited to their environment in an iterative way. One important advantage this kind of algorithms has is the fact that for obtaining the optimum, it does not depend on the derivatives of the function to optimize, so all kinds of functions can be optimized using this approach.
The proposed goals of the control strategy consist of minimizing both the operational costs and the effluent limits violations. In the case of the present study, the operational cost function T C(t ) will follow the expressions developed in Foscoliano et al. (2016) so that: where AE (t) , P E (t) and ME (t) are the aeration, pumping and mixing costs respectively, while SP (t) represents the sludge production disposal term, k E is the electricity price with an assumed fixed value ( Grave et al., 2016 ) and k D is the unitary disposal cost. The aeration energy cost over a certain time range T r can be expressed as follows: where K L a i is the oxygen mass transfer coefficient tightly related to the aeration flow Q a i in each tank, which are evaluated using the expressions from Hreiz et al. (2015 a), V i is the volume of each tank and S sat O is the oxygen saturation concentration. It should be noted that oxygen is provided to both anoxic and aerobic zones so that we should consider two slightly aerated tanks in series with three aerated tanks. The reason to provide oxygen to the anoxic zone is to improve ammonia removal to reduce the use of external carbon sources ( Foscoliano et al., 2016 .) The pumping cost is directly related to external recycle flowrate Q r , waste sludge flowrate Q w and internal recycle flowrate Q A (held constant) according to the expression:  (6) since the anoxic zones should be mixed to avoid settling conditions. Finally, the sludge disposal cost should be added as: where T S S x is the total solid concentration in the activated sludge reactors in the secondary settler and T S S w represents the total solid concentration in the waste sludge flowrate whose respective evolutions are estimated by using the dynamic clarificationthickening process described in Takacs et al. (1991) .
As previously stated, the second goal of the control strategy consists of minimizing the effluent limits violations. In this case, the Effluent Quality Index (EQI) will be used. This index is related to the fines paid due to discharging pollutants into receiving waters and is expressed as follows:  Because more than a single criterion is required to be optimized, a multi-objective control function was used. The 'Pareto dominance' concept will be used for the optimum search in which a given solution dominates another one only if it leads to an equal or better performance in every evaluation criterion. Therefore, a solution is said to be Pareto-optimal if any other feasible solution does not dominate it ( Hreiz et al., 2015 a).
So, the multicriteria function to be optimized can be expressed as: in this study so that the function to be minimized was evaluated in each time step ( t j ) with a time horizon of 4 hours, where only the first optimized control action will be applied. Therefore, in each time step, the optimization problem can be stated as: subject to I. The evolution process is approximated according to the neural identification model set N N I and the neural-soft predictive sensor N N s presented in previous subsections. Therefore ˆ II. In each time step the initial conditions will be used as the state of the system at the given time. III. The control actions will be restricted by the operational constraints imposed by the actuators. So, u ∈ R 10 with 0 ≤ u i ≤ u i,max ∀ t, as there are 7 control input u t = { Q r , Q w Q a i } i = 1 . . . 5 .

Results
As was stated in previous sections, the complete neuro-genetic controller was developed following three different phases.
The first stage is responsible for determining the neural software sensor of the dynamic process. Second, a neural networkbased model of the process dynamics was determined using samples of the complete I/O values set. Finally, this latest neural model was used to derive a genetic-based controller whose objectives include minimizing both the cost function and the number of effluent constraints violations.
The wastewater treatment plant model was developed using Hydromantis GPS-X 6.0 and the MATLAB environment was the 2019 version. The proposed neural networks were developed using the MATLAB specific neural network library. The genetic algorithms were coded in MATLAB without using any specific library. The connection between the Hydromantis wastewater plant model was made by means of the MATLAB link provided in the Hydromantis GPS-X environment.

Results with software sensor and identification model
The structure of the software sensor is a two hidden layer single perceptron with a 100-55-25-3 neuron architecture, where the hidden layer configuration was selected after a trial-and-error procedure using a pruning algorithm based on the Optimal Brain Surgeon methodology ( Christiansen et al., 2012 ).
A multi-fold cross validation approach was made starting from a subset of 4200 points obtained from several experiments carried out with the GPS-X model during a simulation span of ten days of operation.
Comparison between GPS-X measured and predicted data by the neural software estimator shows its ability to accurately estimate the COD, TSS and TN concentrations for each T p = 4 h sampling interval (Figs. 6 and 7) by exclusively using actual and delayed values of the selected set of secondary variables by the PCAbased methodology described in Section 3.1 with a sampling time T s = 15 min.
The neural identification network is responsible for learning the dynamic behaviour of the secondary variables, in a way, it can relate the level of the secondary variables with the control inputs and past states. Therefore, the outputs of the neural identification model are the estimated values of the secondary variables in the following time step while the inputs of the neural model consisted of a combination of selected measurable secondary variables at previous time steps together with the control actions.
Due to the specific dynamic characteristics of the plant process, up to 20 previous time steps of each of the sensors measurements are considered as input candidates for the identification neural network, following the same strategy that was presented in a previous section for determining the input set for the software sensor network.
The behaviour is modelled using a single neural network, with a 50-35-15-1 feedforward architecture per estimated secondary variable, each trained using a Levenberg-Marquardt algorithm with a different subset of 1500 points selected randomly from a simulation data set with a sampling T s = 15 min. The simulation set was obtained using PID algorithms controlling the O 2 level in both the anoxic (slightly aerated) and aerobic tanks and considering a wide operating range.
The neural net was also validated with a subset consisting of a simulation span of ten days of operation and comparing its outputs to the outputs of the system in independent experiments. A comparison between real and predicted data by the neural identification model is depicted in Fig. 7 , showing the ability of the neural model to accurately describe the process behaviour under varying conditions inside the operating range.
It also should be noted that the neural identification model was implemented in a way that it was re-trained if the absolute value Table 4 Control pairs of manipulated-controlled variables.
Airflow Q_ a 1 in Tank 1 Oxygen O_21in Tank 1 Airflow Q a 2 in Tank 2 Oxygen O 22 in Tank 2 Airflow Q a 3 in Tank 3 Oxygen O 23 in Tank 3 Airflow Q a 4 in Tank 4 Oxygen O 24 in Tank 4 Airflow Q a 5 in Tank 5 Oxygen O 25 in Tank 5 Airflow Q a 6 in Tank 6 Oxygen O 26 in Tank 6 Airflow Q a 7 in Tank 7 Oxygen O 27 in Tank 7 Airflow Q a 8 in Tank 8 Oxygen O 28 in Tank 8 External recycle flowrate Q r Effluent ammonia NH +

out
Waste sludge flowrate Q w Nitrate N O 3 , 2 at the output of the anoxic zone of the absolute error between the predicted output and the process output is above a given threshold.

Results with genetic controller
The GA controller is characterized by a population of 250 inhabitants, 250 generations, a mutation rate of a 2.5% and a codification depth of 8 bits. The optimum is accepted if it is invariant in 15 iterations. All these parameters were estimated for achieving a time response lower than 5 s for the computational system used for controlling the neural model of the dynamic wastewater treatment model process.
The output will be compared against a multi decoupled adaptive neural network based PID control scheme, to validate the proposed control scheme, in a such a way that the effluent quality is indirectly controlled. In the case of the present paper, the relative gain matrix methodology ( Seborg et al., 2016 ) was used to provide the pairing between the controlled and manipulated variables.
The resulting control pairing is shown in Table 4 where Q a i is the i th airflow inlet, O 2 i is the O 2 concentration at the i-th section, Q r is the recycled sludge valve actuation and Q w is the valve actuation of the waste sludge.
The structure of each of the decoupled adaptive neural network based PID control loop was designed by using a radial basis function approach, as described in Du et al. (2018) . This kind of adaptive neural-based PID structure has shown promising performance in simulating wastewater treatment processes in comparison to fine-tuned PID strategies. A radial basis neural network was used to adapt the values of the PID parameters for each controller based on delayed values of the controlled and manipulated variables for each controlled pair defined in Table 4 , using each a 9-6-1 feedforward structure.
A subset of influent data from Alex et .al (2018) is extracted over a period T r of 364 days once the plant is stabilized after an initial period of 245-day with T s = 15 min sampling time to check the performance of both control approaches.
The chemical oxygen demand COD concentration in the effluent under the influent conditions aforementioned is shown in Fig. 8 , when using the two control strategies mentioned above.
The total suspended solids TSS concentration and total nitrogen concentration TN in the effluent are depicted in Figs. 9 and 10 respectively also under the same influent conditions.
To assess the prediction results, the mean absolute percent error (MAPE), maximum absolute percent errors (MaxAPE) and correlation coefficient of prediction error (R 2 ) as defined by  were calculated, where N is the number of samples, Y pred,i is the i th output of the neural predictor, Y observ ed,i is the i th observed GPS-X output, Ȳ is the mean value and S Y is the standard deviation. The results obtained for the three effluent primary variables are listed in Table 5 for both PID and neurogenetic controllers, with similar prediction results. A summary of the performance of economic consumption and effluent quality can be seen in Table 6 for comparison purposes during the performance of both the neurogenetic control and the decoupled PID control for the previous subset of influencing conditions. Table 6 confirms that the neurogenetic control behaves better than the decoupled adaptive PID control. The global energy (sludge production, aeration energy and pumping energy) is significantly reduced and the effluent quality index is improved as well, preventing each effluent variable COD, TSS, TN and NH + 4 out from violating the constraints referred to in Table 4 , with a broader operational range than those acquired with decoupled adaptive PID feedback controllers.

Discussion
The main advantages of the application of machine learning techniques for the identification of wastewater treatment processes reside in their capability to grasp the dynamics of the system by using solely operational data. Once trained, the resulting identification model can be used for control purposes since the output can be forecasted for different input sets depending on the current and past states optimizing a cost function, as is shown in the present paper.
An additional advantage is related to wastewater treatment since some of the variables that rule the process are not usually  Continued measured in real-time due to the high cost of the sensors and/or the related high maintenance costs. In this way control schemes can only be validated by off-line laboratory measurements. Therefore, using neural networks enables the development of softwarebased sensors using available secondary measurements to infer primary outputs values and, for control purposes, predictions. One of the main difficulties in designing neural network-based software sensors resides in selecting the most significant set of secondary variables, the final network structure and the proper value of the sample time, that should be selected according to the dynamics of the process. The set of secondary variables should be capable of grasping the behaviour of the primary variables, however, introducing a very large space dimension may lead to overfitting and, in extreme cases, translate into a large computational time. In the present paper a PCA based method was used due to its ability to select the secondary variables that are maximally independent in a linear sense while minimizing correlations among the variables.
The selection of the sampling time is intrinsically linked to the dynamic characteristics of the process to be modelled/controlled. In the case of biological wastewater treatment plants, it is a well-known fact that it involves a wide range of time constants.
Changes of dissolved oxygen concentration may occur in the range of minutes while the time constant for substrate concentration could reach hours, depending on the hydraulic retention time and the reaction rate. Variation of the microbial population occurs in a range of days. However, the typical time delay of the hardware instrumentation might range from the few minutes of the dissolved oxygen to more than 10 minutes for the ammonia and nitrogen analysers, to a few hours for the solids concentration.
For these reasons, the sampling times were chosen so that the process dynamics in the activated sludge process and the realistic time response of the hardware instruments were included. In our particular case, the value of T p = 4 h, compatible with a successful prediction, was selected since this is the minimum value currently used during the off-line measurement procedure that is performed on the effluent stream in the wastewater plant considered. Larger values for sample time would render an unstable prediction.
In the case of the optimization problem a genetic algorithm approach was chosen due to its flexibility since it is based on the testing and selection of fittest individuals. Unlike traditional hill climbing approaches, they do not evaluate and improve a single solution, but a set of solutions having flexibility, efficiency and robustness as their main properties. The strength of this paral- Comparison between the COD effluent output using the neurogenetic control scheme (blue) against decoupled adaptive PID controllers (red) for a 364-day period. (For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.) Fig. 9. Comparison between the TSS effluent output using the neurogenetic control scheme (blue) against decoupled adaptive PID controllers (red) for a 364-day period. (For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.) lel process is enhanced by the mechanics of population modification, making GAs adequate candidates even for NP -hard problems (Baese et al. 2014) . In the case of the present paper, the input to the cost function is a set of possible valid control inputs and the genetic algorithm chooses the set that optimizes the cost function involving both energy consumption and constraints violations.
The obtained results show that the proposed method results in an adequate performance and it is a relatively simple approach since both the software sensor as the dynamic model development are based on I/O operational data. In contrast to this, the perfor-mance of the neural predictor relies tightly on the I/O data content, so that they must be representative of the entire operational workspace. Otherwise, the generalization capabilities exhibited by the neural networks would be reduced, causing malfunction. Additionally, the optimization algorithm does not impose hard constraints in the cost function since it relies on evaluating the cost function in the possible input set.
Nevertheless, the practical implementation of the proposed simulated approach would require an extra investment in extending the actual limited monitoring system to capture the easy to Comparison between the Total Nitrogen effluent output using the neurogenetic control scheme (blue) against decoupled adaptive PID controllers (red) for a 364-day period. (For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)

Table 6
Comparison results with different climatic conditions for quality and economic performance.

Variable
Neuro-genetic control Decoupled PID control measure variables. Additionally, the performance of the software sensor and the dynamic neural identification model should be periodically checked since measurements on such treatment plants are noisy, include sensor drift and include periods where one or more sensors might be out of operation. In contrast, a significant cost reduction would be achieved implementing the neurogenetic approach as compared to the traditional decoupled PID, representing a 12.89 % average total cost reduction ( €/day) in our particular case, according to Table 6 results. In summary, the proposed approach is based on using machine learning supervised networks for both soft-sensing and dynamics identification, and genetic algorithms to choose the pseudooptimal control action in reference to a defined cost function taking into account the present and past states of the system. The use of neural network approaches represents one of the most commonly employed modelling methods for reconstructing the desired outputs in chemical processing. In fact, according to Haimi et al. (2013) , the neural soft-sensor has become the most popular technique used for data-driven sensor development due to its better performance.

Conclusions and future works
In the present paper, an adaptive neural network was applied to estimating the effluent characteristics of a wastewater treatment process model from secondary variables, while an additional neural network was developed to estimate the dynamic behaviour of the referred secondary controllable variables.
A pseudo-optimal genetic algorithm was implemented to determine the control actions based on the legal effluent concentration constraints and the economic costs involved in the actions of the actuators. The whole neuro-genetic system composed of the software sensor module, the identification network and the genetic control module was coded using specific tools within MATLAB and GPS-X software.
The proposed control schema offers the possibility of real-time implementation since it offers a high-speed response to influent condition changes. Better results were obtained with the neurogenetic control than those obtained with decoupled adaptive PID control, both in complying with the legal constraints and achieving lower economic expenses.
It is also necessary to highlight the potential benefits of artificial neural networks combined with GA when applied to the multivariable control of nonlinear plants, as was demonstrated with a wastewater treatment process. Although the proposed schema was applied to a mathematical software model of the physical process, it could be extended to industrial processes requiring for that purpose an extra investment in more reliable and cheaper sensors.
The future work involves applying this strategy to a physical wastewater process since the research group the authors collaborate with is currently designing a neuro-genetic control system that is going to be applied to control an experimental plant within the University of Malaga facilities.