## 5 Artificial Neural Network
### Neural Network  
PID controllers exhibit a notable limitation in their robustness when encountering changes in system parameters. As a result, they are unable to achieve perfect stabilization across various inputs and frequencies, necessitating the need to retune the PID parameters whenever such changes occur. Therefore, the purpose of this section is to replace the PID control system with a trained artificial neural network (ANN) and then examine the system's responsiveness to various excitations. Initially, the error signal entering the PID will serve as the input data, while the corresponding output data from the PID will be used as the target output data for training the ANN. Data collection is performed at different frequencies and with varying roll-and-pitch angles to capture the system's behavior under diverse conditions. It is important to highlight that each run necessitates careful fine tuning of the PID parameters to achieve the optimal response. For training the ANN, the Levenberg-Marquardt algorithm is employed, and the network architecture consists of two layers of feed-forward connections. Figure 16 depicts a visual representation of network architecture, showcasing a two-layer feed-forward configuration. This configuration consists of a hidden layer with 10 neurons, characterized by the sigmoid activation function. The output layer, depicted in Figure 16 as well, employs a linear activation function with one neuron making it suitable for regression tasks. This visual representation provides an overview of the structure of the neural network and the activation functions utilized in each layer. This architecture enables accurate regression for the desired control tasks. Collected data from the PID is divided into three sets: 70% for training the neural network, 15% for verification to ensure the legitimacy of the training data, and the remaining 15% for testing the finalized neural network. Figure 16: Structure of the artificial neural network. After training the ANN, it became evident that the regression model achieved a low regression value R, indicating a poor fit between the predicted and actual values. This outcome is depicted in Figure 17, where the regression line deviates significantly from the ideal fit. To further analyze the performance of the trained neural network, the data were loaded into the regression learner application. Figure 18 illustrates a comparison between the output of the PID controller and the predictions of the trained neural network in relation to error \(e_{1}\). It is observed that the neural fitting is unable to accurately follow the circular shape because of the error's fluctuation over time. Figure 17: Regression plot for the first input. Figure 18: Comparison of the PID output and the predicted output of the trained neural network with respect to error \(e_{1}\). This discrepancy indicated a lack of relevant data in the input. To address this, time data were collected and incorporated into the input as a representation of frequency. The updated dataset, including the time input, was then loaded into the regression learner application in MATLAB. Subsequently, the new data, along with the new added time input, were utilized to retrain the neural network using the regression learner application. The neural network's predicted output exhibited a much-improved fit to the error, even successfully capturing the peculiar shapes resulting from the inclusion of the time input, as shown in Figure 19. Notably, the training results showed a significantly higher R-squared value of 0.9 and a reduced mean-squared error (MSE) of 0.00099, showcasing the enhanced performance of the revised model. To integrate the trained model into Simulink, time was added as a column in the input matrix for each error of the three PID controllers. The trained block was exported from the neural fitting program to Simulink, where further training was conducted. The data for neural networks 1, 2, and 3 have predictor responses.