# Optimization of Multistage Coilgun Based on Neural Network and Intelligent Algorithm
## 3 Recurrent Neural Network  
A neural network can be regarded as a black box that can fit any function. Approximation via superposition of a sigmoidal function [18] has proved this point. As long as the corresponding network is fully trained, the desired output can be obtained through the input. However, the no free lunch theorem also points out that there is no machine learning algorithm that can fit all problems in a limited search space [19]. Ordinary neural networks can only process independent and fixed-length inputs. The previous input and the current input are completely irrelevant with respect to a neural network. However, the number of feeds of an MSSICG varies with the number of coils, so the length of the input will also change. At the same time, the output is not only affected by the current feeding time but also by the previous feeding time. A recurrent neural network (RNN) can solve the problems mentioned above [20]. The network structure of an RNN is shown in Figure 7. It can be seen from the figure that an RNN is essentially a fully connected neural network, in which the role of the embedding layer is to convert the input into a low-dimensional and dense vector, and the role of the linear layer is to convert the output dimension of the hidden layer into the required output dimension. However, the difference is that an RNN splices multiple fully connected neural networks together. The activation value of the current RNN Cell is calculated from the current input and the activation value of the previous RNN Cell, so the RNN can remember each moment's information. The structure of an RNN Cell is shown in Figure 8.  
Figure 6: Comparison of muzzle velocity. (**a**) Experimental result; (**b**) Simulation results. In addition, the activation function usually chooses tanh because the value range of the tanh function is between a negative and positive value, which is more conducive to the calculation of RNN. We can conclude that the formula modelling the behavior of an RNN is as follows:  
\[h_{t}=\tanh\left(W_{ihh}{h_{t}}_{-1}+b_{hh}+W_{ih}x_{t}+b_{ih}\right) \tag{8}\]  
where \(h_{t}\) is the output of the hidden layer at the current moment, tanh is the activation function, \(W_{ihh}\) and \(W_{ih}\) are the weights of the hidden layer, \(b_{hh}\) and \(b_{ih}\) are the biases of the hidden layer, and \(x_{t}\) is the input at the current moment. However, RNNs also suffer from the problem of gradient descent during the training process. When the input sequence is very long, the advantage of RNN that can save each piece of input information becomes a disadvantage, so we used an improved GRU on the basis of an RNN. The structure of the GRU is shown in Figure 9.  
A GRU can save the important information in the input and ignore the unimportant information. This is because a GRU introduces an update gate \(Z_{t}\) and a reset gate \(r_{t}\). The reset gate \(r_{t}\) can control whether the calculation of the candidate state \(\hat{h}_{t}\) depends on the  
Figure 8: Structure of RNN Cell. Figure 7: Network structure of RNN. Figure 9: Structure of GRU. state \(h_{t\text{ }-1}\) at the previous moment. The update gate \(Z_{t}\) controls how much information the current state \(h_{t}\) needs to keep from \(h_{t-1}\) and how much new information needs to be received from \(\hat{h}_{t}\). The formula for a GRU can be summarized as follows:  
\[\left\{ \begin{array}{l}r_{t}=\sigma(W_{r}\cdot[h_{t-1},x_{t}])\\ \overline{h}_{t}=\tanh(W\cdot[r_{t}+h_{t-1},x_{t}])\\ z_{t}=\sigma(W_{z}\cdot[h_{t-1},x_{t}])\\ h_{t}=(1-z_{t})*h_{t-1}+z_{t}*\overline{h}_{t}\end{array} \right. \tag{9}\]  
It can be gleaned from the formula that there is a linear relationship between the current state \(h_{t}\) and the previous state \(h_{t\text{ }-1}\), and there is also a non-linear relationship, which can alleviate the problem of gradient disappearance to a certain extent.