# LSTM-Based Model-Predictive Control with Rationality Verification for Bioreactors in Wastewater Treatment

^{1}

^{2}

^{*}

## Abstract

**:**

## 1. Introduction

^{3}[3], indicating substantial potential for energy conservation [4].

## 2. Data and Case Description

#### 2.1. Wastewater Treatment Plant (WWTP) Description

^{4}m

^{3}/d. It adopts the traditional AAO process and the effluent meets the Class A Discharge standard of pollutants for municipal wastewater treatment plants (GB, 18918-2002).

#### 2.2. Dataset and Preprocessing

_{4}

^{+}-N, TP, TN, SS, pH), and environmental temperature (T). The bioreactor tank data includes dissolved oxygen (DO), oxidation-reduction potential (ORP), ammonia nitrogen (NH

_{4}

^{+}-N), nitrate nitrogen (NO

_{3}

^{−}), and concentration of mixed liquor suspended solids (MLSS) in bioreactor tanks. The control data includes aeration volumes, internal recirculation flow rate (Q

_{r}), and sludge internal recycle flow rate (Q

_{sr}). The abnormal values of these data were examined by PauTa Criterion (Equation (1)) and deleted. Furthermore, to reduce the effect of a small amount of anomalous data and supplement missing values, this study used time-averaged interpolation (Equation (2), where the time span step N = 500) for data preprocessing.

## 3. Methodology

#### 3.1. LSTM Stimulatuon Model

_{3};

_{in}, COD, TP, TN, NH

_{4}

^{+}-N, PH, SS;

_{r}), and ${a}_{t}{}_{3}$ is the sludge internal recycle flow rate (Q

_{sr});

_{3}at the next time step.

#### 3.2. MPC Based on LSTM for Bioreaction Optimal Control

#### 3.2.1. Structure of MPC

#### 3.2.2. Optimization Algorithm

_{1}= C

_{2}= 0.6, and the maximum number of iterations max_steps = 500. Due to the requirement of the algorithm speed in the actual control, the optimization algorithm was terminated if there was no significant change in the fitness function during 200 iterations.

#### 3.2.3. Fitness Function

_{r}and Q

_{sr}ratios should be kept relatively stable to reduce the impact of flow rate changes and the large-scale control operation of the pumps. Their $opt\_bound$ in Equation (9) was a ratio determined by certain historical data.

#### 3.3. The Rationality Verification for LSTM-MPC

#### 3.3.1. The Prescribed Range of Control Variables

#### 3.3.2. Consistency with Similar Historical States

#### 3.3.3. Evaluation of the Control Effects

## 4. Results

#### 4.1. LSTM Prediction

#### 4.2. Performance of LSTM-MPC

_{r}and Q

_{sr}ratios remained stable within a certain range. The objective function ${J}_{i}$ corresponding to the control requirements also increased but only slightly and with some fluctuations, indicating that the AAO system maintained stability and met the water quality parameters threshold after optimization.

_{r}and Q

_{sr}. As aeration is the main energy-consuming process, this reduction would lead to a decrease in the overall energy consumption of the bioreactor.

#### 4.3. The Effect of Rationality Verification

_{r}was slightly reduced, Q

_{sr}was slightly increased, and the overall energy consumption was reduced. The state variables of water quality stayed stable and the DO concentrations decreased after optimal control. After the rationality verification, the optimized control met the safety requirements, but its optimization and energy-saving performance was significantly reduced compared with LSTM-MPC.

## 5. Discussion

#### 5.1. Performance of LSTM Prediction Model

#### 5.2. Effect of Fitness Function for Stability on LSTM-MPC

_{r}), and sludge internal recycle flow (Q

_{sr}).

_{r}/Q

_{in}and Q

_{sr}/Q

_{in}. And the fitness function ${J}_{i}$ corresponding to the stable control requirements fluctuated within a small range, indicating that the operational status of the bioreaction tanks did not undergo drastic fluctuations. During the optimization control process, the variations of state variables MLSS and NO

_{3}in the oxic bioreaction tank were controlled within 15%, and the ORP and DO concentrations in each tank met the threshold requirements for stable operation. The overall bioreaction was running relatively stable after the control variables were changed.

#### 5.3. Effect of Rationality Verification on LSTM-MPC

#### 5.4. Calculation Time of LSTM-MPC

## 6. Conclusions

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Acknowledgments

## Conflicts of Interest

## References

- Guo, H.; Liang, D.; Chen, F.; Sun, Z.; Liu, J. Big earth data facilitates sustainable development goals. Bull. Chin. Acad. Sci. (Chin. Version)
**2021**, 36, 874–884. [Google Scholar] [CrossRef] - Dai, W.; Xu, X.; Liu, B.; Yang, F. Toward energy-neutral wastewater treatment: A membrane combined process of anaerobic digestion and nitritation—Anammox for biogas recovery and nitrogen removal. Chem. Eng. J.
**2015**, 279, 725–734. [Google Scholar] [CrossRef] - Yan, P.; Qin, R.-C.; Guo, J.-S.; Yu, Q.; Li, Z.; Chen, Y.-P.; Shen, Y.; Fang, F. Net-zero-energy model for sustainable wastewater treatment. Environ. Sci. Technol.
**2017**, 51, 1017–1023. [Google Scholar] [CrossRef] [PubMed] - Li, W.; Li, L.; Qiu, G. Energy consumption and economic cost of typical wastewater treatment systems in Shenzhen, China. J. Clean. Prod.
**2017**, 163, S374–S378. [Google Scholar] [CrossRef] - Gurung, K.; Tang, W.Z.; Sillanpää, M. Unit energy consumption as benchmark to select energy positive retrofitting strategies for Finnish Wastewater Treatment Plants (WWTPs): A Case Study of Mikkeli WWTP. Environ. Process
**2018**, 5, 667–681. [Google Scholar] [CrossRef] - Camacho, E.F.; Bordons, C. Model Predictive Control; Springer Science & Business Media: London, UK, 2007; ISBN 978-0-85729-398-5. [Google Scholar]
- Qin, S.; Badgwell, T.A. A survey of industrial model predictive control technology. Control Eng. Pract.
**2002**, 11, 733–764. [Google Scholar] [CrossRef] - Mayne, D.Q.; Rawlings, J.B.; Rao, C.V.; Scokaert, P.O.M. Constrained model predictive control: Stability and optimality. Automatica
**2000**, 36, 789–814. [Google Scholar] [CrossRef] - Henze, M.; Gujer, W.; Mino, T.; van Loosdrecht, M.C.M. Activated Sludge Models ASM1, ASM2, ASM2d and ASM3; IWA Publishing: London, UK, 2000; ISBN 978-1-900222-24-2. [Google Scholar]
- Holenda, B.; Domokos, E.; Rédey, A.; Fazakas, J. Dissolved oxygen control of the activated sludge wastewater treatment process using model predictive control. Comput. Chem. Eng.
**2008**, 32, 1270–1278. [Google Scholar] [CrossRef] - Liu, X.; Jing, Y.; Xu, J.; Zhang, S. Ammonia control of a wastewater treatment process using model predictive control. In Proceedings of the 26th Chinese Control and Decision Conference (2014 CCDC), Changsha, China, 31 May–2 June 2014; pp. 494–498. [Google Scholar]
- Longo, S.; Hospido, A.; Lema, J.; Mauricio-Iglesias, M. A systematic methodology for the robust quantification of energy efficiency at wastewater treatment plants featuring Data Envelopment Analysis. Water Res.
**2018**, 141, 317–328. [Google Scholar] [CrossRef] - Regmi, P.; Stewart, H.; Amerlinck, Y.; Arnell, M.; García, P.J.; Johnson, B.; Maere, T.; Miletić, I.; Miller, M.; Rieger, L.; et al. The future of WRRF modelling—Outlook and challenges. Water Sci. Technol.
**2018**, 79, 3–14. [Google Scholar] [CrossRef] - Newhart, K.B.; Holloway, R.W.; Hering, A.S.; Cath, T.Y. Data-driven performance analyses of wastewater treatment plants: A review. Water Res.
**2019**, 157, 498–513. [Google Scholar] [CrossRef] - Corriou, J.-P.; Pons, M.-N. Model predictive control of wastewater treatment plants: Application to the BSM1 benchmark. In Computer Aided Chemical Engineering; Barbosa-Póvoa, A., Matos, H., Eds.; European Symposium on Computer-Aided Process Engineering-14; Elsevier: Amsterdam, The Netherlands, 2004; Volume 18, pp. 625–630. [Google Scholar]
- Mulas, M.; Tronci, S.; Corona, F.; Haimi, H.; Lindell, P.; Heinonen, M.; Vahala, R.; Baratti, R. Predictive control of an activated sludge process: An application to the Viikinmäki wastewater treatment plant. J. Process Control
**2015**, 35, 89–100. [Google Scholar] [CrossRef] - Shen, W.; Chen, X.; Corriou, J.P. Application of model predictive control to the BSM1 benchmark of wastewater treatment process. Comput. Chem. Eng.
**2008**, 32, 2849–2856. [Google Scholar] [CrossRef] - Khatri, N.; Khatri, K.K.; Sharma, A. Prediction of effluent quality in ICEAS-sequential batch reactor using feedforward artificial neural network. Water Sci. Technol.
**2019**, 80, 213–222. [Google Scholar] [CrossRef] [PubMed] - Guo, H.; Jeong, K.; Lim, J.; Jo, J.; Kim, Y.M.; Park, J.-P.; Kim, J.H.; Cho, K.H. Prediction of effluent concentration in a wastewater treatment plant using machine learning models. J. Environ. Sci.
**2015**, 32, 90–101. [Google Scholar] [CrossRef] [PubMed] - Li, D.; Yang, H.Z.; Liang, X.F. Prediction analysis of a wastewater treatment system using a Bayesian network. Environ. Model. Softw.
**2013**, 40, 140–150. [Google Scholar] [CrossRef] - Antwi, P.; Zhang, D.; Xiao, L.; Kabutey, F.T.; Quashie, F.K.; Luo, W.; Meng, J.; Li, J. Modeling the performance of Single-stage Nitrogen removal using Anammox and Partial nitritation (SNAP) process with backpropagation neural network and response surface methodology. Sci. Total. Environ.
**2019**, 690, 108–120. [Google Scholar] [CrossRef] - Shi, S.; Xu, G. Novel performance prediction model of a biofilm system treating domestic wastewater based on stacked denoising auto-encoders deep learning network. Chem. Eng. J.
**2018**, 347, 280–290. [Google Scholar] [CrossRef] - Farhi, N.; Kohen, E.; Mamane, H.; Shavitt, Y. Prediction of wastewater treatment quality using LSTM neural network. Environ. Technol. Innov.
**2021**, 23, 101632. [Google Scholar] [CrossRef] - Hansen, L.D.; Stokholm-Bjerregaard, M.; Durdevic, P. Modeling phosphorous dynamics in a wastewater treatment process using Bayesian optimized LSTM. Comput. Chem. Eng.
**2022**, 160, 107738. [Google Scholar] [CrossRef] - Pisa, I.; Santin, I.; Morell, A.; Vicario, J.L.; Vilanova, R. LSTM-based wastewater treatment plants operation strategies for effluent quality improvement. IEEE Access
**2019**, 7, 159773–159786. [Google Scholar] [CrossRef] - Yaqub, M.; Asif, H.; Kim, S.; Lee, W. Modeling of a full-scale sewage treatment plant to predict the nutrient removal efficiency using a long short-term memory (LSTM) neural network. J. Water Process Eng.
**2020**, 37, 101388. [Google Scholar] [CrossRef] - Zeng, G.; Qin, X.; He, L.; Huang, G.; Liu, H.; Lin, Y. A neural network predictive control system for paper mill wastewater treatment. Eng. Appl. Artif. Intell.
**2003**, 16, 121–129. [Google Scholar] [CrossRef] - Goldar, A.; Revollar, S.; Lamanna, R.; Vega, P. Neural-MPC for N-removal in activated-sludge plants. In Proceedings of the 2014 European Control Conference (ECC), Strasbourg, France, 24–27 June 2014; pp. 808–813. [Google Scholar]
- Chen, K.; Wang, H.; Valverde-Pérez, B.; Zhai, S.; Vezzaro, L.; Wang, A. Optimal control towards sustainable wastewater treatment plants based on multi-agent reinforcement learning. Chemosphere
**2021**, 279, 130498. [Google Scholar] [CrossRef] [PubMed] - Sengupta, S.; Nawaz, T.; Beaudry, J. Nitrogen and phosphorus recovery from wastewater. Curr. Pollut. Rep.
**2015**, 1, 155–166. [Google Scholar] [CrossRef] - Schuster, M.; Paliwal, K.K. Bidirectional recurrent neural networks. IEEE Trans. Signal Process.
**1997**, 45, 2673–2681. [Google Scholar] [CrossRef] - Hochreiter, S.; Schmidhuber, J. Long short-term memory. Neural Comput.
**1997**, 9, 1735–1780. [Google Scholar] [CrossRef] - Cho, K.; van Merriënboer, B.; Gulcehre, C.; Bahdanau, D.; Bougares, F.; Schwenk, H.; Bengio, Y. Learning phrase representations using RNN encoder-decoder for statistical machine translation. arXiv
**2014**, arXiv:1406.1078. [Google Scholar] - Belloir, C.; Stanford, C.; Soares, A. Energy benchmarking in wastewater treatment plants: The importance of site operation and layout. Environ. Technol.
**2014**, 36, 260–269. [Google Scholar] [CrossRef] - Nguyen, T.K.L.; Ngo, H.H.; Guo, W.; Chang, S.W.; Nguyen, D.D.; Nghiem, L.D.; Liu, Y.; Ni, B.; Hai, F.I. Insight into greenhouse gases emissions from the two popular treatment technologies in municipal wastewater treatment processes. Sci. Total. Environ.
**2019**, 671, 1302–1313. [Google Scholar] [CrossRef] - Kennedy, J.; Eberhart, R. Particle swarm optimization. In Proceedings of the Proceedings of ICNN’95—International Conference on Neural Networks, Perth, WA, Australia, 27 November–1 December 1995; Volume 4, pp. 1942–1948. [Google Scholar]
- Zhang, Y.; Wang, S.; Ji, G. A comprehensive survey on particle swarm optimization algorithm and its applications. Math. Probl. Eng.
**2015**, 2015, e931256. [Google Scholar] [CrossRef] - Chen, G.H.; van Loosdrecht, M.C.; Ekama, G.A.; Brdjanovic, D. (Eds.) Biological Wastewater Treatment; IWA Publishing: London, UK, 2008; ISBN 9781843391883. [Google Scholar]
- Wang, Q.; Li, H.; Dong, X.; Lu, W.; Wang, L.; Du, J.; Li, J.; Chen, L. Process optimization regulation scheme of a full-scale modified A2/O wastewater treatment plant and its improvement of simultaneous nitrogen and phosphorus removal efficiency. Chin. J. Environ. Eng.
**2022**, 16, 659–665. [Google Scholar] [CrossRef]

**Figure 6.**Prediction results of LSTM models on the test dataset with structures 1–4 and different training datasets 1–2 (Dataset 1 on the left; Dataset 2 on the right).

**Figure 9.**The results of the control variables and state variables in 24 h for LSTM-MPC-Rationality Verification.

Data Parameters | Maximum | Minimum | Average | Q1 | Q2 | Q3 |
---|---|---|---|---|---|---|

Q_{in} (m^{3}/s) | 2.759 | 2.462 | 2.623 | 2.578 | 2.622 | 2.667 |

Inflow COD (mg/L) | 390.199 | 101.889 | 233.743 | 207.158 | 227.656 | 265.799 |

Inflow NH_{4}^{+}-N (mg/L) | 30.433 | 9.516 | 17.877 | 14.397 | 17.533 | 20.668 |

Inflow TP (mg/L) | 3.365 | 1.150 | 2.241 | 1.897 | 2.285 | 2.565 |

Inflow TN (mg/L) | 32.979 | 10.799 | 23.370 | 20.817 | 23.888 | 26.766 |

Inflow SS (mg/L) | 529.006 | 17.948 | 188.958 | 93.172 | 178.071 | 275.043 |

Inflow PH | 7.113 | 6.052 | 6.524 | 6.453 | 6.535 | 6.647 |

Inflow Temperature (°C) | 30.747 | 22.063 | 25.302 | 23.223 | 25.268 | 26.485 |

Anaerobic ORP | −449.244 | −490.661 | −471.992 | −475.004 | −473.615 | −469.433 |

Anoxic ORP | 38.548 | −139.841 | −57.301 | −115.423 | −83.833 | 11.299 |

Anaerobic MLSS (g/L) | 5.046 | 1.575 | 3.631 | 3.395 | 3.672 | 4.057 |

Anoxic MLSS (g/L) | 4.822 | 2.772 | 3.672 | 3.486 | 3.616 | 3.814 |

Oxic MLSS (g/L) | 5.837 | 0.867 | 3.675 | 2.049 | 4.059 | 4.570 |

DO1 (mg/L) | 2.632 | 0.074 | 0.733 | 0.438 | 0.636 | 0.979 |

DO2 (mg/L) | 4.882 | 0.033 | 0.857 | 0.250 | 0.656 | 1.066 |

DO3 (mg/L) | 5.830 | 0.665 | 3.043 | 1.469 | 3.134 | 4.415 |

DO4 (mg/L) | 7.297 | 1.052 | 4.173 | 3.139 | 4.351 | 5.309 |

Oxic NO_{3} (mg/L) | 14.970 | 5.742 | 9.582 | 8.300 | 9.067 | 10.342 |

Aeration volume 1 (m^{3}/min) | 39.829 | 21.505 | 29.376 | 26.379 | 27.790 | 31.180 |

Aeration volume 2 (m^{3}/min) | 50.482 | 28.771 | 34.619 | 32.000 | 35.283 | 36.630 |

Aeration volume 3 (m^{3}/min) | 22.657 | 12.481 | 17.635 | 17.150 | 18.061 | 18.957 |

Aeration volume 4 (m^{3}/min) | 24.901 | 17.167 | 21.325 | 19.833 | 21.490 | 22.645 |

Q_{sr} (m^{3}/s) | 1.983 | 1.331 | 1.675 | 1.528 | 1.698 | 1.789 |

Q_{r} (m^{3}/s) | 4.930 | 4.188 | 4.494 | 4.386 | 4.451 | 4.617 |

Hidden Layer Neurons (Num_Unit) | Input Shape | Activation Function | Parameter of the Training Algorithm | |||
---|---|---|---|---|---|---|

Initial Learning Rate | Epoch | Loss | ||||

Structure 1 | 10 | [n, 10, 24] n: number of input data; 10: time steps; 24: the number of states | tanh | 0.0001 | 100 | MSE |

Structure 2 | 15 | |||||

Structure 3 | 20 | |||||

Structure 4 | 25 |

Anaerobic DO (mg/L) | Anoxic DO (mg/L) | Oxic DO (mg/L) | MLSS (g/L) | Anaerobic ORP (mv) | Anoxic ORP (mv) | |
---|---|---|---|---|---|---|

$lower\_bound$ | 0 | 0.2 | 2.0 | 2.0 | Around −150 | <−250 |

$upper\_bound$ | 0.2 | 0.5 | 3.5 | 4.5 |

Structure of Models | Training Dataset of Models | MSE on the Test Dataset | NSE on the Test Dataset |
---|---|---|---|

structure 1 | Training dataset 1 | 8.463662 | 0.945858 |

structure 2 | Training dataset 1 | 7.261208 | 0.960149 |

structure 3 | Training dataset 1 | 4.276100 | 0.986180 |

structure 4 | Training dataset 1 | 4.387872 | 0.985448 |

structure 1 | Training dataset 2 | 3.966258 | 0.988110 |

structure 2 | Training dataset 2 | 3.476448 | 0.990865 |

structure 3 | Training dataset 2 | 2.916338 | 0.993572 |

structure 4 | Training dataset 2 | 2.635806 | 0.994749 |

Average Aeration Volume in 24 h (m ^{3}/min) | Average Q_{r}(m ^{3}/s) | Average Q_{sr}(m ^{3}/s) | Aeration Optimization Ratio | |
---|---|---|---|---|

LSTM-MPC | 66.406 | 4.696 | 1.634 | 33% |

LSTM-MPC-RA (Rationality Verification) | 92.743 | 4.134 | 1.103 | 7.0% |

historical control | 99.727 | 4.130 | 1.125 |

Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |

© 2023 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Liu, Y.; Tian, W.; Xie, J.; Huang, W.; Xin, K.
LSTM-Based Model-Predictive Control with Rationality Verification for Bioreactors in Wastewater Treatment. *Water* **2023**, *15*, 1779.
https://doi.org/10.3390/w15091779

**AMA Style**

Liu Y, Tian W, Xie J, Huang W, Xin K.
LSTM-Based Model-Predictive Control with Rationality Verification for Bioreactors in Wastewater Treatment. *Water*. 2023; 15(9):1779.
https://doi.org/10.3390/w15091779

**Chicago/Turabian Style**

Liu, Yuting, Wenchong Tian, Jun Xie, Weizhong Huang, and Kunlun Xin.
2023. "LSTM-Based Model-Predictive Control with Rationality Verification for Bioreactors in Wastewater Treatment" *Water* 15, no. 9: 1779.
https://doi.org/10.3390/w15091779