Food sampling inspection decision-making method based on graph attention network and Crack-Topsis
Through the Diagram Attention Network and the Critic-Topsis method, the problems of waste of resources and insufficient timeliness in food safety sampling were solved, and a scientific and reasonable sampling strategy was realized, which improved the efficiency and effectiveness of food safety supervision.
Patent Information
- Application Number
- CN202510413713.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-03
- Publication Date
- 2025-07-29
AI Technical Summary
The existing food safety sampling methods lack a dynamic adjustment mechanism, resulting in waste of resources and insufficient timeliness of sampling inspections, making it difficult to deal with the differentiated risks in different regions and seasons.
The graph attention network (GAT) model and Critic-Topsis method are used to predict the number of random inspections through data preprocessing and training models, and priority detection of high-risk substances based on the risk score of hazardous substances is formulated.
The rational allocation of random inspection resources has been achieved, the timeliness and targeted nature of random inspections has been improved, resource waste has been reduced, and the scientificity and effectiveness of random inspections have been improved.
Smart Images

Figure CN120387574A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of food safety, and specifically relates to a food sampling and inspection decision-making method based on a graph attention network and Critic-Topsis. Background Technique
[0002] As a major country in food production and consumption, food safety in China has always been a major issue related to the national economy and people's livelihood, a basic guarantee for people to live and work in peace and contentment, and an important condition for the long-term stable development of the country and society. In China's food safety monitoring system, food quality and safety play an important role. With the rapid development of China's economy and the strengthening of the country's supervision of food safety, people's requirements for food safety are getting higher and higher, and they are more concerned about potential hazards in food. Against the background of the current serious dependence of agriculture on pesticides, problems such as pesticide pollution, mycotoxin pollution, and heavy metal pollution occur from time to time. Safety incidents that endanger public health, such as "cadmium rice" and "gutter oil", are also frequently reported in the media. These incidents not only pose a huge threat to public health but also seriously affect social stability.
[0003] Nowadays, with the development of social economy and the improvement of people's living standards, food quality and safety issues have attracted increasing attention. People's demand for a healthy and nutritious diet is constantly increasing, and their requirements for food safety are becoming more and more stringent. As a key link in ensuring food safety, food sampling and inspection can effectively prevent and control food safety hazards such as pesticide residues, heavy metal pollution, and mycotoxins, and ensure that the food circulating in the market meets national safety standards. Through scientific and systematic sampling and inspection, unqualified products can be discovered and processed in a timely manner, preventing them from entering the consumer market and guaranteeing the health and safety of the public from the source. In addition, food sampling and inspection can also provide data support for regulatory authorities, helping them formulate and adjust relevant policies and regulatory measures, and further improving the scientificity and effectiveness of food safety management. Moreover, food safety sampling and inspection can prompt enterprises to enhance their food safety awareness and management level, discover and rectify problems in production management in a timely manner, and avoid market risks and reputation losses caused by quality problems. Through strict sampling and inspection standards and requirements, enterprises are promoted to continuously improve production processes and technologies, enhance product quality, and promote the healthy development of the food industry. Therefore, food sampling and inspection is not only an important means to maintain food safety but also an important measure to guarantee public health and promote the harmonious and stable development of society. This also shows that it is particularly important to formulate a reasonable sampling and inspection strategy.
[0004] Currently, in the decision-making of food safety sampling inspections, the food safety supervision department usually conducts food safety sampling inspections in the form of task assignment, which is usually carried out according to the characteristics of different provinces and regions, in accordance with the standard of n batches per thousand people per year. However, there are some problems with this method: the risk assessment results and hazard assessment degrees of food hazards vary in different seasons and regions, and the risk levels of different hazards also differ. Sampling inspections are uniformly carried out according to the standard of n batches per thousand people, which may lead to insufficient sampling efforts in areas with prominent food safety problems, while wasting sampling resources in areas with fewer problems. This unbalanced sampling coverage cannot effectively cope with the differentiated risks between regions. In addition, there is a lack of a dynamic adjustment mechanism. Currently, the sampling inspection task assignment is usually based on static indicators and lacks a dynamic adjustment mechanism, making it difficult to respond to changes in food safety problems. For the food safety risks caused by seasonal changes or emergencies in some regions, the current sampling inspection tasks are difficult to adjust and respond in a timely manner, resulting in insufficient timeliness and pertinence of sampling inspections. It can be seen that the current task allocation method is relatively subjective, making it difficult to ensure the quality of sampling inspection work, the reliability and effectiveness of results, and cannot reasonably allocate sampling resources, resulting in resource waste. Therefore, formulating a more reasonable sampling inspection decision-making plan is very important for reasonably allocating sampling resources and achieving refined sampling inspections. Summary of the Invention
[0005] To solve the limitations of the prior art, the present invention proposes a food sampling inspection decision-making method based on a graph attention network and Critic-Topsis. By constructing and training a well-trained graph attention network (GAT) model, the allocation of food sampling inspection times is realized. At the same time, the Critic-Topsis method is used to make decisions on the sampling inspection order of hazards, providing scientific guidance for sampling inspection plans.
[0006] A food sampling inspection decision-making method based on a graph attention network and Critic-Topsis of the present invention includes the following steps:
[0007] Step 1: Collect food sampling inspection data, including food types, sampling inspection times, sampling inspection locations, inspection items and results, and perform preprocessing, including data cleaning, normalization and sorting;
[0008] Step 2: Input the preprocessed data into a graph attention network (GAT) model for training. By extracting node features and calculating the correlation weights between nodes, predict the sampling inspection times of each node;
[0009] Step 3: Use the Critic-Topsis method to make decisions on the sampling inspection order of different hazards, calculate the risk scores of each hazard, and give priority to detecting high-risk hazards to improve the efficiency and effect of sampling inspections.
[0010] The said Step 1 includes:
[0011] Step 1 includes the following:
[0012] Step 101: Data collection.
[0013] Collect food sampling inspection data, including food types, sampling times (specific to quarters, such as the first quarter, the second quarter, etc.), sampling locations (including provinces, cities and regions), and inspection items and results (such as content data of lead, cadmium, chromium, etc.).
[0014] Step 102: Data preprocessing.
[0015] Remove invalid data, standardize the data format, and ensure that the data is not repeated. In addition, since the dimensions of the original data are different, in order to reduce the influence brought by the dimension difference, data normalization needs to be carried out according to the following formula:
[0016]
[0017] where x ij is the value of the i-th sample on the j-th inspection item, and min(x i ) and min(x j ) are the maximum and minimum values of the j-th inspection item respectively.
[0018] Step 2 includes the following:
[0019] Step 201: Construct a GAT model, including the construction of an input layer and a graph attention layer (calculating the association weights between nodes through an attention mechanism and dynamically aggregating neighbor node information), etc.
[0020] Step 202: Input the preprocessed food data for model training.
[0021] Step 203: Use the trained model to predict the number of sampling inspections.
[0022] Step 3 includes the following:
[0023] Step 301: Construct a standardized matrix based on the normalized data.
[0024] Step 302: Use the Critic weight method to find weights, calculate the volatility and correlation matrices, and then calculate the conflict and information content, and finally obtain the weights of each index.
[0025] Step 303: Determine the optimal and worst solutions, and calculate the ideal value and anti-ideal value of each index through the standardized matrix.
[0026] Step 303: Calculate the closeness of each pollutant index to the optimal and worst solutions to measure the risk degree of each pollutant index.
[0027] Step 305: Sort each pollutant according to the proximity. The closer to 1, the better the evaluation object. High-risk hazards are preferentially detected.
[0028] The advantages of the present invention are Brief Description of the Drawings
[0029] Figure 1 is the flowchart of the food sampling inspection decision-making method based on the graph attention network and Critic-Topsis
[0030] Figure 2 The GAT network structure in this article is as shown in the figure. Detailed Embodiment
[0031] The present invention will be described in detail below with reference to the drawings and embodiments.
[0032] As Figure 1 shown, a food sampling inspection decision-making method based on the graph attention network and Critic-Topsis of the present invention includes the following 3 steps.
[0033] Step 1: Collect food sampling inspection data, including food types, sampling times, sampling locations, inspection items and results, and perform preprocessing, including data cleaning, normalization and sorting.
[0034] Step 101: Data collection. The food sampling inspection data in this article is the sampling inspection data of Chinese grain processed products from 2017 to 2019, with a total of more than 710,000 pieces of data, including seven food sub-categories: rice, grain processed products, rice noodles, other cereal flour products, other cereal milling products, general wheat flour, special wheat flour, corn flour, corn flakes, and corn grits. The sampling inspection data includes information such as the time, region, inspection items, and inspection results of the samples.
[0035] Step 102: Perform the following preprocessing on the original data. 1) Since the ratio of the detected data to the total data is greater than 60%, all "not detected" and " / " are replaced with LOD (Limit of detection); 2) Remove symbols such as < and ≤; 3) Remove text; 4) Undetected and qualitatively detected data are invalid data, and this data is deleted; 5) Convert the time data specific to the date into the quarterly form; 6) Due to different inspection items, there will be multiple inspection data for the same sample. Perform data sorting and merge the multiple inspection data of the same sample into the same piece of data.
[0036] And normalize the sorted data according to the following formula:
[0037]
[0038] where, x ijis the value of the i-th sample on the j-th test item, min(x i ) and min(x j ) are the maximum and minimum values of the j-th test item respectively.
[0039] Part of the preprocessed data is shown in Table 1.
[0040] Table 1 Part of the preprocessed rice data (taking rice in food data as an example)
[0041]
[0042] Step 2: Input the preprocessed data into the Graph Attention Network (GAT) model for training, and predict the sampling times of each node by extracting node features and calculating the association weights between nodes.
[0043] Step 201: Construct the GAT model, as Figure 2 shown is the GAT model structure diagram of this article:
[0044] (1) Input layer: Feature vectors of food types, sampling times, sampling locations, test items, etc.
[0045] (2) Graph attention layer: Calculate the association weights between nodes through the attention mechanism, and dynamically aggregate neighbor node information.
[0046] Calculate the attention coefficient:
[0047] Feature transformation, first transform the feature vector of each node to a new feature space through a shared linear transformation matrix W:
[0048] h′ i = Wh i
[0049] Then, input the transformed feature vector into an attention mechanism to calculate the attention coefficient between node i and node j:
[0050] C ij = f(Wh i , Wh j ) = σ1(a Τ ·[(h i ′)||(h j ′)])
[0051] Among them, σ1 is the LeakyReLU activation function, a and W are the parameter matrices to be trained by the attention mechanism f, and || represents the concatenation operation.
[0052] Normalize the attention coefficient:
[0053]
[0054] Among them, N i is the set of neighbor nodes of the target node i.
[0055] Aggregate neighbor information: Further, use the normalized attention coefficients to aggregate the attribute feature information of neighbor nodes to reflect the local structural features of the target node and generate the embedded vector representation of the target node:
[0056]
[0057] In addition, introduce the multi-head attention mechanism to improve the expression ability and robustness of the model, and adopt different processing methods at different stages of the model. For the intermediate layer, use the concatenation method to combine multiple groups of target node embeddings generated by the multi-head attention mechanism to obtain the embedded representation of the target node at the intermediate layer:
[0058]
[0059] where R is the number of heads of the multi-head attention mechanism, and r = 1, 2,..., R.
[0060] To capture deeper features and relationships, multiple graph attention layers can be stacked, and each layer will update and enhance the representation of the nodes. As Figure 2 shown, three graph attention layers are demonstrated.
[0061] (3) Readout layer: After the multi-layer graph attention layers, aggregate the feature representations of each node into the whole graph feature. This step usually averages or sums the node features to obtain the feature representation of the whole graph.
[0062] (4) Fully connected layer: Input the whole graph feature output by the readout layer into the fully connected layer, and perform feature processing through several layers of fully connected neural networks. The fully connected layer can be used to capture the global feature relationships and further extract high-level features.
[0063] (5) Output layer: Use the mean method to combine multiple groups of target node embeddings generated by the multi-head attention mechanism to obtain the final output embedded representation of the target node i:
[0064]
[0065] Use the Adam optimizer to update the parameters:
[0066]
[0067] where, θ t are the parameters of the model, η is the learning rate, m t is the first-order moment estimate after bias correction, and v tis the second - moment estimate after deviation correction, and ε is a small constant used to prevent division - by - zero errors.
[0068] Step 202: Input the pre - processed food data for model training.
[0069] The parameter settings for constructing the GAT model in this application example are as follows:
[0070] Table 2 Parameter Settings for Constructing the GAT Model
[0071]
[0072] Step 203: Use the trained model to predict the number of spot checks.
[0073] Based on the national spot - check data, the decision results of the number of spot checks in each region of the country for the next year are as shown in the following table:
[0074] Table 3 Partial Results of GAT Spot - Check Decision Number Allocation (Taking Rice in Grain Data as an Example)
[0075]
[0076]
[0077] Step 3: Use the Critic - Topsis method to make decisions on the spot - check order of different hazardous substances, calculate the risk scores of each hazardous substance, and preferentially detect high - risk hazardous substances to improve the efficiency and effectiveness of spot checks.
[0078] Step 301: According to the formula for data normalization,
[0079]
[0080] Obtain the standardized matrix Z:
[0081]
[0082] Step 302: Use the Critic weight method to calculate the weights:
[0083] Calculate the volatility:
[0084]
[0085] Among them, is the average value of the j - th column in the standardized matrix.
[0086] Correlation matrix:
[0087]
[0088] Calculate the conflict:
[0089]
[0090] where: r ij represents the correlation coefficient between the i-th index and the j-th index.
[0091] Calculate the information quantity:
[0092] C j = S j × A j
[0093] Calculate the weight:
[0094]
[0095] Step 303: Determine the optimal solution and the worst solution:
[0096] Optimal solution Z + :
[0097]
[0098] Optimal solution Z - :
[0099]
[0100] Step 304: Calculate the closeness of each pollutant index to the optimal solution and the worst solution:
[0101]
[0102] where, w j is the objective weight of the j-th pollutant index obtained by the Critic method, that is, the degree of importance.
[0103] Step 305:
[0104]
[0105] where, C i The closer it is to 1, the better the evaluation object.
[0106] Rank the sampling order of hazardous substances using the Critic-Topsis method based on the national sampling inspection data. The Critic method calculates weights by comparing the intensity and conflict indicators: the comparison intensity reflects the volatility of the data, and the greater the volatility, the higher the weight; the conflict is represented by the correlation coefficient, and the larger the correlation coefficient value, the smaller the conflict and the lower the weight. The Critic method comprehensively considers the volatility of the data and the correlation between the data to finally determine the weights. The Topsis method is a multi-objective decision-making analysis method that ranks by evaluating the degree of proximity of a finite number of hazardous substances to the ideal target, thereby evaluating the relative advantages and disadvantages of these objects, and ranking the hazardous substances according to the degree of harm to achieve targeted sampling guidance. Taking rice as an example, the weights calculated by the Critic method and the closeness results calculated by the Topsis method are shown in the following table.
[0107] Table 5 Hazardous Substance Weights and Closeness Results (Taking Rice in Grain Data as an Example)
[0108]
[0109] Analyze the closeness and ranking results of various hazardous substances in the table. The closeness of inorganic arsenic (calculated as As) is 0.9444, ranking first among the six types of hazardous substances, which means that the probability of non-compliance of inorganic arsenic (calculated as As) is the highest. Therefore, when conducting food sampling inspections, inorganic arsenic (calculated as As) should be detected first. If the test results show that the inorganic arsenic exceeds the standard, there is no need to detect other hazardous substances, thus effectively saving time and human resources.
Claims
1. A food sampling inspection decision-making method based on graph attention network and Critic-Topsis includes the following steps: Step 1: Collect food sampling inspection data, including food types, sampling times, sampling locations, inspection items and results, and perform preprocessing, including data cleaning, normalization and collation. The said Step 1 includes: Step 101: Data collection. Collect food sampling inspection data, including food types, sampling times (specific to quarters, such as the first quarter, the second quarter, etc.), sampling locations (including provinces, cities and regions), and inspection items and results (such as content data of lead, cadmium, chromium, etc.). Step 102: Data preprocessing. Remove invalid data, standardize data formats, and ensure data non-duplication, and perform data normalization according to the following formula: where x ij is the value of the i-th sample on the j-th test item, and min(x i ) and min(x j ) are the maximum and minimum values of the j-th test item, respectively. Step 2: Input the preprocessed data into the graph attention network (GAT) model for training. By extracting node features and calculating the correlation weights between nodes, predict the sampling inspection times of each node. Step 3: Use the Critic-Topsis method to make decisions on the sampling inspection order of different harmful substances, and preferentially detect high-risk harmful substances according to the risk scores of harmful substances, so as to improve the sampling inspection efficiency and effect.
2. A decision support method based on graph attention network and Critic-Topsis as described in claim 1, the said Step 2 includes: Step 201: Construct a GAT model. As shown in Figure 2 is the structural diagram of the GAT model in this article: (1) Input layer: Feature vectors of food types, sampling times, sampling locations, inspection items, etc. (2) Graph attention layer: Calculate the correlation weights between nodes through the attention mechanism, and dynamically aggregate neighbor node information. Calculate the attention coefficient: Feature transformation. First, transform the feature vector of each node to a new feature space through a shared linear transformation matrix W: h i ′ = Wh i Then, input the transformed feature vector into an attention mechanism to calculate the attention coefficient between node i and node j: C ij = f(Wh i , Wh j ) = σ1(a Τ ·[(h i ′)‖(h j ′)]) where σ1 is the LeakyReLU activation function, a and W are the parameter matrices to be trained by the attention mechanism f, and || represents the concatenation operation. Normalize the attention coefficient: Among them, N i is the set of neighbor nodes of the target node i. Aggregate neighbor information: Further, use the normalized attention coefficient to aggregate the attribute feature information of neighbor nodes to reflect the local structural features of the target node, and generate the embedded vector representation of the target node: In addition, introduce the multi-head attention mechanism to improve the expression ability and robustness of the model, and adopt different processing methods at different stages of the model. For the intermediate layer, use the concatenation method to merge multiple groups of target node embeddings generated by the multi-head attention mechanism to obtain the embedded representation of the target node in the intermediate layer: where R is the number of heads of the multi-head attention mechanism, r = 1, 2,..., R. In order to capture deeper features and relationships, multiple graph attention layers can be stacked, and each layer will update and enhance the representation of the nodes. As shown in Figure 2, three graph attention layers are shown. (3) Readout layer: After the multi-layer graph attention layer, the feature representations of each node are aggregated into the overall graph feature. This step usually averages or sums the node features to obtain the feature representation of the overall graph. (4) Fully connected layer: The overall graph feature output by the readout layer is input into the fully connected layer, and the feature processing is performed through several layers of fully connected neural networks. The fully connected layer can be used to capture the global feature relationships and further extract high-level features. (5) Output layer: The mean method is used to merge multiple groups of target node embeddings generated by the multi-head attention mechanism to obtain the final output embedding representation of target node i: Use the Adam optimizer to update the parameters: where θ t is a parameter of the model, η is the learning rate, m t is the first moment estimate after bias correction, v t is the second moment estimate after bias correction, and ε is a small constant used to prevent division by zero errors. Step 202: Input the preprocessed food data and perform model training. Step 203: Use the trained model to predict the number of spot checks.
3. A decision support method based on a graph attention network and Critic-Topsis as described in claim 1, wherein step 3 includes: Step 301: Since the dimensions of the original data are different, in order to reduce the influence caused by the dimensional difference, it is necessary to normalize the data: First, construct the normalization initial matrix: Perform normalization processing on the initial matrix: Obtain the standardized matrix Z: Step 302: Use the Critic weight method to calculate the weights: Calculate the volatility: Among them, is the average value of the j-th column in the standardization matrix. Correlation matrix: Calculate the conflict: where: r ij represents the correlation coefficient between the i-th index and the j-th index. Calculate the information content: C j = S j × A j Calculate the weights: Step 303: Determine the optimal solution and the worst solution: Optimal solution Z + : Optimal solution Z - : Step 304: Calculate the closeness of each pollutant index to the optimal solution and the worst solution: Among them, w j is the objective weight of the j-th pollutant index obtained by the Critic method, that is, the degree of importance. Step 305: Among them, C i The closer it is to 1, the better the evaluation object is indicated.
Citation Information
Cited By
Underwater pile foundation damage condition evaluation method of GRA-KL-TOPSIS model based on game theory
CN119940736A
An underwater pile foundation damage condition evaluation method based on a game theory-based GRA-KL-TOPSIS model
CN119940736B