# Research on Temperature Compensation Method in Crankshaft Online Measurement System
## 3 Compensation Method for LVDT Based on IDA-BP Neural Network
### Dragonfly Algorithm
#### 3.2.3 Improved Dragonfly Algorithm  
Standard BP neural network uses gradient descent for training which indicates that the training result and accuracy are sensitive to the initial weight values and threshold. It is a feasible way to introduce DA into BP neural network. The basic idea is to use the DA to optimize the weight values, and then the optimized solution of the DA is transferred to BP neural network as its initial weight. The purpose of the IDA combination algorithm to optimize the BP neural network is to accurately find the optimal weight from the overall situation, reduce the learning sample error, and improve the performance of the BP neural network. Its specific construction process is shown in Figure 6, and the specific implementation steps are as follows:  
1. Read the sample data, generate training set and test set, and perform normalization processing.
2. Initialization. Initialize BP neural network: the number of neurons in the input layer, hidden layer, and output layer, the weight \(w\), the threshold \(\varphi\). Initialize algorithm parameters: dragonfly algorithm population size \(N\), the maximum number of iterations \(M\), spatial dimension \(l\), inertial weight \(\Delta\omega\), field radius \(r\), five behavior weights \(s\), \(a\), \(c\), \(f\), \(e\).
3. Sort weight \(w\) and threshold \(\varphi\) of BP network to form a row vector (\(w\), \(\varphi\)). Generate the initial position \(P\) according to the value range of weight and threshold, at the same time, initial step vector \(\Delta P\) is also generated randomly.
4. Calculate the fitness of individual dragonfly when the number of iterations \(t\) is less than the maximum number of iterations. Rank dragonflies from best to worst and pick the first \(n\) to form the first generation of elite groups. Determine the boundary according to Equation (19). Use elite strategy to find the first one to determine three generations of dragonfly elite groups.
5. Through the fitness value of individual, excellent dragonfly individual of previous and current generations is obtained. Find the current best individual and worst individual. Consider the best individual as food and the worst individual as an external enemy.
6. Update the five behavior weights \(s\), \(a\), \(c\), \(f\), \(e\), and weights \(\omega\). Use the Formulas (9)-(13) to readjust the values of \(S\), \(A\), \(C\), \(F\), and \(E\).
7. Determine whether there are other dragonflies within the radius of the field. If there are neighboring individuals within the neighborhood radius, use the Formulas (14) and (15) to update the individual position vector \(P\) and step vector \(\Delta P\); if there is no neighbor in the current individual radius, use the Formula (16) to update the individual position vector \(P\).
8. Determine whether the termination condition is met, and if it is satisfied, stop the operation; otherwise return to step 4 to continue the iteration.
9. The optimal individual position \(P\) of IDA is recorded, as the weight \(w\) and threshold \(\varphi\) of the BP neural network.