## 2 AnFIS-PID
### Implementation
#### 2.2.2 Fuzzification Layer (Layer1), Rule Layer (Layer2), and Normalization Layer (Layer3)  
In order to obtain richer information and achieve better control performance, the triangular membership function is used to calculate the membership of each input value mapped to seven fuzzy linguistic values (NB, NM, NS, ZO, PS, PM, PB), as shown in Figure 2 and Equation (3), where \(\mu_{i}\) and \(\mu_{r}\) represent the membership of the input values corresponding to the left and right fuzzy linguistic values, respectively.  
In the fuzzy rule generation phase, each input value is mapped to seven fuzzy linguistic values using membership functions, and two input values can generate 49 (\(7\times 7=49\)) rules in a single forward propagation. However, the midpoint of the membership function used in this paper always coincides with the boundaries of the adjacent membership functions, so each input value has only two valid memberships, the rest being zero. Therefore, during controller implementation, only the activation strengths of four (\(2\times 2=4\)) valid rules are calculated to improve computational efficiency.  
Figure 2: The triangle membership degree function.  
decimals must be restored, which results in the incremental output of the controller being close to 0. As a result, the final output of the ANFIS-PID controller remains constant, which can lead to large fluctuations in the controlled temperature around the target temperature.  
To solve this problem, set the condition that the error between the target temperature and the actual temperature is within \(\pm 3\,^{\circ}\)C. A large learning rate is used when the condition is met, and a small learning rate is used when the condition is not met. Therefore, in the FPGA-in-the-loop (FIL) simulation, the learning rates \(\eta_{1}\) and \(\eta_{2}\) of \(K_{p}\) and \(K_{d}\) were set to 0.33 and 0.67, respectively, and the learning rates \(\eta_{1}\) and \(\eta_{2}\) of \(K_{i}\) were set to 0.005 and 0.01; in the ex vivo experiment, the learning rates \(\eta_{1}\) and \(\eta_{2}\) of \(K_{p}\) and \(K_{d}\) were set to 0.15 and 0.29, respectively, and the learning rates of \(\eta_{1}\) and \(\eta_{2}\) of \(K_{i}\) were set to 0.005 and 0.009, respectively.  
According to the above mapping relationship between input values and fuzzy linguistic values, two input values correspond to a total of four premise parameters. If these four premise parameters are updated separately by the objective function, a large number of multiplication and division operations will be involved, occupying a large amount of FPGA resources. For this purpose, a variable is introduced for each of the two input values to calculate the premise parameters, as shown in Equations (10) and (11), where \(g_{\{[\textit{flag}0]\}}\), \(g_{\{[\textit{flag}0+1]\}}\), \(n_{\{\textit{flag}1\}}\), and \(n_{\{\textit{flag}1+1\}}\) (\(\textit{flag}0=0\), 1, 2, 3, 4, 5, \(\textit{flag}1=0\), 1, 2, 3, 4, 5) are the premise parameters to be updated for \(E\) and \(EC\), respectively, corresponding to \(m_{\{\textit{flag}1\}}\) and \(m_{\{\textit{flag}+1\}}\) in Figure 2. _flag_0 and _flag_1 are used to locate the positions of the input values \(E\) and \(EC\), corresponding to _flag_ in Figure 2. \(S\)0 and \(S\)1 are the variables used to calculate the premise parameters. \(S\)0 and \(S\)1 are updated by Equations (12) and (13), and \(\theta\) is the learning rate.  
\[\begin{cases}g_{\{flag0\}}=S0*(40*flag0-90),\\ g_{\{[\textit{flag}0+1]\}}=S0*(40*flag0-50).\end{cases} \tag{10}\]  
\[\begin{cases}n_{\{flag1\}}=S1*5*(flag1-3),\\ n_{\{[\textit{flag}1+1]\}}=S1*5*(flag1-2).\end{cases} \tag{11}\]  
\[\begin{cases}S(t)=S(t-1)-\theta*d_{\_}S\end{cases} \tag{12}\]  
\[\begin{cases}d_{\_}S=\begin{cases}d_{\_}S0=\frac{\partial y}{\partial S0}\\ d_{\_}S1=\frac{\partial y}{\partial S1}\end{cases}\end{cases} \tag{13}\]