# A Bilevel Optimization Approach for Tuning a Neuro-Fuzzy Controller
## 1 Introduction
According to [9], this controller is a hybridization between controllers based on fuzzy networks [10; 11] and those that use neural networks [12]. A fuzzy logic system uses if-then rules to determine the appropriate course of action based on input data. The programmer initially proposes these rules and uses their expertise to create them; they are further refined by integrating a machine learning algorithm. The rules are based on the experience of the programmer as well as on how the system learns from the data. Therefore, this process involves tuning both the hyperparameters of the neural network and the elements associated with the inference laws of fuzzy logic. In [13], a specific case of tuning an NFC applied to a biodiesel production process was presented. Its architecture requires a series of initial values (weights) to operate, where the number of weights is exponential to the number of membership functions. Optimal tuning involved determining the appropriate membership functions and then the number of initial weights. In fact, the final behavior of the controller was quite susceptible to the initial values despite the training of its neural network. A metaheuristic technique was used to select the optimal initialization values, with the restriction of a fixed number of membership functions. Remarkably, the same task in the biodiesel production process was presented in [14], but using a proportional-integral-derivative (PID) controller tuned with analytical methods. However, its performance was widely surpassed by the system implemented with the NFC. It is worth noting that designing robust controllers capable of dealing with unexpected situations during the process implies increasing difficulty due to their tuning. For example, a PID controller only requires the tuning of three variables in a continuous space, while the NFC in this work requires determining a discrete variable that defines its architecture and the number of continuous variables, \(N\). This is calculated using (1), where \(m\) is the number of membership functions, \(m^{2}\) corresponds to the number of initial weights, and an additional term (in this specific case, 5) relates to the learning constants and additional parameters used to define the membership functions. \[N=m^{2}+m+5 \tag{1}\]The NFC used as a case study in this work has various advantages, such as the ability to adapt itself online to both fulfill the trajectory tracking task and to be robust to disturbances. Despite this, it is necessary to initialize it with a configuration good enough to avoid overreactions to disturbances. In addition to the hyperparameters that define the neural network, the NFC is also sensitive to the initial value of the weights in the network. This aspect limits the application of other proposals such as [15], where the authors tuned the epochs, the number of layers, and neurons of a neural network using DE, but omitted the tuning of the initial weights. In other developments [16; 17], different heuristic techniques (harmony search and genetic algorithm) were used for tuning NNs with additional parameters like the learning rate or a pool of activation functions, but the weights were not considered, as they were initialized randomly or followed a normal distribution. The use of an optimization approach to determine the best tuning parameters of the NFC (including the initial values of its weights) involves solving an unconventional problem in the sense that the candidate solutions have different sizes. The novelty of the proposal in this work is the reinterpretation of the tuning problem as a bilevel optimization problem, where each single problem uses fixed-size solution vectors. Because of this modeling, a variety of metaheuristic algorithms can be applied to solve it, since dealing with variable-size candidate solutions is not required.