1. Introduction
Wastewater treatment plants (WWTPs) form an industry devoted to processing and reducing the pollution present in urban residual water. Their goal is to reduce the incoming water’s pollutant concentrations and, therefore, to preserve the natural resources and the environments into which treated water is discharged. Concentrations of pollutants, which consist of components derived from nitrogen and phosphorus, are reduced by means of highly complex biological and biochemical processes. In addition, the maximum allowed pollutant concentrations present in a WWTP’s effluent are regulated by certain limits established by local administrations.
The main aim of imposing limits is to assure that incoming water is being treated, and therefore, the pollutant concentrations are being reduced. By doing so, the environment into which effluent is dumped can be preserved, and its progressive destruction due to the spilling of contaminated waters into watercourses can be prevented. As a result, WWTPs are punished when violating these limits. Those punishments depend on where WWTPs are located, and each administration is responsible for adapting them to their necessities. For instance, European regulations (European Directive 91/271 [
1]) define different thresholds for the different WWTP effluent’s components. Moreover, these limits are even more restrictive if WWTPs are placed in sensitive areas. Thus, limits are established not only to determine whether a WWTP has to be punished because it is not treating the incoming water but also to ensure that the environment into which treated waters are dumped is preserved.
The International Water Association (IWA) has developed highly complex and nonlinear mathematical models able to replicate a WWTP’s behavior. The most well known and established one is the Activated Sludge Model N.1 (ASM1) [
2], which models the biochemical and biological processes performed in WWTPs related to nitrogen compound dynamics. It has also been adopted in the design of certain simulation scenarios, such as the Benchmark Simulation N.1 (BSM1) and Benchmark Simulation N.2 (BSM2). BSM1 emulates the behavior of a generic urban WWTP’s water line [
3], but it does not replicate the sludge treatment performed outside of this line. To solve this, BSM1 has been enhanced by the appearance of BSM2, which includes BSM1 as well as the sludge treatment process performed outside of the water line [
4]. Both simulation scenarios seek the elimination of carbon and nitrogen components from the incoming water. In terms of the regulations applied in these frameworks, BSM1 and BSM2 implement their own effluent limit concentrations [
5] since they are frameworks offering generality, easy comparison, and replicable results.
Artificial neural networks (ANNs) [
6] have arisen as data-driven methods able to generate mathematical models of high-complexity processes such as the ones carried out at WWTPs. For instance, ANNs were applied in [
7] to generate a mathematical model of ASM1’s behavior in BSM1 and BSM2 scenarios. Only the WWTP’s influent and effluent data are required. In addition, BSM1 and BSM2 are adopted to test certain control strategies in order to maintain the pollutant levels under their limits. For instance, in [
8], model predictive control (MPC) and fuzzy logic control strategies were tested together in a BSM2 scenario. Consequently, the effects of a control strategy should be taken into account when approaching the modeling of ANNs since they are observable in the WWTP’s data effluent.
In some works, ANNs were adopted as soft sensors to predict certain parameters by combining available measurements [
9]. Soft sensors only require available measurements in order to perform predictions of unmeasured process values and/or parameters. Consequently, they have arisen as a low-cost alternative to expensive hardware. This fact motivates its adoption in such different industries as refineries and WWTPs. In [
9,
10], ANN-based soft sensors were deployed to obtain the offline measurement of certain processes (measurements that cannot be obtained directly from the plant and require certain laboratory analyses) from online ones (real-time available measurements) in a refinery’s distillation column. The same objective was sought in [
11], where an ANN-based soft sensor was deployed in a WWTP plant to predict offline and hard-to-measure values from available ones.
On the other hand, the increasing interest in the Internet of Things (IoT) and Industry 4.0 [
12] has also motivated the adoption of ANNs for different purposes in WWTP systems. For instance, there are many works in which ANNs were considered to monitor or predict some WWTPs’ parameters. In [
13], the chemical oxygen demand (
), suspended solids (SS), and the aeration tank’s dissolved oxygen concentrations (
) were predicted and tracked by means of three different multiple layer perceptron (MLP) neural networks. Different nets’ configurations were considered, where the best one adopted 20 neurons in a unique hidden layer. It produced a mean absolute percentage error (MAPE) in the prediction of around 4.48%. Another example is the one observed in [
14], where the authors proposed an MLP structure to predict the
, total suspended solids (
), and the biochemical oxygen demand (
) considering past values of the same parameters. The correlation coefficient (
R), which consists of the square root of the determination coefficient (
), was adopted as a performance metric. Results showed an
R of around 0.93, which means that the MLP’s predictions were quite correlated to real values.
To study the application of ANNs to predict effluent concentration at WWTPs, Foscoliano et al. adopted a recursive neural network (RNN) that forecasted the WWTP’s nutrient concentrations and then fed an MPC-based control strategy to maintain the pollutant concentrations under the maximum levels [
15]. Results were obtained by means of BSM1 model simulations. Another approach was shown by Manu et al., who adopted a neural network to predict the performance of a WWTP plant in removing total Kjeldahl nitrogen (
), as proposed in [
16]. The predictions then fed a fuzzy logic strategy. Results showed that a correlation coefficient of around 0.97 was achievable. In [
17], two MLPs were adopted to predict the ammonia (
) and total nitrogen (
) concentrations in the effluent and determine whenever a violation of their limits was likely to occur. When detecting a violation, an (MPC + fuzzy logic)-based control strategy was activated automatically. In that manner, a reduction of 63.41% of
’s violation time was achieved with respect to [
18]’s control strategy. However, the MLPs’ predictions in [
17] correspond to the effluent’s maximum value observed within a day. Even though predictions were performed online (in real time), the MLP was trained using offline data: the maximum effluent’s value was considered to be MLP’s output data. In that sense, the time correlation between influent and effluent was broken because predictions do not tell when a peak of pollution will be exactly produced. Thus, the control strategy should be applied throughout the day instead of a few moments before the peak is really observed. The common point among these works is the fact that control strategies have been adopted to ensure that effluent concentrations are upheld below the limits; however, some violations still occur. For instance, Jeppsson et al. showed violations of
equal to 0.41% of the WWTP’s operational time (1 year) and equal to 1.18% in terms of
[
18]. Those percentages were translated into violations of ammonium lasting 1.5 days and violations of total nitrogen for around 4.3 days.
The literature shows that ANNs have been widely used to predict certain WWTP measurements. Some studies have adopted MLP networks, which do not preserve the measurement’s time correlation, whereas others have adopted RNNs to preserve it. However, offline measurements are considered to be an RNN’s input data. Therefore, predictions in real time cannot be obtained since offline measurements are not available without performing laboratory analyses. For that reason, we propose the design and implementation of an Effluent Concentration and Alarm Prediction System (ECAPS) that is based on an ANN-based soft sensor. This soft sensor adopts Long-Short Term Memory (LSTM) cells, a type of RNN. They predict the concentration of the effluent’s nutrients, specifically ammonium
and total nitrogen
, two of the most difficult nitrogen-derived concentrations to reduce. Predictions, which are performed in real time adopting BSM2 online available data, determine whenever an effluent limit is prone to violation. In addition, the predictions feed existing control strategies to let them actuate in advance [
17]. In this fashion, possible violations of effluent limits can be detected and minimized to better preserve the environment. Furthermore, this yields a reduction in the WWTP’s overall cost since the cost of deploying expensive hardware to measure offline effluent nutrients (
) [
11] is also reduced.
In summary, the main contributions of this work are
The design of a soft sensor based on ANNs (LSTM structures) to predict WWTP’s effluent concentrations.
The treatment of online data as the unique source of information to predict effluent limits in real time.
The application of data preprocessing techniques to improve the LSTM predictions.
The establishment of a prediction system able to attain a maximum MAPE of 22.65% and provide a minimum ammonium violation detection probability of around 89.02%.
3. Effluent Concentrations and Alarm Prediction System
Although there are several works in the literature that have implemented different control strategies to reduce WWTP effluent violations, violations still occur. Consequently, the overall cost of the WWTP not only increases from the application of control strategies but also as a result of the produced violations. In this work, we propose the Effluent Concentrations and Alarm Prediction System (ECAPS), whose goal is to track the effluent concentrations by means of an ANN-based soft sensor and generate alarms whenever a violation of the effluent limits is predicted. Among the different effluent concentrations, ECAPS focuses on the prediction of
and
, two of the most difficult pollutants to reduce [
17]. The former is a limiting nutrient and can therefore cause eutrophication, while the latter is toxic to aquatic life. ECAPS’ structure (see
Figure 7) is based on two main blocks: the ANN-based soft sensor, which includes the Data Preprocessing and Effluent Prediction, and the Alarm Generation.
3.1. Data Preprocessing Block
The Data Preprocessing block (see
Figure 8) is in charge of the data gathering and preprocessing process, which is briefly introduced in
Section 2.3. Its main purpose is to gather the measurements of the different sensors distributed throughout the WWTP. Once they are gathered, the previously mentioned sliding window is applied. It is characterized by its window length (WL) and prediction horizon (PH), which are 10 and 4 h, respectively. Thus, the sum of WL and PH corresponds to the average WWTP retention time (14 h). Measurements are also normalized in the Data Preprocessing block. As a summary, the Data Preprocessing block prepares the data to feed the Effluent Prediction block.
3.2. Effluent Prediction Block
The Effluent Prediction is the block whose goal is to generate the predictions () of the effluent nutrients’ concentrations. For the purpose of this work, those predictions correspond to the ammonium and total nitrogen concentrations, and . This block consists of the proposed ANN-based soft sensor’s prediction part, where ANNs and especially LSTM cells are used in the predictive approach. These use WWTP measurements from the last 10 h (input vector generated at the Data Preprocessing Block) as inputs and generate a prediction of what the effluent concentrations will be in 4 h.
3.2.1. Prediction Structures
Two prediction structures per control level were adopted: one to predict the ammonium concentration in the effluent (
) and one for the total nitrogen concentration in the effluent (
). Each prediction structure consists of two stacked-LSTM cells (see
Figure 6) and an output network consists of a unique neuron, with one output adopting the linear activation function. The difference between structures is in the number of hidden neurons at each LSTM’s gate and the L2 penalty. The hyperparameter optimization process is performed to find the best LSTM structure in terms of L2 penalty and number of hidden neurons [
36]. The process is based on training different configurations in which the applied hyperparameters (configuration variables external to the model and defined by the user) are varied in order to find those yielding the best performance. After performing the hyperparameter optimization process, a total of six prediction structures, two per control level, are obtained (see
Table 4).
3.2.2. Training Process
Prediction structures were trained with cross-validation, specifically the K-Fold technique [
37]. This technique is based on implementing different data divisions in the ANN’s training process (the number of training runs is that same as the number of folds, so K experiments will be performed). In each experiment, the data subset devoted to testing the ANN performance is changed among the different equally sized subsets (K subsets) (see
Figure 9) [
37]. Consequently, K different model parameters per structure are obtained. For the purpose of this work, the K value was set to 5 just to ensure that at least
of the measurements were considered in the training dataset; the remaining measurements were used for test purposes. Half of these measurements generated the validation dataset. Validation data were used to assess overfitting.
Once training is finished, the structure’s performance can be obtained by either computing the average of the different experiments or choosing the model parameters that perform the best. Other approaches retrain a new model using the same settings of the best model parameters considered in the cross-validation [
37,
38]. In our case, the best model parameters were considered and consequently adopted in the prediction process. Moreover, the K-Fold technique was adopted in the training process not only to find the best model parameters but also to overcome the unbalanced dataset problem. It implicitly determines a good data division with which to train the network.
3.3. Alarm Generator Block
The Alarm Generator contrasts predictions with the effluent limits (
, where
corresponds to the limits of either
(
) or
(
), see
Table 1). Whenever those limits are violated (a violation is likely to be committed), an alarm is generated. Thus, the operator of the WWTP can decide to actuate against this future violation or not. In addition, the Alarm Generator can be calibrated taking into account the operators decision. For instance, if predictions are fully trusted, the Alarm Generator can be calibrated without modifying the limits. On the other hand, if predictions are not trusted, the Alarm Generator limits (
and
) can be lowered, thus generating more alarms. However, an increase in false positives (predicting a violation when it does not occur) can result when the Alarm Generator limits are lowered. Calibration of the Alarm Generation is performed using receiver operating characteristic (RoC) curves, where the false positive rate is compared with the true positive rate or probability of detection (predicting a limit violation when it really occurs).
3.4. ECAPS Performance Evaluation
The performance of the proposed ECAPS was evaluated by means of five metrics: three related to the ANN-based soft sensor and two related to the alarm generation process. The ANN-based soft sensor’s performance was computed according to the mean absolute percentage error (MAPE), the root-mean-squared error (RMSE), and the determination coefficient (). The Alarm Generator’s performance was computed on the basis of the false positive rate or false alarm probability () and the real positive detection rate or probability of detection ().
The MAPE is defined as the percentage of error in the prediction. Good predictions have MAPE values close to 0. It is computed as follows:
where N corresponds to the number of examples,
corresponds to the
ith sample of the real output data, and
is the
ith predicted value. RMSE is computed as:
Desirable RMSE values are close to 0.
The
criterion is computed as:
where
corresponds to the mean of the predicted values. The mean of the real values corresponds to
.
measures the amount of the data variance that is explained by the model and ranges from 0 to 1. Thus, a result of 1 reveals a perfect correlation between values.
Finally, the Alarm Generator’s purpose is based on the generation of alarms whenever the effluent concentrations exceed the limits. Thus,
is defined as the probability of predicting existent limit violations.
is defined as the probability of predicting a nonexistent effluent limit violation. More specifically,
and
are computed as:
Predictions of nonexistent violations imply that actions are taken to reduce pollutant concentrations when they are not really required. Consequently, the overall cost of the WWTP is increased. For that reason, we aim for high and low values.
5. Conclusions
This work is based on the implementation of an Effluent Concentration and Alarm Prediction System (ECAPS) whose aim is to predict concentrations of a WWTP’s effluent and determine when they will exceed the established limits. Since it will be deployed in the BSM2 framework, the limits correspond to BSM2’s own regulations. Predictions are performed by means of an ANN-based soft sensor system. Among the different effluent concentrations, ECAPS is focused on predicting and concentrations. An Alarm Generator system compares the predictions with real imposed effluent limits to determine when future violations of the WWTP’s limits will occur. Consequently, the WWTP operator will be able to act in advance to prevent the predicted violation.
ECAPS predictions are performed by means of two LSTM-based structures, one per effluent considered. Moreover, the ANN-based soft sensor system was designed for three different levels of control, i.e., high, medium, and low control. These levels, as well as the BSM2 framework, were used in the data generation process. The training process was performed by means of the K-fold technique in order to mitigate the problem of highly unbalanced datasets.
Results show that high-accuracy predictions can be obtained for those structures predicting ammonium () concentrations. The probability of violation detection is around 86.57%, 89.02%, and 93.77% for high, medium, and low control levels. In terms of structures devoted to predicting concentration, their performance shows that good levels of violation detection are achieved when a high control level is used (around 85.96%). Moreover, the probabilities of violation detection can be improved by decreasing the ECAPS effluent thresholds at the expense of increasing the false positive rates. RoC curves were computed as a means to select these thresholds. They show an AuC of around 0.99, which translates to a nearly perfect performance. In that vein, 100% of the violations can be detected.