## 2 Materials and Methods
### A Neural Network Based Adaptive PID Algorithm
#### 2.2.2 Design of the RBF Neural Network Based Adaptive PID (RBFNNPID) Algorithm  
In the past decades, Proportional-Integral-Derivative (PID) is the main control method for DO level [36; 37]. However, owing to the WWTP's time-varying feature, strong nonlinearity, significant perturbations and large uncertainty, a fixed parameter linear controller is not able to maintain a satisfactory tracking performance under the full range of operating conditions [1; 37]. The structure of the RBF neural network-based adaptive PID (RBFNNPID) algorithm is shown in Figure 4. The RBF neural network will adaptively calculate weighting coefficient and the parameter gradient information according to the operating state of the dissolved oxygen control system, by its own great learning ability. These results will be used to update the parameters of the PID controller in real time. Hence, such a repeated execution process realizes the adaptive adjustment of PID parameters and achieves the control of DO concentration. We have adopted the incremental PID controller and the control error is:  
\[error(k)=rin(k)-y(k) \tag{18}\]  
where, _rin_ is the desired process value or setpoint of DO concentration; \(y(k)\) is the measured process value of DO. The input of the PID algorithm is three errors, which are defined as:  
\[xc(1)=error(k)-error(k-1) \tag{19}\]  
\[xc(2)=error(k) \tag{20}\]  
\[xc(3)=error(k)-2 error(k-1)+error(k-2) \tag{21}\]  
The output of the PID algorithm is:  
\[u(k)=u(k-1)+\Delta u(k) \tag{22}\]  
\[\Delta u(k)=k_{p}xc(1)+k_{i}xc(2)+k_{d}xc(3) \tag{23}\]  
where, \(k_{p}\), \(k_{i}\) and \(k_{d}\) are the three parameters of the PID controller, which represents the proportion, integration and differentiation. The performance function is defined as:  
\[E(k)=\frac{1}{2}(error(k))^{2} \tag{24}\]  
According to the gradient descent method, the adjustment rules of three parameters are given as:  
\[\Delta k_{p}=-\eta\frac{\partial E}{\partial k_{p}}=-\eta\frac{\partial E}{ \partial y}\frac{\partial y}{\partial u}\frac{\partial u}{\partial k_{p}}=- \eta error(k)\frac{\partial y}{\partial u}xc(1) \tag{25}\]  
Figure 4: Block diagram comparing two controllers: (**a**) Block diagram of a traditional PID controller in a feedback loop; (**b**) Block diagram of proposed RBF neural network-based adaptive PID (RBFNNPID) controller. PID: Proportional-Integral-Derivative. \[error(k)=rin(k)-y(k) \tag{18}\]0  
\[error(k)=rin(k)-y(k) \tag{18}\]1  
in which, \(\partial y/\partial u\) is the identification information for the Jacobian matrix of the controlled object and it can be obtained through the identification process of neural network. The Jacobian matrix reflects the sensitivity of the output of the controlled object to the change of the input of the control. The steps of the proposed RBFNNPID control strategy are as follows:  
1. Initializing the network parameters, including the number of nodes in input layers and hidden layers, learning rate, inertia coefficient, the base width vector and the weight vector. 2. Sampling to get input \(rin\) and output \(y\), calculating error in terms of Equation (18). 3. Calculating the output \(u\) of regulator according to Equation (22). 4. Calculating network output \(y_{m}\), adjusting center vector \(C\), base width vector \(B\), weight vector \(W\) and the Jacobian matrix in terms of Equations from (10) to (17) to obtain network identification information. 5. Adjusting parameters of regulator in terms of Equations (25)-(27). 6. Back to _Step 2_ and repeat the subsequent steps until the end of the simulation time. The DO control module and the main codes of the S-function module of RBFNNPID can be found in Appendix A and B. Appendix C describes the stability and convergence analysis of the proposed RBFNNPID algorithm. An example to verify the convergence of the parameters of the neural network is shown in Appendix D.