Calculation model for food early warning and risk analysis
Through the improved adaptive particle swarm optimization algorithm, the hyperparameters of the long and short-term memory network are optimized, combined with the root mean square error and hierarchical analysis method, a food safety risk warning model was established, which solved the problem that hyperparameter adjustment in the existing technology affects the prediction accuracy. A more efficient food safety risk warning has been achieved.
Patent Information
- Application Number
- CN202310748408.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-25
- Publication Date
- 2024-12-31
AI Technical Summary
In the prior art, in food safety risk warning, hyperparameter adjustment of long-term and short-term memory networks relies on manual selection, affecting prediction accuracy and efficiency, and it is difficult to effectively capture potential risks in food production.
The improved adaptive particle swarm optimization algorithm is used to optimize the hyperparameters of the long and short-term memory network, combined with the root mean square error as the objective function, and the risk value is calculated using the hierarchical analysis method of summation product to establish a short-term memory based on improved adaptive particle swarm length Food safety risk warning model.
It significantly improves the optimization accuracy and convergence speed of long and short-term memory networks, reduces prediction errors, provides more accurate food safety risk warnings, and enhances the decision-making basis of governments and enterprises.
Smart Images

Figure CN119227844A_ABST
Abstract
Description
Technical Field
[0001] This technology involves a food safety analysis algorithm in the context of big data, especially a convenient and efficient prediction model developed for relevant government regulatory departments, food testing agencies and other relevant departments. Background Art
[0002] Ensuring food quality and safety is key to balanced nutrition and avoiding food contamination. However, rapid economic development has led to various sources of risk in food, posing a serious threat to human health. The impact of food risks is evident in events such as the Listeria monocytogenes epidemic in cold meats in Poland and the McDonald's salad contamination incident in the United States. It is estimated that more than 600 million people get sick each year worldwide, of which 420,000 lose their lives due to food-related problems, seriously affecting the lives and health of 33 million people. In order to better protect human health, it is essential to take proactive measures such as risk warning. Early risk warning refers to the use of predictive models to identify potential risks and hazards before food production and processing become critical, including monitoring food quality and safety indicators through raw materials used in food production, analyzing historical data, and using machine learning algorithms to predict potential problems. This method establishes a food risk warning model that can estimate the risk of food contamination based on the presence of potentially harmful substances in raw materials during food production. Early warning and effective identification of high-risk factors in food production can provide better production guidance for enterprises and provide a basis for the government to formulate relevant policies to avoid food safety problems and protect human health.
[0003] Therefore, an improved adaptive particle swarm optimization algorithm is proposed to optimize long short-term memory and create a risk warning model to ensure food safety. The algorithm optimizes the hyperparameters of long short-term memory to reduce the impact of manually selected hyperparameters on prediction accuracy. Compared with the existing particle swarm optimization algorithm, this algorithm has higher optimization accuracy and convergence speed. The sum-product analytic hierarchy process is used to obtain the risk value of the detection data as the expected output of long short-term memory. The root mean square error is used as the objective function of this algorithm to find the optimal hyperparameter combination of long short-term memory. The time series detection data composed of three types of indicators is used as the input of the algorithm model, and the food risk value is used as the output of the algorithm model. A food safety risk warning model based on the improved adaptive particle swarm long short-term memory algorithm is established. Finally, the composite seasoning data of Guizhou Province is used as a detection example, which shows that the adaptive particle swarm long short-term memory algorithm has the best comprehensive performance and the lowest overall prediction error. The high-risk factors in food can be identified by the correlation coefficient method, providing a decision-making basis for targeted food safety risk prevention and control. Summary of the invention
[0004] Long Short-Term Memory Neural Networks Long short-term memory neural network is a popular model for sequence prediction tasks because it can effectively capture long-term dependencies. Long short-term memory consists of a series of repeated modules, each of which contains four neural network layers. The storage blocks of long short-term memory are as follows: Figure 1 As shown in Figure 1. A typical LSTM unit consists of four modules: unit state, forget gate, input gate, and output gate. LSTM processes information through these modules as follows: The forget gate determines which information in the previous cell state should be discarded, as shown in Equation (1). The forget gate accepts the previous cell state and the current input and produces a forget gate activation vector: (1) The input gate determines how much new information should be added to the cell state. It consists of two parts: the input gate activation vector and the candidate cell state vector. The input gate activation vector controls which parts of the candidate cell state vector should be added to the cell state, as shown in (1), (2) and (3).
[0005] (2) (3) Where ∂ and tanh represent sigmoid functions. t ,i t and t Represent the forget gate, input gate and output gate respectively. f 、b i 、b C and b o Represents the offset vector. f , W i , W C and W o represents the weight vector. t Indicates input information. Indicates the candidate unit status.
[0006] The current cell state is updated by combining the information from the forget gate and the input gate, as shown in Equation (4): (4) Among them, C t-1 Represents the cell state at the last time step.
[0007] The output gate determines which part of the cell state should be output, as shown in equations (5) and (6). The output gate takes the current input and the previous cell state and produces the output gate activation vector.
[0008] (5) (6) LSTM can effectively process increasingly large and complex data, making it suitable for tasks that require long-term memory. At the same time, LSTM is a recurrent neural network that can effectively capture long-term dependencies in sequence data. Therefore, the past detection data is taken as input and the future risk value is taken as the output of the LSTM network to model these data pairs. In order to better demonstrate the effectiveness of the improved LSTM in processing temporal data, the prediction effects of the improved LSTM and back-propagation neural network are compared in terms of root mean square error. However, the hyperparameters of LSTM, such as time step, hidden unit, batch size, and epoch, need to be manually set before training. Appropriate hyperparameter adjustment can significantly improve the learning ability and prediction accuracy of LSTM. In this study, the hyperparameters of LSTM were optimized using an improved adaptive particle swarm optimization algorithm.
[0009] Improved Adaptive Particle Swarm Optimization The improved adaptive particle swarm optimization is an improved version of the particle swarm optimization algorithm, which dynamically updates the inertia weight according to the performance of the particles. The specific steps of the improved adaptive particle swarm optimization are as follows: Step 1: Initialization. Set the maximum number of iterations of the algorithm, as well as the velocity range and position range of the particles. Each particle is assigned a random velocity vector and a position vector within the set range. The position vector of each particle is the current individual extreme value, and the fitness value (i.e., the objective function value) of each particle is calculated to determine the global extreme value.
[0010] Step 2: Update the particle’s velocity and position according to equations (7) and (8), ensuring that the updated velocity and position are within the set range.
[0011] (7) (8) Where i represents the i-th particle, d represents the d-th variable, t represents the t-th iteration, v represents the velocity, x represents the position, and p represents the i and p g Represent the optimal positions of the particle and the group respectively. w is the inertia weight, b1 and b2 are learning factors, and k1 and k2 are random numbers uniformly distributed in the range [0,1]. The relationship between the vectors when the particle position is updated is as follows: Figure 2 shown.
[0012] Step 3: Update individual extreme values and global extreme values. Recalculate the fitness value. If the fitness value of the updated particle is better than the current one, adjust the individual extreme value to the updated particle position. Finally, adjust and update the global extreme value of the group.
[0013] Step 4: The particles of the improved adaptive particle swarm optimization are divided into three levels: poor, medium and good. The fitness value of the poor particles is less than the average fitness value of all particles, the fitness value of the good particles is greater than the average fitness value of all particles, and the fitness value of the medium particles is between these two values. The inertia weight is dynamically updated according to equation (9).
[0014] (9) in, and Respectively represent all fitness values less than or greater than f avg The average fitness value of the particles. The performance of the particles is inversely related to the updated inertia weight.
[0015] The medium particles that are slightly far from the optimal solution are updated according to their individual fitness values. If the individual fitness value is large, the inertia weight will increase; otherwise, the inertia weight will decrease. Due to the adaptive update of particles in the improved adaptive particle swarm optimization algorithm, the global search and local search capabilities of particles are balanced.
[0016] Step 5: Repeat steps 2-4 until the termination condition of the improved adaptive particle swarm optimization algorithm is met and the optimal solution is returned.
[0017] Verification of the improved adaptive particle swarm optimization algorithm Experimental tests were conducted based on five commonly used benchmark functions. The effectiveness of the proposed improved adaptive particle swarm optimization algorithm was verified by comparative studies with other well-known particle swarm optimization algorithms (such as traditional particle swarm optimization algorithm, classic particle swarm optimization algorithm, adaptive particle swarm optimization algorithm and D adaptive particle swarm optimization algorithm). Sphere and Rosenbrock functions are unimodal functions used to evaluate the optimization accuracy of these algorithms, while Ackley, Griewank and Rastrigin functions are multimodal functions used to test the global optimization capabilities of these algorithms. The dimension of each test function in this experiment is set to 30. In order to eliminate the influence of random factors on the experimental results, each algorithm is executed independently 30 times, and the average and standard deviation of the optimal function values of these algorithms are calculated to measure the overall optimization accuracy and stability of these optimization algorithms.
[0018] Table 1 Parameter settings of various optimization algorithms
[0019] The parameter settings of the five optimization algorithms are shown in Table 1. The relevant parameter settings are followed to ensure that the experimental results are fair and effective. The specific parameter settings and test function details of each algorithm are shown in Table 2.
[0020] Table 2 Test functions
[0021] Table 3 Experimental results of the optimal function values of each algorithm
[0022] Table 3 gives the average and standard deviation of the optimal function values of each algorithm, as well as the average fitness of the five test functions optimized by the five optimization algorithms with the logarithm e as the base as the number of iterations. Figure 3-Figure 7 As shown. For unimodal functions, the improved adaptive particle swarm optimization algorithm achieves an average value of 1.0E-8, which is significantly better than the traditional particle swarm optimization algorithm and the classic particle swarm optimization algorithm, and has the smallest standard deviation compared with the other four optimal algorithms. Since the optimal value of the test function is 0, the results show that the improved adaptive particle swarm optimization algorithm has the highest optimization accuracy and the strongest stability. For multimodal functions, the improved adaptive particle swarm optimization algorithm has fewer iterations and converges to the global optimum, which is better than the other four algorithms and is not easy to fall into the local optimal solution.
[0023] Based on the above analysis, the proposed improved adaptive particle swarm optimization algorithm has a good balance between global and local search capabilities. The overall optimization accuracy, stability and convergence iteration of the improved adaptive particle swarm optimization algorithm are optimal, and the overall performance is significantly improved.
[0024] After verifying the effectiveness of the improved adaptive particle swarm optimization algorithm, it was used to optimize the hyperparameters of the long short-term memory network. In this study, time step, hidden unit, batch size and epoch were selected as independent variables considering their importance in the long short-term memory network. The experimental data were divided into training group and test group, and the difference between the predicted risk value and the actual risk value of the training group was taken as the minimum target of the improved adaptive particle swarm optimization algorithm. The root mean square error (RMSE) between the predicted risk value and the actual risk value was selected as the objective function of the improved adaptive particle swarm optimization. Finally, the values of the four hyperparameters were obtained when the RMSE was minimized.
[0025] Food safety risk early warning process based on improved adaptive particle swarm optimization-long short-term memory The specific steps of the food safety risk early warning process based on improved adaptive particle swarm optimization long short-term memory are as follows: Step 1: Data preprocessing. The data used in our analysis is a time series data set consisting of several detection indicators that may cause food safety problems in compound seasonings. In order to eliminate the impact of data dimensions, the food safety detection data is dimensionlessly preprocessed.
[0026] Step 2: Data splitting and risk value calculation. The data set is divided into a training set and a test set in a ratio of 7:3. The risk value of the test data in the training set is calculated using the hierarchical analysis method based on sum-product.
[0027] Step 3: Training of the LSTM network. The input of the LSTM network is the training data set in step 2, and the network is trained to predict the risk value. The risk value calculated in step 2 is used as the expected output of the LSTM network.
[0028] Step 4: Hyperparameter optimization. The root mean square error function is shown in the equation. Formula (10) is used as the objective function of the improved adaptive particle swarm optimization algorithm. The improved adaptive particle swarm optimization algorithm is used to obtain the optimal hyperparameters that minimize the root mean square error of the long short-term memory network. The trained optimal long short-term memory network is saved and used to predict the risk value of new food safety test samples.
[0029] (10) Among them, P k represents the true risk value of the kth test sample, represents the predicted risk value of the kth test sample, and n represents the total number of test samples.
[0030] Step 5: Model validation and construction. The improved adaptive particle swarm optimization-long short-term memory model was validated, and the risk prediction model was constructed using the root mean square error, R2, and absolute error (AE), as shown in Eq. Combining Eqs. (10), (11), and (12), reliable risk analysis and early warning of food safety were achieved.
[0031] (11) (12) in, The average value representing the true risk value. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A model of a long short-term memory unit; Figure 2 Update the particle velocity and position diagram; Figure 3 The curve of Sphere's average fitness value changing with the number of iterations; Figure 4 The curve of Rosenbrock's average fitness value changing with the number of iterations; Figure 5 The curve of Ackley average fitness value changing with the number of iterations; Figure 6The curve of Griewank average fitness value changing with the number of iterations; Figure 7 The curve of Rastrigin average fitness value changing with the number of iterations; Figure 8 Weight ranking of detection indicators; Fig. 9 Running time of the six experiments; Fig.10 Root mean square error and R2 of the six groups of models; Fig.11 The risk value prediction errors of the six models; Fig.12 Absolute error distribution of test samples; Fig.13 3D graphs of risk value and risk level; Fig.14 The distribution level of risk value; Fig.15 2D graphs of risk value and risk level; Fig.16 The number and proportion of test samples at different risk levels; Fig.17 Correlation coefficient between detection index content and risk value. DETAILED DESCRIPTION
[0033]
[0034] The experimental data used in this embodiment comes from a food testing agency, and the test data of compound seasoning from January 2016 to early June 2017 are selected as experimental data. According to the national food safety standards, the test indicators that can reflect food safety issues are selected as risk assessment indicators. Compound seasoning is a condiment made of two or more condiments through special processing. Its production process is complicated and may lead to food safety risks such as excessive pathogenic bacteria. The data used for analysis is a time series data set, including 9 test indicators that may cause food safety problems of compound seasoning, including total arsenic and inorganic arsenic, Pb, benzoic acid, sorbic acid, dehydroacetic acid, saccharin sodium, sodium cyclamate, salmonella, and Staphylococcus aureus. The national food safety standards corresponding to the test indicators are shown in Table 5. According to the principle of long short-term memory neural network, the data of 9 indicators are used as the input of long short-term memory neural network. The long short-term memory neural network is constructed by optimizing the hyperparameter combination obtained by the improved adaptive particle swarm optimization algorithm. The output result is obtained as the predicted food risk value. The program code of this study was run on a MacBook Air equipped with a 1.8GHz dual-core Intel Core i5 processor and a server with CPU parameters of 12 CPUs. The software used included MATLAB 2017 and Python 3.8.
[0035] Among the 9 test indicators, the higher the test indicator value, the higher the food safety risk. In order to eliminate the influence of data dimension, dimensionless preprocessing based on equation (13) is required: (13) Among them, x ij represents the value of the jth detection index of the ith detection sample, and n represents the total number of detection samples.
[0036] The preprocessed detection data is used as the input of the sum-product-based hierarchical analysis method algorithm to calculate the weight of each detection index, and is also used as the input of the long short-term memory neural network. Figure 8 The weight ranking of the test indicators is shown. The difference in the weights of the indicators is not significant, indicating that the selected indicators are key indicators reflecting food safety risks. Finally, the risk value is obtained by the linear weighted comprehensive method. The risk value reflects the degree to which the content of each test indicator deviates from the national standard. A higher risk value means a higher food safety risk. In addition, the more the number of indicators in the test sample deviates from the national standard, the higher the risk value.
[0037] Training and application of long short-term memory neural network based on improved adaptive particle swarm optimization algorithm A total of 849 test samples collected from January 2016 to March 2017 were used to train the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model. The trained model was then applied to predict the risk value of 253 test samples collected from April 2017 to June 2017. In addition, the performance of the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model was compared and analyzed with the traditional particle swarm optimization algorithm-long short-term memory neural network, the classic particle swarm optimization algorithm-long short-term memory neural network, the adaptive particle swarm optimization algorithm-long short-term memory neural network, the deterministic and adaptive particle swarm optimization algorithm long short-term memory neural network and the improved adaptive particle swarm optimization algorithm-back propagation neural network. The hyperparameter search space of the long short-term memory neural network and the back propagation neural network is shown in Table 6.
[0038] The performance evaluation of the model was carried out using indicators such as root mean square error, R2 and absolute error. The experimental results were analyzed to determine the effectiveness of the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model in predicting the risk value of food safety testing samples.
[0039] Table 6 Hyperparameter search space for LSTM neural network and back propagation neural network
[0040] The experimental parameter settings are shown in Table 6. The hyperparameters of the long short-term memory neural network after optimization by the four algorithms are (70, 276, 5, 6), (56, 249, 3, 14), (78, 213, 3, 3), (33, 148, 3, 6), and (80, 197, 4, 10), respectively, which are the improved adaptive particle swarm optimization algorithm, the traditional particle swarm optimization algorithm, the classic particle swarm optimization algorithm, the adaptive particle swarm optimization algorithm, and the deterministic and adaptive particle swarm optimization algorithm. The hyperparameters of the back propagation neural network optimized by the improved adaptive particle swarm optimization algorithm are (18, 286, 0.5588). Fig. 9 As shown, the time consumption of the six experiments is comparable. The improved adaptive particle swarm optimization algorithm-long short-term memory neural network takes the second longest time because it divides the particles into three categories when determining the size of w. The traditional particle swarm optimization algorithm and the classic particle swarm optimization algorithm do not divide the particles. The adaptive particle swarm optimization algorithm divides the particles into two categories and calculates the distance of each particle in the deterministic and adaptive particle swarm optimization algorithms. The new risk value is predicted based on the optimized hyperparameters. In order to evaluate the performance of the model, two evaluation indicators, root mean square error and regression coefficient R2, are used. Fig.10The root mean square error and R2 of the six models are shown. The improved adaptive particle swarm optimization algorithm-long short-term memory neural network achieves the smallest root mean square error and the largest R2, indicating that the prediction error fluctuates smoothly and the overall performance is superior. Therefore, the improved adaptive particle swarm optimization algorithm-long short-term memory neural network can predict more accurate risk values and improve the reliability of risk analysis and early warning.
[0041] To evaluate the performance of the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model, we compared the absolute error (absolute error) of the prediction results of the detection samples from April to June 2017 with the other four models. The absolute error of each model is shown in Fig.11 As shown in the figure, the absolute error distribution of each test sample is as follows Fig.12 shown.
[0042] Fig.11 It shows that the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model outperforms other models in terms of prediction accuracy because it has the lowest absolute error within 5. The absolute errors of the classic particle swarm optimization algorithm-long short-term memory neural network and the adaptive particle swarm optimization algorithm-long short-term memory neural network can only be controlled within 10. The maximum absolute error of the deterministic and adaptive particle swarm optimization algorithm-long short-term memory neural network exceeds 10. The maximum absolute error of the traditional particle swarm optimization algorithm-long short-term memory neural network is close to 20. Fig.11 It can be seen that the absolute error value of the improved adaptive particle swarm optimization algorithm-back propagation neural network is controlled within 9. However, from the overall trend of the absolute error, the prediction performance of the back propagation neural network fluctuates greatly and is not as stable as the prediction results of the long short-term memory neural network, which proves the effectiveness of the long short-term memory neural network in processing temporal data. Fig.12 It can be seen that the absolute error values of the improved adaptive particle swarm optimization algorithm-back propagation neural network are mostly concentrated in [0.7, 1.6], while the absolute error values predicted by the other four long short-term memory neural network models are mostly below 0.3, which also proves the effectiveness of the long short-term memory neural network. Therefore, it can be concluded that the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model is effective for food safety early warning and risk analysis.
[0043] Based on the above analysis, it can be concluded that the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model has better prediction performance than the other five models. Although the running time of the improved adaptive particle swarm optimization algorithm-long short-term memory neural network model is 25s longer than the shortest time, it is competitive.
[0044] Evaluation and Analysis The risk level is divided into three levels using the risk values of the samples tested from January 2016 to March 2017. The results and risk value distribution are as follows: Fig.13 and 14 As shown. The test samples with risk values in the interval (0, 10] are low-risk samples, the test samples with risk values in the interval (10, 50] are medium-risk samples, and the test samples with risk values greater than are medium-risk samples. There are 50 high-risk samples, from Fig.13 and Fig.14 It can be seen that the boundary between medium risk and high risk is very clear, and there are 13 high-risk samples, accounting for 1.5% of the total number of samples.
[0045] After dividing the risk levels according to the historical test data, the risk analysis was conducted using the test samples from April 2017 to June 2017. Fig.15 As shown. Fig.15 The density of the middle line shows that most of the tested samples are low risk, and only a few are high risk. Fig.16 As shown. Fig.16 The samples with medium and low risks accounted for 78.2%, and the samples with medium risks accounted for 20.5%. There were 3 high-risk samples, accounting for 1.3%, which was not much different from the proportion of high-risk samples tested from January 2016 to March 2017. Therefore, the overall risk of samples tested from April 2017 to June 2017 was relatively low, and the relevant government departments only needed to focus on monitoring these three high-risk samples.
[0046] Calculate the correlation coefficient between the test sample data and the corresponding risk value to identify the factors causing high risk. The test indicators that are strongly correlated with the trend of risk value changes are extremely correlated indicators. In this way, the relevant government departments can formulate targeted food safety measures in a timely manner. For the test samples from April 2017 to June 2017, the correlation coefficients between the indicators of compound seasoning and the risk value are calculated by formula (14), as follows: Fig.17 As shown. According to the classification standard, the degree of correlation is divided into four levels. The correlation coefficient in the interval [0, 0.1) is irrelevant, the interval [0.1, 0.2) is weakly correlated, the interval [0.2, 0.5) is moderately correlated, and greater than 0.5 is strongly correlated. (14) Among them, Cov is the covariance of the index value related to the detection data and the predicted risk value, D(X) is the variance of the index value related to the detection data, D(Y) is the variance of the index value related to the detection data, and r is the predicted risk value.
[0047] from Fig.17It can be seen that the detection index of cyclamate is highly correlated with the risk value. Therefore, some test samples have a higher content of cyclamate, which leads to a higher risk of these samples. Then, by focusing on monitoring risk factors such as environmental pollution in the production process and improper storage methods, the risk sources of high-risk samples can be traced.
Claims
1. A computational model for food early warning and risk analysis, characterized in that The model method includes the following steps: data preprocessing, data splitting and risk value calculation, long short-term memory network training, hyperparameter optimization, and model verification and construction.
2. The method according to claim 1, characterized in that The data preprocessing step includes using a time series data set consisting of several detection indicators that may cause food safety problems in compound seasonings. In order to eliminate the influence of data dimensions, the food safety detection data is dimensionlessly preprocessed.
3. The method according to claim 1, characterized in that The data splitting and risk value calculation steps include dividing the data set into a training set and a test set in a ratio of 7:3, and using the sum-product-based hierarchical analysis method to calculate the risk value of the detection data in the training set.
4. The method according to claim 1, characterized in that The training steps of the long short-term memory network include the input of the long short-term memory network is the training data set in claim 2, the network is trained to predict the risk value, and the risk value calculated in claim 2 is used as the expected output of the long short-term memory network; the specific details are that the long short-term memory neural network is a popular model for sequence prediction tasks that can effectively capture long-term dependencies. The long short-term memory consists of a series of repeated modules, each module contains four neural network layers, and a typical long short-term memory unit consists of four modules: unit state, forget gate, input gate and output gate, wherein the forget gate determines which information in the previous unit state should be discarded, the forget gate accepts the previous unit state and the current input, and generates a forget gate activation vector, and the input gate determines how much should be added to the unit state. Long short-term memory can effectively process increasingly large and complex data, making it suitable for tasks that require long-term memory. At the same time, long short-term memory is a recursive neural network that can effectively capture sequence data. According to the long-term dependencies in the data, therefore, the past detection data is taken as input, and the future risk value is taken as the output of the long short-term memory network to model these data pairs. In order to better demonstrate the effectiveness of the improved long short-term memory in processing temporal data, the prediction effects of the improved long short-term memory and back propagation neural network are compared in terms of root mean square error. However, the hyperparameters of the long short-term memory, such as time step, hidden unit, batch size and epoch, need to be manually set before training. Appropriate hyperparameter adjustment can significantly improve the learning ability and prediction accuracy of the long short-term memory. It consists of two parts: the input gate activation vector and the candidate cell state vector. The input gate activation vector controls which parts of the candidate cell state vector should be added to the cell state. The current cell state is updated by combining information from the forget gate and the input gate. The output gate determines which part of the cell state should be output. The output gate accepts the current input and the previous cell state and produces an output gate activation vector.
5. The method according to claim 1, characterized in that The hyperparameter optimization step includes using the root mean square error function as the objective function of the improved adaptive particle swarm optimization algorithm, using the improved adaptive particle swarm optimization algorithm to obtain the optimal hyperparameters that minimize the root mean square error of the long short-term memory network, and saving the trained optimal long short-term memory network to predict the risk value of new food safety testing samples.
6. The method according to claim 1, characterized in that The model validation and construction steps included the use of a modified adaptive particle swarm optimization-long short-term memory model. After validation, the risk prediction model was constructed using root mean square error, R2, and absolute error (AE), thus achieving reliable risk analysis and early warning for food safety.
