# A Bilevel Optimization Approach for Tuning a Neuro-Fuzzy Controller
## 5 Experiments and Results
### Discussion  
The results reported in [13] show that the NFC performs the task of the case study efficiently. Those results are presented in Table 4. However, in that work, the authors began modeling the architecture of the controller by biasing the tuning, using an initial configuration based on the experience of a designer who suggested using seven membership functions. On the other hand, the main goal of the proposed method in this paper was to tune the NFC without any bias while trying to improve the response of the controller. The results of both approaches were compared to evaluate the performance of this proposal. From the information in Tables 2-4, it can be observed that after applying the bilevel-optimization tuning algorithm, the number of membership functions was reduced to five, contrasting with the seven in the original development. This parameter (\(m=5\)) was used as a constant to determine the rest of the optimal tuning parameters, which obtained better performance than those generated with seven membership functions. The worst solution of the tuned parameters obtained with the proposed method (Run 6, Table 3) is better than the best solution reported in the original work (Run 5, Table 4). It should also be mentioned that the lower level achieved competitive results without the need for refining the noise parameters since some with varying numbers of membership functions obtained preliminary results that were better than those reported in Table 4. The difference in the standard deviation of the objective function between the lower and upper levels can be attributed to the noise vectors and the architecture of the controllers, as a result of the variation in the number of membership functions. Figure 9: Dynamics of the reactor temperature with an initial condition of 20 \({}^{\circ}\)C using the NFC tuned by the bilevel optimization approach. A direct consequence of using fewer membership functions is that it simplifies the design problem and, from a control perspective, allows for easier implementation. Despite the proposed approach yielding better results, it has a drawback: it uses more computational time because the first level of the tuning algorithm requires a considerable number of executions. However, in cases where the possible behaviors of the controller under specific conditions are unknown, using this algorithm is recommended to generate candidate parameters and subsequently refine them using processes such as metaheuristic algorithms. This approach is a safety measure to prevent potential overreactions due to poor tuning. It is advisable to establish a good initial setting, like the one calculated with this proposal, to enable the NFC to handle potential events such as overheating in the reactor, which was considered in the simulation. A common practice in the literature is to report the results of the tuning process and claim that one controller is better than another based on the final results (but without mentioning the sensitivity of the controller). In the case of the NFC, it may not be well-tuned because there are many solution vectors (\(\vec{x}\)) that produce similar behaviors. The objective function computed with those vectors using MATLAB software can produce an infinite value as output, as the difference between the control point and the controller output is very large. Figure 10 shows the dynamics of the mathematical model of the reactor temperature using one of the worst possible settings for the NFC. The graphic presents temperature magnitudes in the order of \(10^{102}\). While this is not realistic, it corresponds to the overreaction that a poorly tuned NFC has to a disturbance in the mathematical model used for the plant (which maps to infinite values). In real life, although the simulation would not be compatible with the real world because the temperature exceeds the melting point of the tank material, the system actuator would not be able to handle what was requested by the controller, and the behavior of the plant would become unpredictable due to different failures.