# Artificial Intelligence-Based Controller for DC-DC Flyback Converter
## 4 Controller Design
### ANFIS-Based Controller
#### 4.2.5 Layer 5  
Layer 5 is the last layer for the output and is comprised of a single node (fixed (circle)). All the outputs from Layer 4 from each rule are added up here, and a single output, i.e., the duty cycle is generated and is calculated by Equation (36). \[\sum\overline{w_{i}}f_{i}=\frac{\sum w_{i}\cdot f_{i}}{\sum w_{i}} \tag{36}\]  
In this paper, a hybrid algorithm (HA) was used for the training purpose. The HA was the hybrid combination of the back-propagation algorithm (BPA) and least-squares error algorithm (LSA). It determined the antecedent (input) and consequent (output) parameters. First, the consequent (output) parameters were revised using the LSA and, antecedent (input) parameters were then updated using BPA. Furthermore, the gradient descent algorithm (GDA) back-propagated the errors that still existed [45]. The squared error \(\parallel AX-B\parallel^{2}\) was actually minimized by LSA, where \(A\) represents the outputs produced according to Equation (34), \(B\) represents a target output, and \(X\) is the unknown consequent value. \(X\) can be obtained using the pseudo-inverse of \(X\), expressed in Equation (37). \[X^{*}=\left(A^{\top}A\right)^{-1}A^{\top}B \tag{37}\]  
where \(A^{\top}\) represents the transposition of \(A\) and \(\left(A^{\top}A\right)^{-1}A^{\top}\) is the pseudo-inverse of \(A\) if \(\left(A^{\top}A\right)\) is non-singular. However, as ANFIS is based on data training, in certain iterations, the \(A^{\top}A\) produced a singular matrix. To overcome this problem, the recursive LSA was implemented as presented in Equation (38). \[ \begin{array}{c}S_{i+1}=S_{i}-\frac{S_{i\left(i+1\right)}A_{\left(i+1 \right)}^{T}S_{i}}{1+A_{\left(i+1\right)}^{T}S_{i\left(i+1\right)}}\\ X_{i+1}=X_{i}+S_{\left(i+1\right)}a_{\left(i+1\right)}(b_{\left(i+1\right)}^{T }-a_{\left(i+1\right)}^{T}X_{i})\end{array} \Bigg{)}\text{for }i=1,\ \ldots,P \tag{38}\]  
where \(X_{0}=0\), \(S_{0}=\gamma I\) (where \(\gamma\) represents a positive large number and \(I\) is the identity matrix), \(a_{i}^{T}\) is the \(i\)th line of matrix \(A\), and \(b_{i}^{T}\) is the \(i\)th element of matrix \(B\) and \(X^{*}=X_{P}\) (where P represents the training data points number). After the identification of consequent parameters, the network output was computed and the expression in Equation (39) was then employed to measure the error for the \(P\)th entry of the training data. \[E_{P}=\left(T_{P}-O_{P}\right)^{2} \tag{39}\]  
where \(T_{P}\) and \(O_{P}\) represent the desired and the ANFIS output, respectively. Finally, the root mean square error (RMSE) of the training data was calculated using Equation (40). \[E=\sqrt{\frac{\sum E_{P}}{P}} \tag{40}\]  
The RMSE in Equation (40) can be expressed generally as  
\[RMSE=\sqrt{\frac{\sum_{i=1}^{P}\left(E_{predict,i}-E_{actual,i}\right)^{2}}{P}} \tag{41}\]  
This RMSE is actually minimized during the training of data in ANFIS. The flowchart in Figure 8 shows the ANFIS implementation. First of all, the training data were loaded for the generation of FIS. Initial antecedent (input) parameters and MFs were set. Next, the FIS model optimization method (BPA or HA) was chosen. After this, training and testing (optional) parameters were defined. The number of training epochs was set to a specific value, e.g., 50 or 100. The training data were input to the ANFIS system. The training of the data was done N times, and when finished, the results were obtained. The testing data were loaded (optional), and testing was done. Eventually, the FIS structure and output surface could be viewed along with the modified rules and MFs adjusted by ANFIS. The data from FLC were extracted using the MATLAB environment and are presented in Appendix A. Two hundred data points were extracted from the FLC, which included all possible combinations of Neg. Big, Neg. Small, Zero, Pos. Small, and Pos. Big values of error and derivative of the error. The data from Appendix A were then loaded into the neuro-fuzzy designer, as shown in Figure 9.  
Figure 8: Flowchart of implementation of ANFIS.