A food quality analysis method and system based on big data analysis
Patent Information
- Application Number
- CN202611262844.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-19
- Publication Date
- 2026-10-27
AI Technical Summary
食品质量数据来源分散,字段格式、采样周期和记录时间不一致,部分设备记录缺少批次标识,现有归集方式难以按照产品批次准确关联质量对象与质量事件,容易出现跨批次数据混入和质量关系缺失;不同食品类别和质量阶段的正常状态存在差异,固定基线或全局图分析方法难以表征质量状态的动态变化,并容易在图特征交互中引入其他批次的无关信息,导致异常识别结果不稳定;各质量阶段的持续时间及影响滞后不同,传统相关性分析或固定时间滞后的因果分析方法难以适配各质量阶段,容易遗漏延迟出现的风险因素或引入无关变量,且难以结合质量传递路径形成连续的质量影响链,影响异常批次处置优先级及管理决策信息的准确确定
本发明通过改进Graphormer模型与PCMCI算法的串联分析,针对食品质量及管理数据来源分散、批次标识不完整和时空关系不一致的问题,采用批次归集、数据清洗与时空对齐生成标准化质量特征集,以产品批次为主键关联质量对象与质量事件,构建时空质量关联图;在质量状态分析环节,通过有向路径编码表征质量因素的传递方向与事件次序,并利用批次图令牌和批次隔离机制阻断不同产品批次之间的无关特征交互,生成批次质量状态表示;针对不同食品类别和质量阶段正常波动不一致的问题,根据历史批次质量状态表示构建动态质量基线,通过状态均值和状态波动值识别质量异常指标;在风险追溯环节,根据各质量阶段持续时间设置阶段自适应时滞,通过PCMCI算法筛选风险因素,结合时空质量关联图反向搜索传递路径,生成风险因素排序结果和质量影响链,减少固定时滞造成的风险因素遗漏和无关变量引入,最终确定质量等级、异常批次及处置优先级,输出食品质量分析报告和管理决策信息。
Smart Images

Figure CN122988855A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of food quality management technology, and in particular to a food quality analysis method and system based on big data analysis. Background Technology
[0002] With the expansion of food production scale and the improvement of digitalization in quality management, food quality analysis technologies targeting raw materials, processing, testing, and storage have received widespread attention. Currently, food companies typically collect data separately through quality management systems, production monitoring equipment, and testing systems, and use fixed thresholds, statistical analysis, or correlation analysis methods to identify abnormal batches. However, the following problems commonly exist in practical applications: Food quality data sources are scattered, with inconsistent field formats, sampling periods, and recording times. Some equipment records lack batch identifiers, making it difficult for existing collection methods to accurately associate quality objects and quality events according to product batches. This can easily lead to cross-batch data mixing and missing quality relationships. The normal states of different food categories and quality stages vary, making it difficult for fixed baseline or global graph analysis methods to characterize the dynamic changes in quality status. Furthermore, irrelevant information from other batches can be introduced into graph feature interactions, resulting in unstable anomaly identification results. The duration and impact lag of each quality stage differ, making it difficult for traditional correlation analysis or causal analysis methods with fixed time lags to adapt to each quality stage. This can easily lead to the omission of delayed risk factors or the introduction of irrelevant variables, and it is difficult to combine the quality transmission path to form a continuous quality impact chain, affecting the accurate determination of the priority of handling abnormal batches and management decision information.
[0003] Therefore, how to provide a food quality analysis method and system based on big data analysis is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0004] One objective of this invention is to propose a food quality analysis method and system based on big data analytics. This invention employs a method combining an improved Graphormer model and the PCMCI algorithm. It constructs a spatiotemporal quality correlation graph through batch aggregation and spatiotemporal alignment, and sets up directed path encoding and batch isolation mechanisms to characterize the direction of quality transmission and block irrelevant feature interactions between different product batches. Based on this, a dynamic quality baseline is constructed according to historical batches to identify quality anomaly indicators. A stage-adaptive time lag is set in the PCMCI algorithm, and combined with reverse search of the correlation graph, risk factor ranking results and quality impact chains are formed. This enables the identification of abnormal batches, risk tracing, and determination of disposal priorities. It has the advantages of less cross-batch interference, accurate anomaly identification, clear impact chains, and strong targeted management decisions.
[0005] A food quality analysis method and system based on big data analysis according to an embodiment of the present invention includes the following steps: 1. A food quality analysis method based on big data analysis, characterized by comprising the following steps: S1. Collect food quality and management data, aggregate them by product batch, and generate a food quality dataset; S2. Clean the food quality dataset and perform spatiotemporal alignment to generate a standardized quality feature set; S3. Using the product batch as the primary key, associate quality objects and quality events to construct a spatiotemporal quality correlation graph; S4. Input the spatiotemporal quality correlation graph into the improved Graphormer model, use directed path encoding to represent the quality transfer path, and use a batch isolation mechanism to isolate cross-batch interactions to generate a batch quality status representation. S5. Statistically represent the historical batch quality status and construct a dynamic quality baseline. Compare the batch quality status representation with the dynamic quality baseline to generate a set of quality anomaly indicators. S6. Based on the time lag set for the quality stage, the PCMCI algorithm with adaptive time lag set for the stage is used to analyze the causal relationship between the quality anomaly indicators and risk factors. Combined with the spatiotemporal quality correlation diagram, a reverse path search is performed to generate the risk factor ranking results and the quality impact chain. S7. Determine the quality grade, abnormal batches, and handling priority based on the risk factor ranking results and the quality impact chain, and output a food quality analysis report and management decision information.
[0006] Optionally, S1 specifically includes: Obtain batch registration information from the food enterprise's quality management system, extract the batch number, food category, production task identifier, and formation time, and determine the product batch according to the batch number; Quality data is generated by reading food testing results and processing status records from quality testing systems and production monitoring equipment. Retrieve the business execution records corresponding to the product batch from the food enterprise's quality management system to form management data; Extract the data source, recording time, and food object identifier from the quality data and the management data, and write the extraction results into the corresponding data record to generate food quality and management data; Read the batch number from each piece of food quality and management data and match it with the corresponding product batch; For food quality and management data without recorded batch numbers, the production and operation period corresponding to each product batch is determined based on the batch registration information, and the corresponding product batch is determined by combining the recording time and food object identification. The matched food quality and management data are collected according to the product batches, and the data records within the same product batch are arranged according to the recording time to generate a food quality dataset.
[0007] Optionally, S2 specifically includes: Obtain the food quality dataset, parse the format of each data record according to the data source and field type, and identify duplicate records, missing fields and fields with abnormal format; Delete duplicate records with identical content, fill in missing fields based on the field values of adjacent records within the same product batch, and convert fields with abnormal formats to the corresponding target format to obtain the cleaned food quality data; Extract the recording time and data generation location from the quality data of the cleaned food, convert the recording time according to a unified time benchmark, and arrange the converted recording times according to the production and operation sequence corresponding to the product batch; The data generation location is mapped to the corresponding quality stage, and each data record is aligned according to the converted recording time and the quality stage to obtain spatiotemporally aligned data; The numerical fields in the spatiotemporal aligned data are subjected to unit unification and normalization, the categorical fields are encoded, and the processed fields are combined according to product batches to generate a standardized quality feature set.
[0008] Optionally, S3 specifically includes: Obtain the standardized quality feature set and the product batch, extract the batch identifier corresponding to each product batch, and generate a batch node set; Extract the quality object identifier and corresponding attribute field from the standardized quality feature set, merge the attribute fields according to the same quality object identifier, and generate a quality object node set. Quality events are divided according to the operation type and recording time of each data record, and data records that occur consecutively under the same operation type are merged into one quality event to generate a set of quality event nodes. Using the product batch as the primary key, establish batch affiliation edges between the batch node set and the quality object node set and the quality event node set, respectively; Event timing edges are established based on the order in which the quality events occur, and quality transfer edges are established based on the flow relationship of quality objects between adjacent quality stages. Record the time and data generation location and write them into the corresponding nodes and relational edges. Combine the batch node set, the quality object node set, the quality event node set, and each relational edge to construct a spatiotemporal quality correlation graph.
[0009] Optionally, the improved Graphormer model includes a node embedding module, a path encoding module, a batch isolation module, a graph encoding module, and a state output module. The path encoding module is configured with directed path encoding, and the batch isolation module embeds a batch isolation mechanism. The node attributes, node types, and recording times in the spatiotemporal quality correlation graph are input into the node embedding module, and numerical mapping and encoding processes are performed respectively. The corresponding results are concatenated and mapped to a unified dimension through a fully connected layer to generate the initial feature sequence of the nodes. The relationship edge is input into the path encoding module, and the directed path distance and path order between nodes are calculated according to the direction of the relationship edge and the order of quality events. The calculation result is converted into a path feature vector to generate a directed path feature matrix. The product batch and the node initial feature sequence are input into the batch isolation module. A batch graph token is established for each product batch. Each batch graph token is mapped as a special node to the unified dimension and added to the node initial feature sequence. The nodes are connected to the corresponding batch graph tokens according to the batch affiliation relationship to generate a batch node group. The batch isolation mechanism sets an interaction identifier for nodes within the same product batch and an isolation identifier for nodes in different product batches to generate a batch isolation matrix. The initial feature sequence of nodes, the directed path feature matrix, and the batch isolation matrix are input into the graph encoding module. The graph encoding module includes a multi-head self-attention layer, a residual normalization layer, and a feedforward network layer. The multi-head self-attention layer maps the initial feature vector of each node into a query vector, a key vector, and a value vector. The query vector and the key vector are multiplied dimension by dimension and accumulated. The accumulated result is then divided by the square root of the vector dimension to obtain the node correlation value. The corresponding path feature vector is input into the linear mapping layer to obtain the path correction value. The path correction value is then added to the node correlation value to obtain the path correction correlation value. Based on the batch isolation matrix, retain the path correction correlation values with interaction identifiers, set the path correction correlation values with isolation identifiers as mask values, normalize the retained path correction correlation values to obtain node interaction coefficients, multiply the node interaction coefficients with the corresponding value vectors dimension by dimension and accumulate them to generate a node aggregation feature sequence. The residual normalization layer adds the node aggregated feature sequence to the node initial feature sequence dimension by dimension and performs normalization. The feedforward network layer performs linear mapping and nonlinear transformation on the normalization result to generate the node encoded feature sequence. The node encoding feature sequence is input into the state output module, average pooling is performed according to the batch node group, batch graph token features are extracted, the average pooling result is concatenated with the batch graph token features and dimension mapping is performed to generate a batch quality state representation.
[0010] Optionally, the batch isolation mechanism specifically includes: In the batch isolation module, the batch node group and the initial feature sequence of the node are obtained, the product batch corresponding to each node is read, and a node batch mapping table is established according to the node arrangement order. Select any node from the node batch mapping table as the target node, and compare the product batches corresponding to the target node with the other nodes one by one; When the target node and another node correspond to the same product batch, the association position between the two nodes is set as an interaction identifier, and the other node is added to the set of interaction nodes in the batch corresponding to the target node. When the target node and another node correspond to different product batches, the association position between the two nodes is set as an isolation identifier, and the other node is added to the cross-batch isolation node set corresponding to the target node; Set the association position between each batch of graph tokens and all nodes within the corresponding product batch as an interaction identifier, and set the association position between the batch of graph tokens and nodes within other product batches as an isolation identifier. Write the interaction identifiers and isolation identifiers between each node into a two-dimensional matrix according to the node arrangement order to generate a batch isolation matrix; The batch isolation matrix is matched with the directed path feature matrix according to the node position, the path feature vector corresponding to the interaction identifier is retained, and the position corresponding to the isolation identifier is set as the mask position. When the graph encoding module aggregates node information, it retains the node features corresponding to the set of interactive nodes within the batch, and blocks the node features corresponding to the set of isolated nodes across batches from participating in the feature accumulation of the target node.
[0011] Optionally, S5 specifically includes: The food category and quality stage corresponding to each product batch are read from the standardized quality feature set, and batches with the same food category and quality stage as the product batch to be analyzed are selected from the historical batch quality status representation to form a historical reference batch set. The historical batch quality status representations in the historical reference batch set are sorted according to the recording time, and a preset number of adjacent historical batch quality status representations are selected to generate a dynamic reference status set. The state values of the same dimension in the dynamic reference state set are accumulated, and the accumulated result is divided by the number of historical batch quality state representations contained in the dynamic reference state set to obtain the state mean of each dimension. Calculate the difference between the quality status representation of each historical batch and the mean status value in the same dimension, and average the absolute value of the difference to obtain the status fluctuation value in each dimension. Replace the status fluctuation value with a value of zero with the preset minimum fluctuation value. The mean values of each dimension and the corresponding state fluctuation values are combined in order of feature dimension to construct a dynamic quality baseline; The batch quality status representation is obtained, and the status value of each dimension is subtracted from the corresponding status mean in the dynamic quality baseline and the absolute value is taken to obtain the status deviation value. Divide each state deviation value by the corresponding state fluctuation value to obtain the standardized deviation sequence. Each standardized deviation value in the standardized deviation sequence is compared with a preset deviation threshold. Feature dimensions exceeding the preset deviation threshold are extracted and mapped according to the correspondence between feature dimensions and quality indicators to generate a set of quality anomaly indicators.
[0012] Optionally, S6 specifically includes: Obtain the set of quality anomaly indicators, the set of standardized quality features, and the spatiotemporal quality correlation graph. Map each quality anomaly indicator to the corresponding quality object node or quality event node in the spatiotemporal quality correlation graph to generate a set of anomaly indicator nodes. Starting from the nodes in the set of abnormal indicator nodes, upstream nodes are extracted in the opposite direction of the quality transfer edge, and the quality features corresponding to the upstream nodes are identified as risk factors. Arrange the characteristic values corresponding to each quality anomaly indicator and each risk factor according to the recording time, and generate the time series of anomaly indicators and risk factors. Obtain the start and end times of the quality stage corresponding to each risk factor, subtract the start time from the end time to obtain the stage duration, divide the stage duration by the data sampling interval, and round up the resulting quotient to obtain the stage lag order. The PCMCI algorithm sets a stage adaptive time lag, and sets the stage lag order corresponding to each risk factor as the maximum time lag between the risk factor and the quality anomaly index. The time series of the abnormal indicators and the time series of the risk factors are input into the PCMCI algorithm. Lagged variables are selected within the maximum time lag corresponding to each risk factor. The conditional independence test between the lagged variables and the quality abnormal indicators is performed through PC screening. Lagged variables that satisfy the conditional independence relationship are deleted, and a set of candidate parent variables is generated. Perform instantaneous conditional independence test on each candidate parent variable in the candidate parent variable set, calculate the conditional dependency strength between each candidate parent variable and the quality anomaly index, retain candidate parent variables whose conditional dependency strength exceeds a preset dependency threshold, and generate a time-delay causal relationship set. The time-delay causal relationship set is mapped to the spatiotemporal quality correlation graph. Reverse path search is performed starting from each abnormal indicator node. Reverse paths containing the time-delay causal relationship are retained to generate candidate quality impact paths. The risk contribution value is obtained by multiplying the condition dependence strength of each risk factor by the standardized deviation value of the corresponding quality anomaly index. The risk factors are then arranged in descending order of their risk contribution values to generate a risk factor ranking result. The nodes in the candidate quality impact paths are arranged according to the quality stage and time lag, and consecutive paths with the same start and end points are merged to generate a quality impact chain.
[0013] Optionally, S7 specifically includes: Obtain the set of quality anomaly indicators, the ranking results of the risk factors, and the quality impact chain; determine the product batches corresponding to each quality anomaly indicator, risk factor, and quality impact chain according to the product batches. The number of quality anomaly indicators for each product batch is counted. The position of each risk factor in the risk factor ranking result is read. The total number of risk factors is subtracted from the ranking position and then one is added to obtain the risk ranking value. The risk ranking values for the same product batch are summed to obtain the batch risk ranking value. The number of quality stages included in each quality impact chain is calculated and the number of quality stages for the same product batch is summed to obtain the batch impact stage number. The number of quality anomaly indicators, the batch risk ranking value, and the number of batch impact stages are normalized respectively. The normalization results corresponding to the same product batch are summed to obtain the batch quality risk value. The batch quality risk value is matched with a preset quality level range to determine the quality level corresponding to each product batch, and the product batch with a batch quality risk value exceeding a preset abnormal threshold is determined as an abnormal batch. The abnormal batches are arranged in descending order of their batch quality risk value. When multiple abnormal batches have the same batch quality risk value, they are arranged in descending order of the number of stages of impact of the batches to form a priority for handling. Based on the product batch, compile the corresponding quality grade, quality anomaly index set, risk factor ranking results, quality impact chain and disposal priority to generate a food quality analysis report; Based on the quality level and the disposal priority, corresponding quality re-inspection, batch isolation, or production adjustment operations are matched to generate management decision information.
[0014] A food quality analysis system based on big data analysis according to an embodiment of the present invention includes the following modules: The data collection module is used to collect food quality and management data, collect them according to product batches, and generate a food quality dataset. The feature processing module is used to clean the food quality dataset and perform spatiotemporal alignment to generate a standardized quality feature set; The association graph construction module is used to construct a spatiotemporal quality association graph by associating quality objects and quality events with the product batch as the primary key. The state analysis module is used to input the spatiotemporal quality correlation graph into the improved Graphormer model, and perform graph feature processing through directed path encoding and batch isolation mechanism to generate batch quality state representations. The anomaly analysis module is used to statistically represent the quality status of historical batches and construct a dynamic quality baseline, compare the batch quality status representation with the dynamic quality baseline, and generate a set of quality anomaly indicators. The risk tracing module is used to analyze the causal relationship between the quality anomaly indicators and risk factors by setting the time lag according to the quality stage, and to perform reverse path search in combination with the spatiotemporal quality correlation graph to generate risk factor ranking results and quality impact chain. The decision output module is used to determine the quality level, abnormal batches and disposal priority based on the risk factor ranking results and the quality impact chain, and output food quality analysis reports and management decision information.
[0015] The beneficial effects of this invention are: This invention addresses the issues of scattered data sources, incomplete batch identification, and inconsistent spatiotemporal relationships in food quality and management by improving the cascade analysis of the Graphormer model and the PCMCI algorithm. It employs batch aggregation, data cleaning, and spatiotemporal alignment to generate a standardized quality feature set, using product batches as the primary key to associate quality objects and events, constructing a spatiotemporal quality correlation graph. In the quality status analysis stage, directed path encoding represents the transmission direction and event sequence of quality factors, and batch graph tokens and batch isolation mechanisms are used to block irrelevant feature interactions between different product batches, generating a batch quality status representation. To address the issue of inconsistent normal fluctuations across different food categories and quality stages, a dynamic quality baseline is constructed based on historical batch quality status representations, identifying quality anomalies through state mean and state fluctuation values. In the risk traceability stage, an adaptive time lag is set based on the duration of each quality stage. The PCMCI algorithm is used to screen risk factors, and the spatiotemporal quality correlation graph is combined with a reverse search of the transmission path to generate risk factor ranking results and quality impact chains. This reduces the omission of risk factors and the introduction of irrelevant variables caused by fixed time lags, ultimately determining the quality level, abnormal batches, and disposal priorities, outputting a food quality analysis report and management decision information. Attached Figure Description
[0016] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is an overall flowchart of a food quality analysis method based on big data analysis proposed in this invention; Figure 2 This is a schematic diagram of the improved Graphormer model structure proposed in this invention; Figure 3 This is a schematic diagram of the structure of a food quality analysis system based on big data analysis proposed in this invention. Detailed Implementation
[0017] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0018] refer to Figures 1-2 A food quality analysis method based on big data analysis includes the following steps: S1. Collect food quality and management data, aggregate them by product batch, and generate a food quality dataset; S2. Clean the food quality dataset and perform spatiotemporal alignment to generate a standardized quality feature set; S3. Using product batch as the primary key, associate quality objects and quality events to construct a spatiotemporal quality correlation graph; S4. Input the spatiotemporal quality correlation graph into the improved Graphormer model, use directed path encoding to represent the quality transfer path, and use a batch isolation mechanism to isolate cross-batch interactions to generate batch quality status representations. S5. Statistically represent the historical batch quality status and construct a dynamic quality baseline. Compare the batch quality status representation with the dynamic quality baseline to generate a set of quality anomaly indicators. S6. Based on the time lag set for the quality stage, the PCMCI algorithm with adaptive time lag set for the stage is used to analyze the causal relationship between quality anomaly indicators and risk factors. Combined with the spatiotemporal quality correlation diagram, a reverse path search is performed to generate the risk factor ranking results and quality impact chain. S7. Determine the quality grade, abnormal batches, and handling priority based on the risk factor ranking results and quality impact chain, and output food quality analysis report and management decision information.
[0019] In this embodiment, S1 specifically refers to: Obtain batch registration information from the food enterprise's quality management system, extract the batch number, food category, production task identifier, and formation time, and determine the product batch according to the batch number; Quality data is generated by reading food testing results and processing status records from quality testing systems and production monitoring equipment. Retrieve business execution records corresponding to product batches from the food enterprise's quality management system to form management data; Extract data source, recording time and food object identifier from quality data and management data, and write the extraction results into the corresponding data records to generate food quality and management data; Read the batch number from each piece of food quality and management data and match it with the corresponding product batch; For food quality and management data without recorded batch numbers, the production and operation period corresponding to each product batch is determined based on the batch registration information, and the corresponding product batch is determined by combining the recorded time and food object identification. The matched food quality and management data are collected according to product batches, and the data records within the same product batch are arranged according to the recording time to generate a food quality dataset. In practice, the food enterprise quality management system uses a relational database to store batch registration information and business execution records. The batch number is set to 12 to 20 characters. Quality inspection results are written after each inspection. Production monitoring equipment reads the processing status records at 30-second sampling intervals. The data source code, recording time, and food object identifier are written into each data record, and the recording time is uniformly converted into a millisecond-level timestamp to form food quality and management data. For data records containing batch numbers, precise matching is performed according to the batch number. For data records that do not include batch numbers, the production and operation period of the product batch is extended by 30 minutes before and after. Candidate product batches whose record time falls within the extended period and whose food object identifier is consistent are selected. If there are multiple candidate product batches, the product batch with the smallest absolute value of the difference between the formation time and the record time is selected. After the matching is completed, data groups are established by batch number, and the records in the group are arranged in ascending order of record time. The batch registration information, quality data and management data are combined into a food quality dataset.
[0020] In this embodiment, S2 specifically refers to: Obtain a food quality dataset, parse the format of each data record according to the data source and field type, and identify duplicate records, missing fields, and fields with abnormal format. Delete duplicate records with identical content, fill in missing fields based on the field values of adjacent records within the same product batch, and convert fields with abnormal formats to the corresponding target format to obtain the cleaned food quality data; Extract the recording time and data generation location from the quality data of the cleaned food, convert the recording time according to a unified time benchmark, and arrange the converted recording time according to the production and operation sequence corresponding to the product batch; The data generation location is mapped to the corresponding quality stage, and each data record is aligned according to the converted recording time and quality stage to obtain spatiotemporally aligned data; The numerical fields in the spatiotemporally aligned data are subjected to unit unification and normalization, the categorical fields are encoded, and the processed fields are combined according to product batches to generate a standardized quality feature set. In the specific implementation process, the product batch, food object identifier and record time are used as the composite index. When the composite index of two data records is the same and the field content is consistent, the data record written for the first time is retained. When the numerical field is missing and the time interval between adjacent records does not exceed 10 minutes, the adjacent field values are used for linear interpolation. The categorical field is filled with the field value of the most recent record. Data records with a field missing ratio of more than 30% are deleted. The recording time is uniformly converted into millisecond-level timestamps, and the measurement unit of the test results is converted into a preset standard unit to obtain the quality data of the cleaned food. According to the preset location and stage mapping table, the quality stage corresponding to each data generation location is determined. With 1 minute as the time window, the data records of the same product batch and quality stage are arranged in ascending order according to the recording time to obtain spatiotemporally aligned data. Numerical fields are mapped to the 0-1 range using the min-max normalization method, while categorical fields are encoded using one-hot encoding. The processed fields are then concatenated according to product batch, quality stage, and time window to generate a standardized quality feature set.
[0021] In this embodiment, S3 specifically refers to: Obtain standardized quality feature sets and product batches, extract batch identifiers corresponding to each product batch, and generate a set of batch nodes; Extract the quality object identifier and corresponding attribute field from the standardized quality feature set, merge the attribute fields according to the same quality object identifier, and generate a set of quality object nodes; Quality events are divided according to the operation type and recording time of each data record, and data records that occur consecutively under the same operation type are merged into one quality event to generate a set of quality event nodes. Using product batch as the primary key, establish batch affiliation edges between the batch node set and the quality object node set and the quality event node set, respectively; Establish event sequence edges based on the order in which quality events occur, and establish quality transfer edges based on the flow relationship of quality objects between adjacent quality stages; Write the recording time and data generation location into the corresponding nodes and relational edges, combine the batch node set, quality object node set, quality event node set and each relational edge to construct a spatiotemporal quality correlation graph; In the specific implementation process, a unique batch node number is assigned to each product batch, and the batch number, food category and formation time are written into the node attribute to generate a batch node set; using the food object identifier as the merging key, the detection value, processing status and location code of the same food object in different records are arranged according to the record time and written into the same node to generate a quality object node set; Data records with the same operation type, the same product batch, and an adjacent record time interval of no more than 5 minutes are merged into one quality event. The start and end times of the first and last records are used as the event start and end times, respectively. Event node numbers are generated according to product batch, operation type, and event start time to form a quality event node set. Batch nodes are pointed to the corresponding quality object nodes and quality event nodes to establish batch affiliation edges. Connect adjacent quality event nodes within the same product batch in ascending order of event start time to establish event sequence edges; when the same quality object has records in adjacent quality stages, establish quality transfer edges in the direction from the previous quality stage to the next quality stage; write the millisecond-level timestamp after converting the record time into the nodes and relationship edges, write the location code corresponding to the data generation location into the node attributes, and finally combine the node sets and relationship edges in the form of a node table and a relationship edge table to construct a spatiotemporal quality association graph.
[0022] In this embodiment, the improved Graphormer model includes a node embedding module, a path encoding module, a batch isolation module, a graph encoding module, and a state output module. The path encoding module is configured with directed path encoding, and the batch isolation module embeds a batch isolation mechanism. The node attributes, node type, and recording time in the spatiotemporal quality correlation graph are input into the node embedding module. Numerical mapping and encoding processes are performed respectively. The corresponding results are concatenated and mapped to a unified dimension through a fully connected layer to generate the initial feature sequence of the nodes. Input the relation edges into the path encoding module, calculate the directed path distance and path order between nodes according to the direction of the relation edges and the order of quality events, convert the calculation results into path feature vectors, and generate a directed path feature matrix; The product batch and node initial feature sequence are input into the batch isolation module. A batch graph token is created for each product batch. Each batch graph token is mapped to a unified dimension as a special node and added to the node initial feature sequence. The nodes are connected to the corresponding batch graph tokens according to the batch affiliation relationship to generate batch node groups. The batch isolation mechanism sets interaction identifiers for nodes within the same product batch and isolation identifiers for nodes in different product batches to generate a batch isolation matrix. The initial feature sequence of nodes, the directed path feature matrix, and the batch isolation matrix are input into the graph encoding module. The graph encoding module includes a multi-head self-attention layer, a residual normalization layer, and a feedforward network layer. The multi-head self-attention layer maps the initial feature vector of each node into a query vector, a key vector, and a value vector. The query vector and the key vector are multiplied dimension by dimension and accumulated. The accumulated result is then divided by the square root of the vector dimension to obtain the node correlation value. The corresponding path feature vector is input into the linear mapping layer to obtain the path correction value. The path correction value is then added to the node correlation value to obtain the path correction correlation value. Based on the batch isolation matrix, retain the path correction correlation values with interaction identifiers, set the path correction correlation values with isolation identifiers as mask values, normalize the retained path correction correlation values to obtain node interaction coefficients, multiply the node interaction coefficients with the corresponding value vectors dimension by dimension and accumulate them to generate a node aggregation feature sequence. The residual normalization layer adds the node aggregated feature sequence to the node initial feature sequence dimension by dimension and performs normalization. The feedforward network layer performs linear mapping and nonlinear transformation on the normalization result to generate the node encoded feature sequence. The node encoding feature sequence is input into the state output module, average pooling is performed according to the batch node group, the batch graph token feature is extracted, the average pooling result is concatenated with the batch graph token feature and dimension mapping is performed to generate the batch quality state representation. In the specific implementation process, the Graphormer model is improved by inheriting the node encoding and graph modeling process of the traditional Graphormer model. Directed path encoding is set in the path encoding module, and batch graph tokens and batch isolation mechanisms are set in the batch isolation module. Numerical node attributes are normalized to the 0-1 range, and node type and recording time are converted into encoded vectors. These are then concatenated with numerical node attributes and mapped through a fully connected layer to a 256-dimensional initial node feature vector. The initial node feature sequence is then generated by arranging the nodes according to their node numbers. The path encoding module searches for the shortest directed path with a length not exceeding 8 between any two nodes along the direction of the relation edges; it encodes the type, direction, and arrangement position of each relation edge in the path, and then sums each encoded vector dimension by dimension and divides it by the number of relation edges to obtain the path feature vector; it writes an unreachable flag for node pairs that do not have a directed path, and arranges all path feature vectors according to the node positions to generate a directed path feature matrix. The batch isolation module establishes a 256-dimensional batch graph token for each product batch. This token is added as a special node to the initial feature sequence of the node and connected to nodes within the corresponding batch. Interaction identifiers are written to node pairs within the same batch, while isolation identifiers are written to node pairs from different batches. The batch graph token only interacts with nodes in its corresponding batch, generating a batch isolation matrix. The graph encoding module sets up a 4-layer graph encoding structure, each layer including an 8-head self-attention layer, a residual normalization layer, and a feedforward network layer. Each attention head divides the 256-dimensional node features into a 32-dimensional query vector, key vector, and value vector. The query vector is multiplied by the corresponding dimensions of the key vector, summed, and then divided by the square root of 32 to obtain the node relevance value. The path feature vector is linearly mapped to a path correction value and added to the node relevance value. A negative infinity masking value is written to the isolation identifier position, and exponential normalization is performed on the remaining values to obtain the node interaction coefficients. The node interaction coefficients are multiplied dimension-wise with their corresponding value vectors and then accumulated to form node aggregation features. These features are then processed through residual summation, layer normalization, and a feedforward network to generate a node encoding feature sequence. The state output module performs average pooling on the node encoding features within the same batch, concatenates the pooling result with the batch graph token features, and maps it to a 256-dimensional vector to generate a batch quality state representation. Traditional Graphormer primarily describes the graph structure based on distances between nodes and uses a single graph token to participate in all graph node interactions. The improved Graphormer model preserves the quality transmission direction and event order through directed path encoding and blocks irrelevant batch features from mixing in through a batch isolation mechanism. This preserves the complete quality correlation within a batch while reducing interference between different food categories and production periods, improving the boundary clarity and anomaly discrimination capability of the batch quality state representation.
[0023] In this embodiment, the batch isolation mechanism is specifically as follows: In the batch isolation module, the batch node group and the initial feature sequence of the node are obtained, the product batch corresponding to each node is read, and a node batch mapping table is established according to the node arrangement order. Select any node from the node batch mapping table as the target node, and compare the target node with the product batches corresponding to the other nodes one by one. When the target node and another node correspond to the same product batch, the association position between the two nodes is set as the interaction identifier, and the other node is added to the set of interaction nodes in the batch corresponding to the target node. When the target node and another node correspond to different product batches, set the association position between the two nodes as an isolation identifier, and add the other node to the cross-batch isolation node set corresponding to the target node; Set the association position between each batch of graph tokens and all nodes within the corresponding product batch as an interaction identifier, and set the association position between batch graph tokens and nodes within other product batches as an isolation identifier. Write the interaction identifiers and isolation identifiers between nodes into a two-dimensional matrix according to the node arrangement order to generate a batch isolation matrix; The batch isolation matrix is matched with the directed path feature matrix according to the node position, the path feature vector corresponding to the interaction identifier is retained, and the position corresponding to the isolation identifier is set as the mask position. When the graph coding module aggregates node information, it retains the node features corresponding to the interactive node set within a batch and blocks the node features corresponding to the isolated node set across batches from participating in the feature accumulation of the target node. In the specific implementation process, the batch isolation module assigns a continuous index to each ordinary node and batch graph token according to the arrangement position in the initial feature sequence of the nodes, and writes the node index, node type and product batch into the node batch mapping table; for any target node, it reads the product batch corresponding to the target node, and then reads the product batches corresponding to the remaining nodes in turn. When the product batches of two nodes are the same, the corresponding associated position is written with the value 1 as an interaction identifier, and the corresponding node index is added to the batch-interactive node set; when the product batches of two nodes are different, the corresponding associated position is written with the value 0 as an isolation identifier, and the corresponding node index is added to the cross-batch isolation node set. For batch graph tokens, write the bidirectional association positions between the batch graph token and all nodes within the corresponding product batch into the interaction identifier, and write the association positions between the batch graph token and nodes within other product batches and other batch graph tokens into the isolation identifier; build a two-dimensional matrix with the same number of rows and columns according to the total number of nodes, where the matrix rows represent target nodes and the matrix columns represent nodes participating in the interaction, and write the interaction identifier and isolation identifier corresponding to each association position into the matrix to generate a batch isolation matrix; The batch isolation matrix and the directed path feature matrix are matched item by item according to the same row and column positions. The path feature vector corresponding to the interaction identifier remains unchanged, while the path feature vector corresponding to the isolation identifier is replaced with a zero vector. When the graph coding module calculates the node correlation value, the node correlation value corresponding to the set of interactive nodes within the batch is retained, while the node correlation value corresponding to the set of isolated nodes across batches is set to negative billion. After performing exponential normalization on the processed node correlation value, the node interaction coefficient corresponding to the isolation position approaches zero, and the node interaction coefficient corresponding to the interaction position is allocated according to the correlation magnitude. The interaction coefficients of each node are multiplied dimension-wise with the value vectors of the corresponding nodes within the batch and then accumulated to obtain the node aggregation feature of the target node. All nodes are processed in the same way to complete the information aggregation within the batch. Compared to the traditional Graphormer method that allows all graph nodes to directly participate in correlation calculation, the batch isolation mechanism cuts off the feature transfer between different product batches through matrix masking, while retaining the batch graph token for the overall aggregation of quality objects and quality events within the batch. This prevents features from high-frequency batches or abnormal batches from entering the quality state representation of other batches, improving the state independence between different product batches.
[0024] In this embodiment, S5 specifically refers to: The food category and quality stage corresponding to each product batch are read from the standardized quality feature set, and batches with the same food category and quality stage as the product batch to be analyzed are selected from the historical batch quality status representation to form a historical reference batch set. The historical batch quality status representations in the historical reference batch set are sorted according to the recording time, and a preset number of adjacent historical batch quality status representations are selected to generate a dynamic reference status set. The state values of the same dimension in the dynamic reference state set are accumulated, and the accumulated result is divided by the number of historical batch quality state representations contained in the dynamic reference state set to obtain the state mean of each dimension. Calculate the difference between the quality status representation and the status mean of each historical batch in the same dimension, and average the absolute value of the difference to obtain the status fluctuation value in each dimension. Replace the status fluctuation value with zero value with the preset minimum fluctuation value. The mean values of each dimension and the corresponding state fluctuation values are combined in order of feature dimension to construct a dynamic quality baseline; To obtain the batch quality status representation, the status value of each dimension is subtracted from the corresponding status mean in the dynamic quality baseline, and the absolute value is taken to obtain the status deviation value. Divide each state deviation value by the corresponding state fluctuation value to obtain the standardized deviation sequence. Each standardized deviation value in the standardized deviation sequence is compared with a preset deviation threshold. Feature dimensions that exceed the preset deviation threshold are extracted and mapped according to the correspondence between feature dimensions and quality indicators to generate a set of quality anomaly indicators. In the specific implementation process, food category and quality stage are used as joint screening conditions. The most recent 30 product batches are selected from the historical batch quality status representations before the analysis time. If the number of historical batches is less than 30, all historical batches that meet the conditions are used. If there are fewer than 10, dynamic quality baselines are not generated. The screened historical batch quality status representations are arranged in ascending order of recording time to generate a dynamic reference status set. The batch quality status representation is set to 256 dimensions. The status values of each dimension in the dynamic reference status set are accumulated and divided by the number of historical batches involved in the calculation to obtain the status mean of the corresponding dimension. The absolute value of the difference between each historical status value and the corresponding status mean is calculated. All absolute differences of the same dimension are accumulated and divided by the number of historical batches to obtain the status fluctuation value. When the status fluctuation value is less than 0.01, it is replaced with 0.01. The 256 status means and status fluctuation values are stored according to the dimension number to construct the dynamic quality baseline. The standard deviation sequence is obtained by subtracting the mean value of each dimension of the product batch to be analyzed from the mean value of the corresponding state and taking the absolute value, and then dividing by the corresponding state fluctuation value. The preset deviation threshold is set to 3.0, and feature dimensions with a standard deviation value greater than 3.0 are extracted. The correlation coefficient between each feature dimension and quality indicator in the training sample is pre-calculated, and the quality indicator with the largest absolute correlation coefficient is taken as the corresponding indicator, and a mapping table between feature dimensions and quality indicators is established. According to the mapping table, feature dimensions exceeding the preset deviation threshold are converted into corresponding quality indicators, and the product batch, quality stage, standard deviation value and quality indicator name are recorded to generate a set of quality anomaly indicators.
[0025] In this embodiment, S6 specifically refers to: Obtain the set of quality anomaly indicators, the set of standardized quality features, and the spatiotemporal quality correlation graph. Map each quality anomaly indicator to the corresponding quality object node or quality event node in the spatiotemporal quality correlation graph to generate a set of anomaly indicator nodes. Starting from the nodes in the abnormal indicator node set, extract the upstream nodes in the opposite direction of the quality transmission edge, and determine the quality characteristics corresponding to the upstream nodes as risk factors. Arrange the characteristic values corresponding to each quality anomaly indicator and each risk factor according to the recording time, and generate the time series of anomaly indicators and risk factors. Obtain the start and end times of the quality phase corresponding to each risk factor, subtract the start time from the end time to get the phase duration, divide the phase duration by the data sampling interval, and round up the resulting quotient to obtain the phase lag order. The PCMCI algorithm sets a stage adaptive time lag, and sets the stage lag order corresponding to each risk factor to the maximum time lag between the risk factor and the quality anomaly index. Input the time series of abnormal indicators and the time series of risk factors into the PCMCI algorithm, select lagged variables within the maximum time lag corresponding to each risk factor, perform conditional independence tests on lagged variables and quality abnormal indicators through PC screening, delete lagged variables that satisfy the conditional independence relationship, and generate a set of candidate parent variables. Perform instantaneous conditional independence tests on each candidate parent variable in the candidate parent variable set, calculate the conditional dependency strength between each candidate parent variable and the quality anomaly index, retain candidate parent variables whose conditional dependency strength exceeds the preset dependency threshold, and generate a time-delay causal relationship set. The time-delay causal relationship set is mapped to the spatiotemporal quality correlation graph. Reverse path search is performed starting from each abnormal indicator node. Reverse paths containing time-delay causal relationships are retained to generate candidate quality impact paths. The risk contribution value is obtained by multiplying the condition dependence strength of each risk factor by the standardized deviation value of the corresponding quality anomaly index. The risk factors are then ranked from largest to smallest according to their risk contribution values to generate the risk factor ranking results. The nodes in the candidate quality impact paths are arranged according to the quality stage and time lag, and consecutive paths with the same start and end points are merged to generate a quality impact chain. In the specific implementation process, based on the product batch, quality stage, and quality indicator name, the quality anomaly indicators are matched with the node attributes in the spatiotemporal quality correlation diagram. When the quality indicator corresponds to the food test result, it is mapped to the quality object node; when the quality indicator corresponds to the processing operation or management record, it is mapped to the quality event node, generating a set of anomaly indicator nodes. Starting from each anomaly indicator node, upstream nodes are searched in the opposite direction of the quality transmission edge for no more than 6 layers. The test values, processing status, and business execution fields associated with the upstream nodes are extracted to determine the risk factors. Based on a 1-minute data sampling interval, the quality anomaly index values and risk factor values within the same product batch are arranged according to the recording time. When multiple values exist at the same sampling location, the average value is taken. For missing locations, linear interpolation of adjacent values is used to generate the anomaly index time series and risk factor time series, respectively. The end time of the quality stage corresponding to the risk factor is subtracted from the start time to obtain the stage duration. This duration is then divided by 1 minute and rounded up to obtain the stage lag order. When the stage lag order is less than 1, it is set to 1; when it is greater than 120, it is set to 120. The processed stage lag order is used as the maximum time lag of the corresponding risk factor. The time series of abnormal indicators and risk factors are input into the PCMCI algorithm, and lagged variables are constructed sequentially within the maximum time lag range corresponding to each risk factor. The PC screening adopts the partial correlation conditional independence test, with the significance level set to 0.05 and the upper limit of the number of conditional variables set to 3. When the test probability between the lagged variable and the quality abnormal indicator is greater than 0.05, it is determined that the two satisfy the conditional independence relationship and the lagged variable is deleted. The remaining lagged variables form a candidate parent variable set. Perform instantaneous conditional independence tests on candidate parent variables and use the absolute value of the partial correlation coefficient as the conditional dependency strength; retain candidate parent variables with a test probability of no more than 0.05 and a conditional dependency strength of more than 0.2, and record risk factors, quality anomaly indicators, and time lags to generate a time-lag causal relationship set; map the time-lag causal relationships to a spatiotemporal quality correlation graph, and search in the reverse direction from the anomaly indicator node for paths containing the corresponding risk factor nodes and time sequence to generate candidate quality impact paths; The risk contribution value is obtained by multiplying the conditional dependency strength by the standardized deviation value of the corresponding quality anomaly indicator. Risk factors are then ranked in descending order of risk contribution value to generate a risk factor ranking result. Nodes in the candidate quality impact paths are connected according to the sequence of quality stages and time lag. Duplicate paths with nodes sharing the same anomaly indicator and risk factor are merged, retaining the path with complete nodes and the highest risk contribution value to generate a quality impact chain. Compared to the PCMCI algorithm using a uniform maximum time lag, the stage-adaptive time lag limits the causal search range according to the actual duration of each quality stage, reducing causal omissions caused by excessively short time lags and irrelevant variables introduced by excessively long time lags, thus improving the targeting of food quality risk traceability and impact chain identification.
[0026] In this embodiment, S7 specifically refers to: Obtain the set of quality anomaly indicators, the ranking results of risk factors, and the quality impact chain; determine the product batches corresponding to each quality anomaly indicator, risk factor, and quality impact chain according to the product batch. The number of quality anomalies for each product batch is counted. The position of each risk factor in the risk factor ranking result is read. The total number of risk factors is subtracted from the ranking position and then one is added to obtain the risk ranking value. The risk ranking values for the same product batch are summed to obtain the batch risk ranking value. The number of quality stages included in each quality impact chain is calculated and the number of quality stages for the same product batch is summed to obtain the batch impact stage number. The number of quality anomaly indicators, batch risk ranking value, and number of batch impact stages were normalized respectively. The normalized results corresponding to the same product batch were summed to obtain the batch quality risk value. The batch quality risk value is matched with the preset quality level range to determine the quality level corresponding to each product batch, and the batch quality risk value exceeding the preset abnormal threshold is identified as an abnormal batch. The abnormal batches are arranged in descending order of batch quality risk value. When multiple abnormal batches have the same batch quality risk value, they are arranged in descending order of the number of stages of impact of the batch to form a priority for handling. A food quality analysis report is generated by compiling the corresponding quality grade, set of quality anomaly indicators, ranking results of risk factors, quality impact chain and disposal priority according to product batch; Based on the quality level and disposal priority, corresponding quality re-inspection, batch isolation, or production adjustment operations are matched to generate management decision information; In the specific implementation process, quality anomaly indicators, risk factors, and quality impact chains are associated according to the product batch number; the number of quality anomaly indicators for each product batch is counted, and the position of each risk factor is read according to the risk factor ranking result. The total number of risk factors for the corresponding product batch is subtracted from the ranking position and then 1 is added to obtain the risk ranking value. All risk ranking values are summed to obtain the batch risk ranking value; the number of quality stages traversed by each quality impact chain is counted, and the statistical results for the same product batch are summed to obtain the batch impact stage number. Obtain the maximum and minimum values of the number of quality anomaly indicators, batch risk ranking value, and number of batch impact stages for all product batches to be analyzed. Subtract the corresponding minimum value from each value and divide by the difference between the maximum and minimum values to obtain the normalized result in the range of 0 to 1. When the maximum and minimum values are equal, set the corresponding normalized result to 0. Add the three normalized results for the same product batch to obtain the batch quality risk value in the range of 0 to 3. Product batches with quality risk values less than 0.75, between 0.75 and 1.5, between 1.5 and 2.25, and not less than 2.25 are sequentially classified as the first quality level, the second quality level, the third quality level, and the fourth quality level. The preset abnormal threshold is set to 1.5, and product batches with quality risk values not less than 1.5 are identified as abnormal batches. Abnormal batches are arranged in descending order of batch quality risk value, and if the values are the same, they are arranged in descending order of the number of batches affected at different stages, thus forming a priority for handling. The food quality analysis report is generated by compiling the quality grade, quality anomaly indicator set, risk factor ranking results, quality impact chain, and disposal priority of product batches. For the second quality grade, quality re-inspection is matched; for the third quality grade, quality re-inspection and batch isolation are matched; and for the fourth quality grade, batch isolation and production adjustment are matched. The execution order of each operation is arranged according to the disposal priority to generate management decision information.
[0027] refer to Figure 3 A food quality analysis system based on big data analytics includes the following modules: The data collection module is used to collect food quality and management data, collect them according to product batches, and generate a food quality dataset. The feature processing module is used to clean the food quality dataset and perform spatiotemporal alignment to generate a standardized quality feature set; The association graph construction module is used to construct a spatiotemporal quality association graph by associating quality objects and quality events with product batches as the primary key. The state analysis module is used to input the spatiotemporal quality correlation graph into the improved Graphormer model, and perform graph feature processing through directed path encoding and batch isolation mechanisms to generate batch quality state representations. The anomaly analysis module is used to statistically represent the quality status of historical batches and construct a dynamic quality baseline, compare the batch quality status representation with the dynamic quality baseline, and generate a set of quality anomaly indicators. The risk tracing module is used to analyze the causal relationship between quality anomaly indicators and risk factors by setting a time lag according to the quality stage and using the PCMCI algorithm with adaptive time lag for the set stage. It also combines the spatiotemporal quality correlation graph to perform reverse path search and generate risk factor ranking results and quality impact chain. The decision output module is used to determine the quality level, abnormal batches, and handling priorities based on the risk factor ranking results and quality impact chain, and output food quality analysis reports and management decision information.
[0028] Example 1: To verify the feasibility of this invention in practice, it was applied to a multi-category baked goods quality management scenario in a food production company. This company alternately produces bread, cakes, and biscuits, with production management data, quality inspection data, and equipment monitoring data stored in different systems. Because the normal quality ranges differ for different food categories, and the durations of ingredient preparation, baking, cooling, and packaging stages vary, traditional fixed threshold analysis is prone to false alarms. Furthermore, when multiple product batches are produced adjacently, there are issues with cross-batch data mixing and incorrect association of risk factors.
[0029] This embodiment collected food quality and management data from 720 product batches over three months, including 18,432 quality inspection records, 438,615 equipment monitoring records, and 55,389 management records related to production tasks, material requisition, batch release, and re-inspection procedures, totaling 512,436 data records. The first 520 product batches were used as historical reference data, and the last 200 product batches were used as data for analysis. After confirmation by quality management personnel based on re-inspection results, 34 abnormal batches were found among the 200 product batches to be analyzed.
[0030] Data records were grouped by product batch and aligned using a 1-minute time window. A spatiotemporal quality correlation graph was constructed based on product batches, quality objects, and quality events, resulting in 720 batch nodes, 6843 quality object nodes, 11276 quality event nodes, and 48719 relationship edges. The spatiotemporal quality correlation graph was input into an improved Graphormer model. Directed path encoding was used to preserve the quality transmission direction and event order, and a batch isolation mechanism was used to shield the node interactions between different product batches, generating a 256-dimensional batch quality status representation.
[0031] Based on food category and quality stage, a dynamic quality baseline is constructed by selecting the most recent 30 historical batches for each product batch to be analyzed. Feature dimensions with standardized deviation values exceeding 3.0 are mapped to quality anomaly indicators. The PCMCI algorithm sets the maximum time lag according to the duration of each quality stage, sets the significance level of the conditional independence test to 0.05, sets the threshold of conditional dependence strength to 0.2, and combines it with the spatiotemporal quality correlation graph to perform reverse path search, generating risk factor ranking results and quality impact chains.
[0032] Taking a batch of cake products as an example, the finished product moisture content was measured at 25.6%, corresponding to a standardized deviation of 3.84. Risk tracing results showed that the conditional dependence strength of cooling environment humidity at a lag of 27 minutes was 0.43, with a risk contribution of 1.65; the conditional dependence strength of the final baking zone temperature at a lag of 46 minutes was 0.36, with a risk contribution of 1.38; and the conditional dependence strength of raw material moisture content at a lag of 88 minutes was 0.21, with a risk contribution of 0.81. This generated a quality impact chain of "high raw material moisture content—insufficient final baking zone temperature—high cooling environment humidity—abnormal finished product moisture content," and output decisions for quality re-inspection and batch isolation. The re-inspection results were consistent with the risk tracing results.
[0033] To verify the analytical effect of the present invention, the same data were processed using the fixed threshold and correlation tracing method, the original Graphormer and fixed time delay PCMCI method, the method without batch isolation mechanism, the present invention method with fixed time delay, and the complete present invention method. The results are shown in Table 1.
[0034] Table 1. Comparison of anomaly identification and risk traceability results using different food quality analysis methods
[0035] The complete method of this invention correctly identified 30 abnormal batches out of 200 batches of products to be analyzed, outputting a total of 32 abnormal batches. The accuracy rate for abnormal batch identification was 93.8%, and the recall rate was 88.2%. Compared with the fixed threshold and correlation traceability method, the accuracy rate was improved by 22.8 percentage points, the recall rate was improved by 23.5 percentage points, and 8 more abnormal batches were identified out of 34 actual abnormal batches. This indicates that the dynamic quality baseline can adapt to the normal fluctuations of different food categories and quality stages, and reduce false alarms and false negatives caused by fixed thresholds.
[0036] The cross-batch false association rate of the original Graphormer and fixed-delay PCMCI methods was 8.9%, which was reduced to 2.7% by the complete method of this invention. After removing the batch isolation mechanism, the cross-batch false association rate increased to 7.4%, indicating that the batch isolation mechanism can block the transmission of irrelevant features between different product batches. Compared with the complete method of this invention, the hit rate of the top three risk factors using the fixed-delay method increased from 79.4% to 85.3%, indicating that the stage adaptive time delay can limit the causal search range according to the duration of different quality stages, improving the matching degree between the risk factor identification results and the actual production process.
[0037] The average analysis time per batch using the complete method of this invention is 21.4 seconds, which is higher than that of the fixed threshold method, but significantly lower than the average of 42.6 minutes required for manual verification of a single abnormal batch. After re-inspection, batch isolation, and production adjustments were performed based on food quality analysis reports and management decision information, subsequent observations of 60 similar product batches showed that the number of batches with the same quality abnormalities decreased from 8 to 3, demonstrating that this invention can complete the identification of abnormal batches, traceability of risk factors, and prioritization of management and disposal.
[0038] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A food quality analysis method based on big data analysis, characterized in that, Includes the following steps: S1. Collect food quality and management data, aggregate them by product batch, and generate a food quality dataset; S2. Clean the food quality dataset and perform spatiotemporal alignment to generate a standardized quality feature set; S3. Using the product batch as the primary key, associate quality objects and quality events to construct a spatiotemporal quality correlation graph; S4. Input the spatiotemporal quality correlation graph into the improved Graphormer model, use directed path encoding to represent the quality transfer path, and use a batch isolation mechanism to isolate cross-batch interactions to generate a batch quality status representation. S5. Statistically represent the historical batch quality status and construct a dynamic quality baseline. Compare the batch quality status representation with the dynamic quality baseline to generate a set of quality anomaly indicators. S6. Based on the time lag set for the quality stage, the PCMCI algorithm with adaptive time lag set for the stage is used to analyze the causal relationship between the quality anomaly indicators and risk factors. Combined with the spatiotemporal quality correlation diagram, a reverse path search is performed to generate the risk factor ranking results and the quality impact chain. S7. Determine the quality grade, abnormal batches, and handling priority based on the risk factor ranking results and the quality impact chain, and output a food quality analysis report and management decision information.
2. The food quality analysis method based on big data analysis according to claim 1, characterized in that, Specifically, S1 is: Obtain batch registration information from the food enterprise's quality management system, extract the batch number, food category, production task identifier, and formation time, and determine the product batch according to the batch number; Quality data is generated by reading food testing results and processing status records from quality testing systems and production monitoring equipment. Retrieve the business execution records corresponding to the product batch from the food enterprise's quality management system to form management data; Extract the data source, recording time, and food object identifier from the quality data and the management data, and write the extraction results into the corresponding data record to generate food quality and management data; Read the batch number from each piece of food quality and management data and match it with the corresponding product batch; For food quality and management data without recorded batch numbers, the production and operation period corresponding to each product batch is determined based on the batch registration information, and the corresponding product batch is determined by combining the recording time and food object identification. The matched food quality and management data are collected according to the product batches, and the data records within the same product batch are arranged according to the recording time to generate a food quality dataset.
3. The food quality analysis method based on big data analysis according to claim 1, characterized in that, Specifically, S2 is: Obtain the food quality dataset, parse the format of each data record according to the data source and field type, and identify duplicate records, missing fields and fields with abnormal format; Delete duplicate records with identical content, fill in missing fields based on the field values of adjacent records within the same product batch, and convert fields with abnormal formats to the corresponding target format to obtain the cleaned food quality data; Extract the recording time and data generation location from the quality data of the cleaned food, convert the recording time according to a unified time benchmark, and arrange the converted recording times according to the production and operation sequence corresponding to the product batch; The data generation location is mapped to the corresponding quality stage, and each data record is aligned according to the converted recording time and the quality stage to obtain spatiotemporally aligned data; The numerical fields in the spatiotemporal aligned data are subjected to unit unification and normalization, the categorical fields are encoded, and the processed fields are combined according to product batches to generate a standardized quality feature set.
4. The food quality analysis method based on big data analysis according to claim 1, characterized in that, Specifically, S3 is: Obtain the standardized quality feature set and the product batch, extract the batch identifier corresponding to each product batch, and generate a batch node set; Extract the quality object identifier and corresponding attribute field from the standardized quality feature set, merge the attribute fields according to the same quality object identifier, and generate a quality object node set. Quality events are divided according to the operation type and recording time of each data record, and data records that occur consecutively under the same operation type are merged into one quality event to generate a set of quality event nodes. Using the product batch as the primary key, establish batch affiliation edges between the batch node set and the quality object node set and the quality event node set, respectively; Event timing edges are established based on the order in which the quality events occur, and quality transfer edges are established based on the flow relationship of quality objects between adjacent quality stages. Record the time and data generation location and write them into the corresponding nodes and relational edges. Combine the batch node set, the quality object node set, the quality event node set, and each relational edge to construct a spatiotemporal quality correlation graph.
5. The food quality analysis method based on big data analysis according to claim 1, characterized in that, The improved Graphormer model includes a node embedding module, a path encoding module, a batch isolation module, a graph encoding module, and a state output module. The path encoding module is configured with directed path encoding, and the batch isolation module embeds a batch isolation mechanism. The node attributes, node types, and recording times in the spatiotemporal quality correlation graph are input into the node embedding module, and numerical mapping and encoding processes are performed respectively. The corresponding results are concatenated and mapped to a unified dimension through a fully connected layer to generate the initial feature sequence of the nodes. The relationship edge is input into the path encoding module, and the directed path distance and path order between nodes are calculated according to the direction of the relationship edge and the order of quality events. The calculation result is converted into a path feature vector to generate a directed path feature matrix. The product batch and the node initial feature sequence are input into the batch isolation module. A batch graph token is established for each product batch. Each batch graph token is mapped to the unified dimension as a special node and added to the node initial feature sequence. The node is connected to the corresponding batch graph token according to the batch affiliation relationship to generate a batch node group. The batch isolation mechanism sets interaction identifiers for nodes within the same product batch and isolation identifiers for nodes in different product batches, generating a batch isolation matrix. The initial feature sequence of nodes, the directed path feature matrix, and the batch isolation matrix are input into the graph encoding module. The graph encoding module includes a multi-head self-attention layer, a residual normalization layer, and a feedforward network layer. The multi-head self-attention layer maps the initial feature vector of each node into a query vector, a key vector, and a value vector. The query vector and the key vector are multiplied dimension by dimension and accumulated. The accumulated result is then divided by the square root of the vector dimension to obtain the node correlation value. The corresponding path feature vector is input into the linear mapping layer to obtain the path correction value. The path correction value is then added to the node correlation value to obtain the path correction correlation value. Based on the batch isolation matrix, retain the path correction correlation values with interaction identifiers, set the path correction correlation values with isolation identifiers as mask values, normalize the retained path correction correlation values to obtain node interaction coefficients, multiply the node interaction coefficients with the corresponding value vectors dimension by dimension and accumulate them to generate a node aggregation feature sequence. The residual normalization layer adds the node aggregated feature sequence to the node initial feature sequence dimension by dimension and performs normalization. The feedforward network layer performs linear mapping and nonlinear transformation on the normalization result to generate the node encoded feature sequence. The node encoding feature sequence is input into the state output module, average pooling is performed according to the batch node group, batch graph token features are extracted, the average pooling result is concatenated with the batch graph token features and dimension mapping is performed to generate a batch quality state representation.
6. The food quality analysis method based on big data analysis according to claim 5, characterized in that, The batch isolation mechanism is as follows: In the batch isolation module, the batch node group and the initial feature sequence of the node are obtained, the product batch corresponding to each node is read, and a node batch mapping table is established according to the node arrangement order. Select any node from the node batch mapping table as the target node, and compare the product batches corresponding to the target node with the other nodes one by one; When the target node and another node correspond to the same product batch, the association position between the two nodes is set as an interaction identifier, and the other node is added to the set of interaction nodes in the batch corresponding to the target node. When the target node and another node correspond to different product batches, the association position between the two nodes is set as an isolation identifier, and the other node is added to the cross-batch isolation node set corresponding to the target node; Set the association position between each batch of graph tokens and all nodes within the corresponding product batch as an interaction identifier, and set the association position between the batch of graph tokens and nodes within other product batches as an isolation identifier. Write the interaction identifiers and isolation identifiers between each node into a two-dimensional matrix according to the node arrangement order to generate a batch isolation matrix; The batch isolation matrix is matched with the directed path feature matrix according to the node position, the path feature vector corresponding to the interaction identifier is retained, and the position corresponding to the isolation identifier is set as the mask position. When the graph encoding module aggregates node information, it retains the node features corresponding to the set of interactive nodes within the batch, and blocks the node features corresponding to the set of isolated nodes across batches from participating in the feature accumulation of the target node.
7. The food quality analysis method based on big data analysis according to claim 1, characterized in that, Specifically, S5 is: The food category and quality stage corresponding to each product batch are read from the standardized quality feature set, and batches with the same food category and quality stage as the product batch to be analyzed are selected from the historical batch quality status representation to form a historical reference batch set. The historical batch quality status representations in the historical reference batch set are sorted according to the recording time, and a preset number of adjacent historical batch quality status representations are selected to generate a dynamic reference status set. The state values of the same dimension in the dynamic reference state set are accumulated, and the accumulated result is divided by the number of historical batch quality state representations contained in the dynamic reference state set to obtain the state mean of each dimension. Calculate the difference between the quality status representation of each historical batch and the mean status value in the same dimension, and average the absolute value of the difference to obtain the status fluctuation value in each dimension. Replace the status fluctuation value with a value of zero with the preset minimum fluctuation value. The mean values of each dimension and the corresponding state fluctuation values are combined in order of feature dimension to construct a dynamic quality baseline; The batch quality status representation is obtained, and the status value of each dimension is subtracted from the corresponding status mean in the dynamic quality baseline and the absolute value is taken to obtain the status deviation value. Divide each state deviation value by the corresponding state fluctuation value to obtain the standardized deviation sequence. Each standardized deviation value in the standardized deviation sequence is compared with a preset deviation threshold. Feature dimensions exceeding the preset deviation threshold are extracted and mapped according to the correspondence between feature dimensions and quality indicators to generate a set of quality anomaly indicators.
8. The food quality analysis method based on big data analysis according to claim 1, characterized in that, Specifically, S6 is: Obtain the set of quality anomaly indicators, the set of standardized quality features, and the spatiotemporal quality correlation graph. Map each quality anomaly indicator to the corresponding quality object node or quality event node in the spatiotemporal quality correlation graph to generate a set of anomaly indicator nodes. Starting from the nodes in the set of abnormal indicator nodes, upstream nodes are extracted in the opposite direction of the quality transfer edge, and the quality features corresponding to the upstream nodes are identified as risk factors. Arrange the characteristic values corresponding to each quality anomaly indicator and each risk factor according to the recording time, and generate the time series of anomaly indicators and risk factors. Obtain the start and end times of the quality stage corresponding to each risk factor, subtract the start time from the end time to obtain the stage duration, divide the stage duration by the data sampling interval, and round up the resulting quotient to obtain the stage lag order. The PCMCI algorithm sets a stage adaptive time lag, and sets the stage lag order corresponding to each risk factor as the maximum time lag between the risk factor and the quality anomaly index. The time series of the abnormal indicators and the time series of the risk factors are input into the PCMCI algorithm. Lagged variables are selected within the maximum time lag corresponding to each risk factor. The conditional independence test between the lagged variables and the quality abnormal indicators is performed through PC screening. Lagged variables that satisfy the conditional independence relationship are deleted, and a set of candidate parent variables is generated. Perform instantaneous conditional independence test on each candidate parent variable in the candidate parent variable set, calculate the conditional dependency strength between each candidate parent variable and the quality anomaly index, retain candidate parent variables whose conditional dependency strength exceeds a preset dependency threshold, and generate a time-delay causal relationship set. The time-delay causal relationship set is mapped to the spatiotemporal quality correlation graph. Reverse path search is performed starting from each abnormal indicator node. Reverse paths containing the time-delay causal relationship are retained to generate candidate quality impact paths. The risk contribution value is obtained by multiplying the condition dependence strength of each risk factor by the standardized deviation value of the corresponding quality anomaly index. The risk factors are then arranged in descending order of their risk contribution values to generate a risk factor ranking result. The nodes in the candidate quality impact paths are arranged according to the quality stage and time lag, and consecutive paths with the same start and end points are merged to generate a quality impact chain.
9. The food quality analysis method based on big data analysis according to claim 1, characterized in that, Specifically, S7 is: Obtain the set of quality anomaly indicators, the ranking results of the risk factors, and the quality impact chain; determine the product batches corresponding to each quality anomaly indicator, risk factor, and quality impact chain according to the product batches. The number of quality anomaly indicators for each product batch is counted. The position of each risk factor in the risk factor ranking result is read. The total number of risk factors is subtracted from the ranking position and then one is added to obtain the risk ranking value. The risk ranking values for the same product batch are summed to obtain the batch risk ranking value. The number of quality stages included in each quality impact chain is calculated and the number of quality stages for the same product batch is summed to obtain the batch impact stage number. The number of quality anomaly indicators, the batch risk ranking value, and the number of batch impact stages are normalized respectively. The normalization results corresponding to the same product batch are summed to obtain the batch quality risk value. The batch quality risk value is matched with a preset quality level range to determine the quality level corresponding to each product batch, and the product batch with a batch quality risk value exceeding a preset abnormal threshold is determined as an abnormal batch. The abnormal batches are arranged in descending order of their batch quality risk value. When multiple abnormal batches have the same batch quality risk value, they are arranged in descending order of the number of stages of impact of the batches to form a priority for handling. Based on the product batch, compile the corresponding quality grade, quality anomaly index set, risk factor ranking results, quality impact chain and disposal priority to generate a food quality analysis report; Based on the quality level and the disposal priority, corresponding quality re-inspection, batch isolation, or production adjustment operations are matched to generate management decision information.
10. A food quality analysis system based on big data analysis, executing the food quality analysis method based on big data analysis as described in any one of claims 1 to 9, characterized in that, Includes the following modules: The data collection module is used to collect food quality and management data, collect them according to product batches, and generate a food quality dataset. The feature processing module is used to clean the food quality dataset and perform spatiotemporal alignment to generate a standardized quality feature set; The association graph construction module is used to construct a spatiotemporal quality association graph by associating quality objects and quality events with the product batch as the primary key. The state analysis module is used to input the spatiotemporal quality correlation graph into the improved Graphormer model, and perform graph feature processing through directed path encoding and batch isolation mechanism to generate batch quality state representations. The anomaly analysis module is used to statistically represent the quality status of historical batches and construct a dynamic quality baseline, compare the batch quality status representation with the dynamic quality baseline, and generate a set of quality anomaly indicators. The risk tracing module is used to analyze the causal relationship between the quality anomaly indicators and risk factors by setting the time lag according to the quality stage, and to perform reverse path search in combination with the spatiotemporal quality correlation graph to generate risk factor ranking results and quality impact chain. The decision output module is used to determine the quality level, abnormal batches and disposal priority based on the risk factor ranking results and the quality impact chain, and output food quality analysis reports and management decision information.