Surface roughness prediction method for optimizing BP neural network based on swarm intelligence search algorithm
Through the method of optimizing BP neural network based on the group intelligent search algorithm, the problem of difficulty in modeling the existing surface roughness model is solved, and more efficient and accurate surface roughness prediction is achieved.
Patent Information
- Application Number
- CN202411508269.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-03-07
AI Technical Summary
The existing mathematical model of surface roughness is difficult to model, the parameters are limited, and the working conditions are limited, making it difficult to achieve accurate and stable prediction of surface roughness in variable working conditions.
The method of optimizing the BP neural network based on the group intelligent search algorithm is adopted. By constructing the BP neural network, generating the training set and test set, determining the optimal number of hidden layer nodes, and optimizing the BP neural network hyperparameters, a prediction model of surface roughness is established.
It improves the accuracy and process efficiency of surface roughness prediction, improves the generalization of the model, and reduces the root mean square error and loss rate.
Smart Images

Figure CN119578208A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of machining error prediction, and in particular relates to a surface roughness prediction method based on swarm intelligence search algorithm to optimize BP neural network. Background Art
[0002] Surface roughness is the residual geometric shape error of the surface caused by the relative motion between the tool and the workpiece during the machining process. It is a key indicator for evaluating the quality of the machined surface. Roughness has an important impact on the product, including wear resistance, corrosion resistance and mechanical properties. There are many factors that affect the roughness of the machined surface, such as cutting parameters, tool geometry, blade runout, spindle deformation, tool vibration, workpiece elastic recovery, cutting heat, lubrication conditions, etc.
[0003] Most of the existing surface roughness prediction methods establish models through tool trajectories. The models established on this basis have the following problems: difficult modeling, limited parameters, limited working conditions, and poor generalization. It is difficult to achieve accurate and stable prediction of surface roughness under variable working conditions, and people have begun to introduce data-driven machine learning models into the field of mechanical processing. With the development of machine learning in recent years, using the powerful data processing capabilities of machine learning to analyze and process experimental data and establish a mapping relationship between cutting parameters and surface roughness has become a new idea for predicting surface roughness. Summary of the invention
[0004] The purpose of the present invention is to overcome the deficiencies of the prior art and provide a surface roughness prediction method based on swarm intelligence search algorithm to optimize BP neural network, so as to solve the problems of difficulty in modeling the existing surface roughness mathematical model, limited consideration of parameters, and working condition restrictions.
[0005] The present invention solves the technical problem by the following technical solutions:
[0006] A surface roughness prediction method based on swarm intelligence search algorithm to optimize BP neural network, the steps of the method are:
[0007] S1. Construct a BP neural network, wherein the BP neural network is a multi-layer feedforward neural network trained according to an error back propagation algorithm, and is composed of an input layer, a hidden layer, and an output layer;
[0008] S2, generate data training set and test set, the training set is used for BP training neural network, and the test set is used for BP testing neural network prediction effect;
[0009] S3, training the BP neural network, determining the optimal number of hidden layer nodes, and obtaining the BP neural network topology with the minimum loss function;
[0010] S4. Based on the determination of the optimal number of hidden layer nodes, the sparrow optimization algorithm is used to optimize the hyperparameters of the BP neural network;
[0011] S5. Train the BP neural network with optimal parameters and call the BP neural network to predict and compare the test set.
[0012] Moreover, the BP neural network structure of S1 is: input layer - hidden layer - output layer; the connection state of the nodes between layers is reflected by weights, and the initial value is generally set according to the empirical formula, and the training parameters are set: the number of training times is N, the learning rate is I, and the minimum root mean square error of the training target is RMSE min , training algorithm, activation function;
[0013] The input layer input parameters include: feed speed, spindle speed and cutting depth and parameters related to surface forming mechanism, the initial value of the hidden layer is determined according to an empirical formula, and the output layer is surface roughness.
[0014] Moreover, the training set and test set of S2 are composed of multiple groups of measured processing data, the processing data are derived from mechanical processing data, and the data volume is at least 30 groups, divided according to a certain ratio, and the data set and test set are normalized.
[0015] Moreover, the optimal number of hidden layer nodes of S3 is determined by trial and error. By trying different numbers of hidden layer nodes, the evaluation indicators of the trained network are calculated, including root mean square error, accuracy and loss value, so as to select the optimal number of hidden layer nodes.
[0016] Moreover, the S4 is specifically:
[0017] S41, initialize population position, fitness, number of iterations N, warning value ST, proportion of discoverers PD, number of individuals sensing danger SD, etc.;
[0018] S42, start loop;
[0019] S43, sorting the population to obtain the current optimal individual position and the best fitness value;
[0020] S44, update the discoverer's position, update the joiner's position;
[0021] S45, anti-predation behavior, updating population position;
[0022] S46, update the historical optimal fitness;
[0023] S47. Repeat steps S43 to S47 until the maximum number of iterations is reached, end the loop, and output the optimal individual position and fitness value. The optimal individual position represents the weight and threshold of the neural network hyperparameters, and the fitness value function is the loss function value.
[0024] The positive effects that the present invention can produce are:
[0025] 1. The present invention improves the overall efficiency of the prediction process: Compared with the traditional theoretical modeling method, the machine learning method avoids the complex cutting process and establishes the mapping relationship between surface roughness and cutting parameters based on the data.
[0026] 2. The present invention adopts the trial and error method to determine the optimal number of hidden layer nodes of the neural network, builds a neural network model with the optimal topological structure, and improves the accuracy of the prediction method.
[0027] 3. The present invention constructs an optimization module: the swarm intelligence search algorithm is used to optimize the hyperparameters of the BP neural network. Compared with the unoptimized BP neural network, the prediction accuracy is improved, the model generalization is better, and the evaluation indicators: the root mean square error and the loss rate are improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 It is a schematic diagram of the process of the present invention;
[0029] Figure 2 is a neural network structure distribution diagram of the present invention;
[0030] Figure 3 It is a comparison chart of the actual value and the predicted value of the present invention. DETAILED DESCRIPTION
[0031] The present invention is further described in detail below through specific examples. The following examples are only illustrative and not restrictive, and the protection scope of the present invention cannot be limited thereto.
[0032] like Figure 1 As shown, the present invention provides a surface roughness prediction method based on swarm intelligence search algorithm to optimize BP neural network, comprising:
[0033] There are two steps: building a BP neural network and optimizing the hyperparameters of the BP neural network. Specifically, building a BP neural network is to determine the optimal number of hidden layer nodes through trial and error, calculate the loss function Loss(i) after each training, compare and retain the minimum value, and record the corresponding number of hidden layer nodes. Build the best hidden layer neural network structure with the smallest loss function value. The step of optimizing the hyperparameters of the neural network is to use the sparrow search algorithm to solve the optimal fitness function. Set the loss function as the fitness function, the individual positions of the population as the weights and thresholds of the neural network, update the population position through foraging and anti-predation behavior, calculate the fitness functions corresponding to different population positions, and solve the optimal weights and thresholds.
[0034] Specifically, the surface roughness prediction method based on neural network provided in this embodiment includes the following steps:
[0035] (1) According to the actual machining process, the cutting parameters and the corresponding surface roughness data are recorded as the sample data set Data:
[0036]
[0037] Among them: f represents feed rate, n represents spindle speed, ap represents cutting depth, and Ra represents surface roughness value. The first three columns of the data set are used as input of the neural network, and the last column is used as output.
[0038] (2) The dataset is normalized and divided into training set and test set with a ratio of 4:1.
[0039] (3) Set the initial number of hidden layer nodes according to the empirical formula:
[0040]
[0041] Where: hiddennum is the number of hidden layer nodes, m and n are the number of output layer and output layer nodes respectively, a is a regulation constant between 1 and 10, and the constructed neural network structure is shown in Figure 2 .
[0042] (4) Initialize the weights and bias items in the network. The parameters from the input layer to the hidden layer are ω (0) , The parameter from hidden layer to input layer is v (0) ,
[0043] (5) Activate and propagate forward to obtain the output and loss function of each layer, where the loss function Loss(i) is:
[0044]
[0045] Where y represents the true value, Represents the predicted value.
[0046] (6) According to the loss function, calculate the error term of the output unit and the error term of the hidden unit. The error term of the output unit, that is, calculate the gradient value or partial derivative of the loss function with respect to the output unit, according to the chain rule:
[0047]
[0048] The error term of the hidden unit, that is, the gradient value or partial derivative of the loss function with respect to the hidden unit, is calculated according to the chain rule:
[0049]
[0050] (7) Update the weights and bias items in the neural network, and update the output unit parameters:
[0051]
[0052] Where: η represents the learning rate, k=1,2,...,n represents the number of iterations.
[0053] (8) Repeat the above steps (5) to (8) until the iterative loop ends and output the parameters.
[0054] (9) Increase the number of hidden layer nodes, repeat the above steps (4) to (8), output the optimal number of hidden layer nodes and optimal parameters, and establish the topological structure of the BP network.
[0055] (10) The sparrow algorithm optimizes the neural network weights and thresholds, initializes the sparrow population position, fitness function Fitness, optimization element number dim, population size n, maximum number of iterations N, number of discoverers PD, warning value ST, discoverer ratio PD, number of sparrows sensing danger SD, etc., where the fitness function is:
[0056] Fitness = min(MSE TrianningSet,TestingSet )
[0057] In the formula: TrainingSet and TestingSet represent the test set and training set samples respectively. The fitness function shows that the network we finally obtained can get good results on both the training set and the test set. The smaller the fitness function value, the higher the prediction accuracy of the model.
[0058] The number of optimized elements dim is:
[0059] dim=inputnum*hiddennum+hiddennum*outputnum+hiddennum+outputnum
[0060] Where: inputnum represents the number of input layer nodes, outputnum represents the number of output layer nodes. The first two items represent the number of weights in the neural network, and the last two items represent the number of thresholds in the neural network.
[0061] (11) Start the loop and obtain the current optimal individual sparrow position and the optimal fitness value.
[0062] (12) Update the location. Update the discoverer's location according to the following formula:
[0063]
[0064] Where Q is a random number that obeys a normal distribution, L is a unit row vector, and a is a random number between [0 and 1].
[0065] Update the joiner's position according to the following formula:
[0066]
[0067] Where X' worst is the sparrow position with the lowest fitness, A + is a row vector containing only two random elements, 1 and -1.
[0068] Update sparrow population location:
[0069]
[0070] Where: β is a random number that follows a normal distribution and controls the step size of the updated position. K is a random number between [-1,1], and F i is the individual fitness value, and ε is a constant close to 0 to avoid the denominator being 0.
[0071] Calculate the fitness value corresponding to the new population position and update the historical optimal fitness.
[0072] (13) Calculate the fitness value of the optimal individual for the new population position and update the historical optimal fitness.
[0073] (14) The loop ends when the maximum number of iterations is reached, and the optimal individual position and fitness value are output.
[0074] (15) Build the optimal parameter BP neural network, train and make predictions. The prediction results are as follows Figure 3 As shown, the prediction accuracy of the training set reached 93%, and the prediction accuracy of the test set reached 90%.
[0075] Although the embodiments and drawings of the present invention are disclosed for illustrative purposes, those skilled in the art will appreciate that various substitutions, changes and modifications are possible without departing from the spirit and scope of the present invention and the appended claims. Therefore, the scope of the present invention is not limited to the contents disclosed in the embodiments and drawings.
Claims
1. A surface roughness prediction method based on swarm intelligence search algorithm to optimize BP neural network, characterized by: The steps of the method are: S1. Construct a BP neural network, wherein the BP neural network is a multi-layer feedforward neural network trained according to an error back propagation algorithm, and is composed of an input layer, a hidden layer, and an output layer; S2, generate data training set and test set, the training set is used for BP training neural network, and the test set is used for BP testing neural network prediction effect; S3, training the BP neural network, determining the optimal number of hidden layer nodes, and obtaining the BP neural network topology with the minimum loss function; S4. Based on the determination of the optimal number of hidden layer nodes, the sparrow optimization algorithm is used to optimize the hyperparameters of the BP neural network; S5. Train the BP neural network with optimal parameters and call the BP neural network to predict and compare the test set.
2. The surface roughness prediction method based on swarm intelligence search algorithm optimization BP neural network according to claim 1 is characterized by: The BP neural network structure of S1 is: input layer - hidden layer - output layer; the connection state of nodes between layers is reflected by weights, and the initial value is generally set according to the empirical formula, and the training parameters are set: the number of training times is N, the learning rate is I, and the minimum root mean square error of the training target is RMSE min , training algorithm, activation function; The input layer input parameters include: feed speed, spindle speed and cutting depth and parameters related to surface forming mechanism, the initial value of the hidden layer is determined according to an empirical formula, and the output layer is surface roughness.
3. The surface roughness prediction method based on swarm intelligence search algorithm optimization BP neural network according to claim 1 is characterized by: The training set and test set of S2 are composed of multiple groups of measured processing data, which are derived from mechanical processing data, and the data volume is at least 30 groups. The data set and test set are divided according to a certain ratio, and normalized.
4. The surface roughness prediction method based on swarm intelligence search algorithm optimization BP neural network according to claim 1 is characterized by: The optimal number of hidden layer nodes of S3 is determined by trial and error. By trying different numbers of hidden layer nodes, the evaluation indicators of the trained network are calculated, including root mean square error, accuracy and loss value, so as to select the optimal number of hidden layer nodes.
5. The surface roughness prediction method based on swarm intelligence search algorithm optimization BP neural network according to claim 1 is characterized by: The S4 is specifically: S41, initialize population position, fitness, number of iterations N, warning value ST, proportion of discoverers PD, number of individuals sensing danger SD, etc.; S42, start loop; S43, sorting the population to obtain the current optimal individual position and the best fitness value; S44, update the discoverer's position, update the joiner's position; S45, anti-predation behavior, updating population position; S46, update the historical optimal fitness; S47. Repeat steps S43 to S47 until the maximum number of iterations is reached, end the loop, and output the optimal individual position and fitness value. The optimal individual position represents the weight and threshold of the neural network hyperparameters, and the fitness value function is the loss function value.
Citation Information
Patent Citations
Surface roughness predicting method for machining
CN108920812A
Collision energy absorption prediction method of vehicle body front end structural component, medium and terminal
CN112685834A
Method for predicting surface roughness of curved surface of abrasive belt grinding screw
CN113065207A
Method for establishing screw rotor surface roughness prediction model based on improved BP (Back Propagation) algorithm
CN116245140A