A food safety risk comprehensive prediction and grading evaluation method and system
By processing dairy supply chain data through segmented normalization, wavelet mapping, and dimensionality reduction techniques, combined with modulation gating mechanisms and hierarchical risk classification, the problem of dynamic early warning of food safety risks in the dairy supply chain is solved, achieving efficient risk assessment and fine-grained evaluation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHENGDU BIZ UNITED INFORMATION TECH
- Filing Date
- 2026-03-30
- Publication Date
- 2026-06-19
AI Technical Summary
Existing technologies cannot provide dynamic and forward-looking early warning of food safety risks in the dairy supply chain. Furthermore, the non-stationary temporal characteristics and scale differences of multi-source heterogeneous data result in insufficient model robustness and failure to effectively integrate prior domain knowledge.
Multi-source heterogeneous data is processed using segmented normalization, wavelet mapping, and dimensionality reduction techniques to construct an enhanced feature matrix. Risk perception context and external condition features are then fused through a modulation gating mechanism, and a hierarchical risk classification model is used to conduct risk level probability assessment.
It enables accurate prediction and fine-grained assessment of food safety risks, enhances the model's ability to capture risk evolution mechanisms, provides a logically consistent assessment basis, and avoids the lack of generalization and loss of semantic information in traditional methods.
Smart Images

Figure CN121936929B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of risk comprehensive prediction and classification assessment technology, and in particular to a method and system for comprehensive prediction and classification assessment of food safety risks. Background Technology
[0002] With the continued growth in dairy consumption and the increasing complexity of global supply chains, food safety risk management is facing unprecedented challenges. Traditional risk assessment methods mainly rely on periodic sampling and monitoring rules based on fixed thresholds. These methods are often lagging and cannot achieve dynamic and forward-looking risk warnings throughout the entire supply chain.
[0003] While existing research has attempted to apply machine learning models to analyze food safety data, significant limitations generally exist. Firstly, multi-source, heterogeneous data collected directly from the dairy supply chain exhibits typical non-stationary time-series characteristics, with large scale variations and susceptibility to local outliers, making it difficult to construct robust feature representations using conventional data preprocessing methods. Secondly, most models fail to effectively integrate prior domain knowledge, such as key environmental factors influencing microbial growth and their dynamic action patterns, resulting in insufficient capture of the intrinsic mechanisms of risk evolution. Summary of the Invention
[0004] This application provides a method and system for comprehensive prediction and classification assessment of food safety risks to address the problems of existing solutions.
[0005] Firstly, this application provides a method for comprehensive prediction and grading assessment of food safety risks, the method comprising:
[0006] Collect multi-source heterogeneous raw data from each preset link in the food supply chain; perform segmented normalization on the raw data to obtain normalized values; perform wavelet mapping and dimensionality reduction on the normalized values to obtain dimensionality-reduced feature matrices.
[0007] The reduced feature matrix is averaged over the time dimension and aggregated into a feature vector, which is then used to calculate the Laplace score. The enhanced feature matrix is obtained using the Laplace score and the reduced feature matrix.
[0008] The enhanced feature matrix is input into the trained model, and the temporal features in the enhanced feature matrix are weighted and aggregated to obtain the risk perception context vector. Through a modulation gating mechanism, the risk perception context vector and the preset external condition feature vector are fused to obtain the condition perception decision feature vector. The condition perception decision feature vector is then subjected to hierarchical risk classification to obtain the risk level probability vector.
[0009] In one implementation of this application, before inputting the enhanced feature matrix into the trained model, the method further includes:
[0010] Obtain the enhanced feature matrix of the original training data;
[0011] Input the enhanced feature matrix into the initial model to obtain the risk level probability vector of the enhanced feature matrix;
[0012] Calculate the asymmetric weighted cross-entropy loss using the probability distribution of each risk level;
[0013] The standard cross-entropy loss is calculated using the true risk level and predicted risk level of the original training data.
[0014] By utilizing the standard cross-entropy loss, the link reliability factor extracted from the external condition feature vector, the preset link uncertainty amplification coefficient, and the Shannon entropy of the risk level probability vector, a link reliability weighted and confidence regularized composite loss is obtained.
[0015] The total loss is calculated using asymmetric weighted cross-entropy loss, link reliability weighted loss, and confidence regularization composite loss.
[0016] Based on the total loss, a gradient-based optimization algorithm is used to perform backpropagation, calculate the gradient of the total loss function with respect to each trainable parameter of the model, and iteratively update the trainable parameters according to the gradient.
[0017] When the number of iterations exceeds the preset upper limit or meets the preset requirements, the iteration stops and the trained model is obtained.
[0018] In one implementation of this application, the original data is multi-source heterogeneous data, consisting of several attribute data;
[0019] The original data is segmented and normalized to obtain normalized values, specifically including:
[0020] Calculate the median of all data points for the m-th attribute data of the original data within the preset time period to which time step t belongs;
[0021] Determine the interquartile range of all data points for the m-th attribute within the preset time period to which time step t belongs;
[0022] Using the original measurement value, median, interquartile range value, and preset minimum normal number of the m-th attribute data at time step t, normalization calculation is performed to obtain the normalized value.
[0023] In one implementation of this application, wavelet mapping and dimensionality reduction are performed on the normalized values to obtain a dimensionality-reduced feature matrix, specifically including:
[0024] Introduce adaptive weights for each preset time period;
[0025] By using adaptive weights, the normalized time-series normalized values are mapped to the enhanced feature space that integrates local time window frequency domain information to obtain a preset high-dimensional feature matrix.
[0026] The preset high-dimensional feature matrices of all attributes are concatenated along the attribute dimension to obtain the intermediate feature matrix of the current original time.
[0027] Each time step vector in the intermediate feature matrix is collected as an M-dimensional vector. Kernel principal component analysis is performed using the radial basis function kernel to learn the projection matrix from M-dimensional to D-dimensional. This projection is then applied to each time step vector to obtain the dimensionality-reduced feature matrix, where D is less than M.
[0028] In one implementation of this application, the dimensionality-reduced feature matrix is averaged over the time dimension and aggregated into a feature vector, thereby obtaining the Laplacian score, specifically including:
[0029] The reduced feature matrix is averaged over the time dimension and aggregated into a feature vector;
[0030] An adjacency graph model is constructed based on the similarity between time-averaged feature vectors, and the Laplace score of the feature vectors in the graph is calculated for each feature dimension.
[0031] In one implementation of this application, the enhanced feature matrix is obtained using the Laplacian fraction and the dimensionality-reduced feature matrix, specifically including:
[0032] The Laplace score is mapped to importance weights using an exponential decay function, and each dimension of the dimensionality-reduced feature matrix is weighted element-wise to obtain the enhanced feature matrix.
[0033] In one implementation of this application, a condition-aware decision feature vector is obtained by fusing a risk-aware context vector and a preset external condition feature vector through a modulation gating mechanism, specifically including:
[0034] In the formula, Indicates the first The conditional-aware decision feature vector of each sample, with dimension [ ]. It integrates dynamic temporal risks with static background information;
[0035] Indicates the first The external conditional feature vector of each sample has a dimension of . ; Indicates the first The risk perception context vector of each sample has a dimension of . ;
[0036] The dimension of the external condition feature vector;
[0037] Represents the modulation gate vector, with dimension . ;
[0038] This represents the context vector transformation weight matrix used for non-linear paths, with dimensions of . ;
[0039] This represents the external eigenvector transformation weight matrix used for nonlinear paths, with dimension 1. ;
[0040] The bias vector representing the nonlinear path has dimensions of . ;
[0041] This represents the context vector transformation weight matrix used for a linear path, with dimensions of . ;
[0042] This represents the external eigenvector transformation weight matrix used for the linear path, with dimension 1. ;
[0043] This represents a vector whose elements are all 1s, with dimension 1. .
[0044] In one implementation of this application, a hierarchical risk classification is performed on the condition-aware decision feature vector to obtain a risk level probability vector, specifically including:
[0045] Through the formula:
[0046] Obtain the risk level probability vector of the i-th original data. ;
[0047] in, This represents the risk level probability vector of the current raw data, with dimension 1. ;
[0048] The total number of risk levels is a hyperparameter.
[0049] This represents the condition-aware decision feature vector of the original data, with dimension 1. It integrates dynamic temporal risks with static background information;
[0050] Let represent the weight matrix of the first hidden layer, which are trainable parameters with dimension . ;
[0051] This represents the number of neurons in the first hidden layer; it is a hyperparameter with an example value of 128.
[0052] Let $\mathbf{ ... ;
[0053] Represents the activation function of the exponential linear unit;
[0054] The weight matrix of the second hidden layer is a set of trainable parameters with dimension O(n). ;
[0055] The bias vector of the second hidden layer is a trainable parameter with dimension O(n). ;
[0056] This represents the Softmax function.
[0057] Secondly, this application provides a comprehensive food safety risk prediction and grading assessment system, the system comprising:
[0058] The data acquisition module is used to collect multi-source heterogeneous raw data from various preset links in the food supply chain;
[0059] The data preprocessing module is used to perform segmented normalization on the raw data to obtain normalized values;
[0060] The feature engineering module is used to perform wavelet mapping and dimensionality reduction on the normalized values to obtain the dimensionality-reduced feature matrix; the dimensionality-reduced feature matrix is averaged over the time dimension and aggregated into a feature vector, thereby obtaining the Laplace score; using the Laplace score and the dimensionality-reduced feature matrix, the enhanced feature matrix is obtained.
[0061] The model application module is used to input the enhanced feature matrix into the trained model, perform weighted aggregation of the temporal features in the enhanced feature matrix to obtain the risk perception context vector; through a modulation gating mechanism, it fuses the risk perception context vector with the preset external condition feature vector to obtain the condition perception decision feature vector; and performs hierarchical risk classification on the condition perception decision feature vector to obtain the risk level probability vector.
[0062] As can be seen from the above technical solutions, this application has the following advantages:
[0063] Segmented normalization effectively mitigates interference caused by significant differences in data scale across different stages of the supply chain, avoiding excessive smoothing of local outliers by global normalization. This allows non-stationary time-series data to achieve stable representation while maintaining its original dynamic characteristics. Wavelet mapping and dimensionality reduction compress redundant dimensions while preserving key frequency domain information, significantly improving the sparsity and interpretability of the feature space. Furthermore, through time-dimensional averaging and Laplace fraction calculation, an enhanced feature matrix is constructed that combines local neighborhood structure preservation with global discriminative power. This enables the model to adaptively focus on time-series sub-patterns with high discriminative value for risk evolution, thus overcoming the insufficient generalization problem caused by the fragility of feature representation in traditional methods. This process does not rely on manually setting thresholds or assuming data distributions, achieving end-to-end structured transformation from raw data to robust features, providing a high-quality input foundation for subsequent risk perception.
[0064] This application further achieves, for the first time, explicit embedding and dynamic interaction of domain prior knowledge within a food safety prediction framework through weighted aggregation of risk-perception context vectors and conditional fusion of modulation gating mechanisms. The modulation gating mechanism uses preset external condition feature vectors (such as key environmental factors like temperature, humidity, transportation time, and storage period) as control signals to dynamically adjust the contribution weights of the risk-perception context vectors. This enables the model to adaptively adjust its risk assessment logic based on real-time external constraints, thereby accurately capturing the nonlinear and time-varying mechanisms of microbial growth. Furthermore, the hierarchical risk classification structure, through multi-level probability outputs, not only achieves fine-grained risk level classification (e.g., low, medium, high, and extremely high) but also preserves the semantic hierarchy between categories, avoiding the loss of semantic information caused by traditional single-level classification. This design allows the system to intrinsically integrate causal knowledge in the food safety field directly through architectural design without relying on experimental calibration, enhancing the model's ability to model the intrinsic mechanisms of risk evolution and providing traceable and logically consistent assessment criteria for regulatory decisions. Attached Figure Description
[0065] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the description will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0066] Figure 1 This is a flowchart of a comprehensive food safety risk prediction and grading assessment method provided in an embodiment of this application.
[0067] Figure 2 This is a flowchart of raw data acquisition and processing provided in an embodiment of this application.
[0068] Figure 3 This is a flowchart of a food safety risk assessment classification provided in an embodiment of this application.
[0069] Figure 4 This is a schematic diagram of the internal structure of a comprehensive food safety risk prediction and grading assessment system provided in an embodiment of this application. Detailed Implementation
[0070] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0071] Those skilled in the art should understand that the embodiments described below are merely preferred embodiments of this disclosure and do not imply that this disclosure can only be implemented through these preferred embodiments. These preferred embodiments are merely used to explain the technical principles of this disclosure and are not intended to limit the scope of protection of this disclosure. Based on the preferred embodiments provided by this disclosure, all other embodiments obtained by those skilled in the art without creative effort should still fall within the scope of protection of this disclosure.
[0072] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0073] The technical solutions proposed in the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0074] The embodiment provides a method for comprehensive prediction and classification assessment of food safety risks, such as Figure 1 As shown in the embodiments of this application, the method mainly includes the following steps:
[0075] Step 110: Collect multi-source heterogeneous raw data from each preset link in the food supply chain.
[0076] In some embodiments, data acquisition spans multiple key operational stages, including production, warehousing, transportation, and sales, through the deployment of corresponding IoT sensing devices and data recording systems for real-time or timed data collection. For example, in the production stage, sensors are installed at key processing points (such as after pasteurization and on the filling line) to continuously monitor properties of the product and environment, including temperature, relative humidity, pH, conductivity, dissolved oxygen, turbidity, and redox potential. In the warehousing stage, a sensor network is deployed at different shelf locations in cold storage to continuously record ambient temperature, humidity, and carbon dioxide concentration within modified atmosphere packaging. In the transportation stage, portable data loggers with GPS positioning are used to collect real-time data on ambient temperature, humidity, vibration frequency, and some product physicochemical indicators within the vehicle. Simultaneously, throughout the entire distribution process, samples are taken at predetermined time intervals and sent to a laboratory for microbial analysis (such as total bacterial count testing) to obtain key biological indicators directly reflecting the safety status. The sampling frequency of all sensors is uniformly set according to the characteristics of each operational stage; for example, data is recorded once per minute in production and warehousing, and once every five minutes in transportation, thus forming multivariate time series raw data with a unified time step.
[0077] Step 120: Perform segmented normalization on the original data to obtain normalized values.
[0078] It should be noted that the original data is multi-source heterogeneous data, consisting of several attribute data;
[0079] This step can be specifically described as follows:
[0080] Calculate the median of all data points for the m-th attribute data of the original data within the preset time period to which time step t belongs;
[0081] Determine the interquartile range of all data points for the m-th attribute within the preset time period to which time step t belongs;
[0082] Using the original measurement value, median, interquartile range value, and preset minimum normal number of the m-th attribute data at time step t, normalization calculation is performed to obtain the normalized value.
[0083] Step 130: Perform wavelet mapping and dimensionality reduction on the normalized values to obtain the dimensionality-reduced feature matrix; average the dimensionality-reduced feature matrix over the time dimension and aggregate it into an eigenvector to obtain the Laplace score; use the Laplace score and the dimensionality-reduced feature matrix to obtain the enhanced feature matrix.
[0084] Specifically, wavelet mapping and dimensionality reduction are performed on the normalized values to obtain the dimensionality-reduced feature matrix, including:
[0085] Introduce adaptive weights for each preset time period;
[0086] By using adaptive weights, the normalized time-series normalized values are mapped to the enhanced feature space that integrates local time window frequency domain information to obtain a preset high-dimensional feature matrix.
[0087] The preset high-dimensional feature matrices of all attributes are concatenated along the attribute dimension to obtain the intermediate feature matrix of the current original time.
[0088] Each time step vector in the intermediate feature matrix is collected as an M-dimensional vector. Kernel principal component analysis is performed using the radial basis function kernel to learn the projection matrix from M-dimensional to D-dimensional. This projection is then applied to each time step vector to obtain the dimensionality-reduced feature matrix, where D is less than M.
[0089] The process involves averaging the reduced feature matrix over the time dimension to form a feature vector, which is then used to calculate the Laplacian score. This process specifically includes:
[0090] The reduced feature matrix is averaged over the time dimension and aggregated into a feature vector;
[0091] An adjacency graph model is constructed based on the similarity between time-averaged feature vectors, and the Laplace score of the feature vectors in the graph is calculated for each feature dimension.
[0092] The enhanced feature matrix is obtained by using the Laplacian fraction and the dimensionality-reduced feature matrix, specifically including:
[0093] The Laplace score is mapped to importance weights using an exponential decay function, and each dimension of the dimensionality-reduced feature matrix is weighted element-wise to obtain the enhanced feature matrix.
[0094] Step 140: Input the enhanced feature matrix into the trained model, perform weighted aggregation of the temporal features in the enhanced feature matrix to obtain the risk perception context vector; through the modulation gating mechanism, fuse the risk perception context vector with the preset external condition feature vector to obtain the condition perception decision feature vector; perform hierarchical risk classification on the condition perception decision feature vector to obtain the risk level probability vector.
[0095] In some embodiments, the method further includes, before inputting the enhanced feature matrix into the trained model:
[0096] Obtain the enhanced feature matrix of the original training data;
[0097] Input the enhanced feature matrix into the initial model to obtain the risk level probability vector of the enhanced feature matrix;
[0098] Calculate the asymmetric weighted cross-entropy loss using the probability distribution of each risk level;
[0099] The standard cross-entropy loss is calculated using the true risk level and predicted risk level of the original training data.
[0100] By utilizing the standard cross-entropy loss, the link reliability factor extracted from the external condition feature vector, the preset link uncertainty amplification coefficient, and the Shannon entropy of the risk level probability vector, a link reliability weighted and confidence regularized composite loss is obtained.
[0101] The total loss is calculated using asymmetric weighted cross-entropy loss, link reliability weighted loss, and confidence regularization composite loss.
[0102] Based on the total loss, a gradient-based optimization algorithm is used to perform backpropagation, calculate the gradient of the total loss function with respect to each trainable parameter of the model, and iteratively update the trainable parameters according to the gradient.
[0103] When the number of iterations exceeds the preset upper limit or meets the preset requirements, the iteration stops and the trained model is obtained.
[0104] Based on the above description, the complete training process can be summarized as follows:
[0105] S1. Dairy product supply chain data collection and dataset construction:
[0106] It is worth noting that, during the training phase, the following points should be added: Figure 2 As shown, to construct a training and testing dataset suitable for a comprehensive food safety risk prediction and grading assessment system, it is necessary to systematically collect multi-source heterogeneous data covering the entire dairy product supply chain. Data collection spans multiple key operational stages, including production, warehousing, transportation, and sales, through the deployment of corresponding IoT sensing devices and data recording systems for real-time or timed data collection. For example, in the production stage, sensors are installed at key processing points (such as after pasteurization and on the filling line) to continuously monitor properties such as temperature, relative humidity, pH, conductivity, dissolved oxygen, turbidity, and redox potential of the product and environment; in the warehousing stage, a sensor network is deployed at different shelf locations in the cold storage to continuously record ambient temperature, humidity, and carbon dioxide concentration within the modified atmosphere packaging; in the transportation stage, portable data loggers with GPS positioning are used to collect real-time data on ambient temperature, humidity, vibration frequency, and some product physicochemical indicators within the vehicle compartment; simultaneously, throughout the entire distribution process, samples are taken at predetermined time intervals and sent to the laboratory for microbial analysis (such as total bacterial count testing) to obtain key biological indicators directly reflecting the safety status. The sampling frequency of all sensors is uniformly set according to the characteristics of the operation stage. For example, the production and warehousing stages record once per minute, while the transportation stage records once every five minutes, thus forming multivariate time series raw data with a uniform time step. Each sample corresponds to the complete time-series monitoring data of a specific batch of dairy products throughout the entire supply chain process, and the sample's metadata records static information such as its operation stage, production date, and month.
[0107] In one embodiment, the monitored attributes include:
[0108] Monitoring attribute table:
[0109]
[0110] After completing the initial data collection, crucial data annotation is required to generate training data for supervised learning. Annotation is based on a comprehensive review of the final microbiological test report for that batch of products, historical safety incident records of similar products, and expert experience. Food safety assessment experts assign a risk level label to each data sample according to pre-defined risk level classification standards. For example, they might categorize it into three levels: "low risk," "medium risk," and "high risk," corresponding to different degrees of microbial contamination and potential hazard levels. Specifically, "low risk" indicates that all monitored indicators are within safe thresholds, and microbial growth is slow; "medium risk" indicates that some indicators (such as temperature) experience short-term fluctuations, which may accelerate microbial proliferation, but do not immediately exceed the standard; and "high risk" indicates that key indicators (such as total bacterial count) are approaching or exceeding safety limits, or that environmental conditions such as temperature have been in a dangerous range for an extended period, posing a high probability of safety hazard.
[0111] All collected time-series data, corresponding sample metadata, and labeled risk level tags are integrated to construct a structured dataset.
[0112] S2, Normalization and Adaptive Feature Mapping:
[0113] Dairy supply chain data includes multiple attributes such as temperature, humidity, and bacterial count. The dimensions and scales of each attribute data differ at different time steps, and the overall data exhibits non-stationarity and local fluctuations over time. Conventional Z-score normalization methods are sensitive to outliers in the data and fail to fully consider the correlation between attributes and the characteristics of time series data within local time windows. This results in insufficient robustness of the final feature representation and affects the classification performance of subsequent models.
[0114] This invention employs a method combining adaptive piecewise normalization and wavelet feature mapping to eliminate scale differences among multiple attributes, suppress the influence of outliers, and effectively capture the local frequency domain features of time-series data at multiple scales. The specific steps are as follows:
[0115] Adaptive piecewise normalization:
[0116] Based on the time-dynamic clustering results, each attribute sequence is segmented, and then normalization is performed within each time period using robust statistics. This overcomes the problems of global normalization being sensitive to outliers and ignoring local temporal characteristics, and is expressed as follows:
[0117] ,
[0118] In the formula, Indicates the first The first sample The attribute in the first The normalized values of the time steps, after adaptive piecewise normalization, can eliminate scale differences between different attributes and mitigate the impact of local outliers using robust statistics.
[0119] This represents the sample index, used to identify different data samples, with a value range of [value range missing]. , This represents the total number of samples;
[0120] This represents the attribute index, used to identify different monitoring attributes, with a value range of [value range missing]. , This represents the total number of attributes.
[0121] This represents the time step index, used to identify the time point of data acquisition, with a value range of [value range missing]. , This represents the total number of time steps.
[0122] Indicates the first The first sample The attribute in the first The raw measurements at the time step;
[0123] This represents a time-time mapping function, whose output is a time step. The time period index is obtained through a dynamic time clustering algorithm, and its value range is [value range missing]. , This represents the total number of time periods;
[0124] This represents the median of all data points for the m-th attribute within the k(t)-th time interval to which time step t belongs, i.e., the median corresponding to the time interval to which time step t belongs;
[0125] This represents the interquartile range (the difference between the 75th and 25th quantiles) of all data points within the k(t)-th time interval to which the m-th attribute belongs at time step t, i.e., time step. The interquartile range corresponding to the given time period;
[0126] This represents a very small positive integer, added to the denominator to prevent the denominator from being zero, ensuring the stability of numerical calculations. An example value is shown below. .
[0127] In its implementation, dynamic temporal clustering uses the K-means algorithm to cluster the time series of all samples along the time dimension, thereby increasing the total number of time steps. Divided into For each continuous or non-continuous time period, the statistics (median and interquartile range) for each time period are calculated based only on the data within that period, achieving local normalization.
[0128] It should be noted that the median and interquartile range, as robust statistical measures, differ from the mean and standard deviation, which are sensitive to outliers. The median represents the middle value after data is sorted and is not easily affected by extreme values. The interquartile range measures the dispersion of the middle 50% of the data and is also not sensitive to outliers. Using it for normalization can effectively reduce the distortion effect of local outliers on the normalization scale, thereby obtaining a more stable feature representation.
[0129] Wavelet feature mapping:
[0130] To enhance the representational power of time-series features and capture local frequency domain information, a Morlet wavelet basis centered on the time period is used for feature mapping of each normalized attribute sequence. Adaptive weights are assigned to the mapping process based on the stability of the data within the time period, thereby realizing wavelet feature mapping, as shown below:
[0131] ,
[0132] In the formula, Indicates the first The feature mapping function of each attribute is used to map the normalized time series data to the enhanced feature space that integrates the frequency domain information of the local time window. By introducing time period adaptive weights, the feature mapping process can adaptively focus on the local time window where the data is more stable and the signal-to-noise ratio may be higher.
[0133] Indicates a time period index;
[0134] Indicates the first The attribute in the first The adaptive weights for each time period are scalars used to measure the importance of the features contributed by the data in that time period. A larger weight indicates a more prominent contribution of the features in that time period to the overall mapping. The calculation method is expressed as follows: ;
[0135] This represents the Morlet wavelet basis function, used to extract the frequency domain features of local oscillations centered at a specific time point;
[0136] Indicates the index of the time step within the local time window;
[0137] This represents the radius of the time window, i.e., from the current time step. The number of time steps to extend forward and backward is used to define the range of the local time window, for example... ;
[0138] Indicates the first The first sample The attribute in the first Normalized value of time step;
[0139] Indicates the first The time center point of each time period is obtained by calculating the mean value of all time step indices within that time period, and is used to locate the center of the wavelet function.
[0140] Indicates the first The time window width parameter for each time period controls the range of the wavelet function on the time axis. It is preferably set to twice the standard deviation of the time points within that time period (rounded down).
[0141] Indicates the first The attribute in the first The variance of all sample data points within a time period is used to measure the volatility or stability of the data during that time period.
[0142] Represents the natural exponential function;
[0143] The hyperparameter represents the degree to which the control variance affects the weights; examples of possible values are shown below. .
[0144] Dimensionality reduction:
[0145] Kernel principal component analysis (KPCA) is used to reduce the dimensionality of the high-dimensional feature matrix formed by splicing, thereby reducing computational complexity and mitigating the risk of the "curse of dimensionality" while preserving the main nonlinear discriminative information in the data. Specifically,
[0146] All The feature values obtained by the feature mapping function for each attribute are concatenated along the attribute dimension to obtain the intermediate feature matrix of the i-th sample. , dimension ,Right now, The element in the t-th row and m-th column ;
[0147] Then, to further reduce dimensionality and retain key information, the vector at each time step in the intermediate feature matrix of all training samples (i.e., the vector at each time step for each sample) is... (dimensional row vectors) are collected as indivual 3D vectors, using radial basis function kernels for kernel principal component analysis, learn from... Via A dimensional projection matrix is obtained, and then this projection is applied to the vector at each time step for each sample to obtain a dimensionality-reduced feature matrix. For the i-th sample, the implementation is to... Project to 3D space ( ), to obtain the dimensionality-reduced feature matrix of the i-th sample. , dimension To achieve the original Each attribute dimension is projected onto a more discriminative dimensional subspace;
[0148] This indicates the number of feature dimensions retained after dimensionality reduction, which is less than... Hyperparameters.
[0149] S3, Feature Selection and Importance Weighting:
[0150] Dimensionality reduction features may still contain redundant or weakly discriminative feature dimensions. Conventional feature selection based on variance thresholds or mutual information often ignores the inherent temporal dependence of time series data and the correlation of different feature dimensions in the local geometric structure of the sample, resulting in insufficient discriminative power of the selected feature subset in the temporal context.
[0151] This invention employs a feature importance weighting method based on temporal Laplacian scores. By analyzing the local nearest neighbor relationships of samples in the feature space, it dynamically evaluates the ability of each feature dimension to maintain the structure and assigns importance weights accordingly. This suppresses redundant and noisy dimensions and enhances the expression of key discriminative features. The specific steps are as follows:
[0152] Time dimension average:
[0153] The reduced feature matrix of each sample is averaged over the time dimension and aggregated into a sample-level feature vector, represented as:
[0154] ,
[0155] In the formula, Indicates the first Dimensionally reduced feature matrix of each sample The Line, i.e., the first All of them took a step at that time. A row vector composed of feature dimensions;
[0156] Indicates the first The time-averaged feature vector of each sample has a dimension of . It represents the global static features of the sample.
[0157] Calculate the Laplace fraction:
[0158] An adjacency graph model is constructed based on the similarity between time-averaged feature vectors, and the Laplacian score of each feature dimension in the graph is calculated to measure the ability of that dimension to maintain local nearest neighbor relationships, expressed as:
[0159] ,
[0160] In the formula, Indicates the first The Laplace score of each feature dimension is used to quantitatively evaluate the ability of that dimension to preserve the local neighborhood structure of the sample.
[0161] Indicates difference from The sample index;
[0162] Indicates the first Time-averaged feature vector of each sample The d-th element represents the d-th element. The sample at the th The global time average across each feature dimension is calculated as follows: ;
[0163] Indicates the first Dimensionally reduced feature matrix of each sample In the Time step, number Values in each feature dimension;
[0164] Indicates the first Time-averaged feature vector of each sample The d-th element;
[0165] Represents the sample similarity matrix. Represents the sample similarity matrix The element in the i-th row and j-th column represents the sample. With sample The similarity between two samples is such that a higher value indicates that the two samples are closer in the feature space. The calculation method is expressed as follows: ;
[0166] Indicates that all samples are in the first... The global mean across the feature dimensions, used as the i-th feature value for all samples at the i-th feature dimension. The global center on each feature dimension is calculated as follows: ;
[0167] The degree matrix represents the first degree. Line number The elements of the column, i.e., the first element of the degree matrix. The diagonal element is the th element. The sum of similarities between a sample and all other samples is calculated as follows: This is used to measure the importance of the sample in the adjacency graph;
[0168] Indicates the feature dimension index;
[0169] This represents the L2 norm, also known as the Euclidean norm.
[0170] This represents the bandwidth parameter for similarity calculation, which controls the rate at which similarity decreases as Euclidean distance increases. It is preferably set to the median (rounded) of the Euclidean distance between all sample pairs.
[0171] It should be noted that, The smaller the value, the smoother the variation of the sample's value in that dimension within its local nearest neighbor range. In other words, the dimension can better maintain the smoothness of the local structure, and its discriminative importance is higher.
[0172] Calculate importance weights and generate a weighted feature matrix:
[0173] The importance weight of each feature dimension is calculated based on its Laplace score. A smaller Laplace score indicates a more important feature dimension, thus requiring a larger weight. The Laplace scores are mapped to importance weights using an exponential decay function, and each dimension of the reduced feature matrix is weighted element-wise to obtain the enhanced feature matrix, expressed as:
[0174] ,
[0175] In the formula, Indicates the first The enhanced feature matrix of each sample, with dimension [missing information]. The characterization focuses on sample features that highlight key discriminative temporal patterns;
[0176] express A column vector of all 1s, used to expand the dimension of the weighted row vector through a broadcast mechanism;
[0177] This represents the Hadamard product operator, which is an element-wise multiplication operation.
[0178] This represents the scaling parameter, which controls the sensitivity of the Laplace score to the influence of the weights. An example value is shown below. ;
[0179] This indicates that the index will be used as a reference. From 1 to The calculated scalar results are concatenated into A row vector of dimension.
[0180] It should be noted that, The first term represents the The importance weights of each feature dimension are scalars, and their range is within... Within the interval, The smaller The closer The more important this dimension is, the more important it is.
[0181] S4. Construct a food safety risk assessment classification model:
[0182] Food safety risk level assessment needs to comprehensively consider the identification of key risk moments in time-series dynamics, the modulating effects of external environment or operating conditions, and the potential nonlinear and hierarchical decision boundaries between different risk levels. Conventional recurrent neural networks or basic attention mechanisms are usually difficult to model the cumulative effect of risk over time and the complex interaction of external factors, and they also fail to effectively integrate the contribution of time-series risk with static background information.
[0183] like Figure 3 As shown, this invention employs a model that integrates temporal risk attention, external condition modulation, and hierarchical classification, aiming to accurately capture risk evolution patterns and output reliable risk level probabilities. The specific steps are as follows:
[0184] Time-series risk attention aggregation:
[0185] Based on prior knowledge of temperature and humidity in bacterial growth dynamics, a guided attention mechanism is constructed to focus on time steps with high risk potential. The temporal features in the enhanced feature matrix are weighted and aggregated to generate a risk-aware context vector containing key risk information, represented as follows:
[0186] ;
[0187] In the formula, Indicates the first The risk perception context vector of each sample has a dimension of . It is obtained by summing the feature vectors of all time steps based on their importance, and is used to comprehensively characterize the temporal risk pattern of the sample.
[0188] Indicates the first Enhanced feature matrix of each sample In the The row vector corresponding to the time step, i.e., the first... time step 3D feature representation;
[0189] Indicates the first The sample at the th Normalized value of temperature attribute at time step Indicates the first The sample at the th Normalized value of humidity attribute at time step;
[0190] The coefficient representing the contribution of temperature to bacterial growth potential is a trainable scalar parameter. The initial value can be set according to the microbial growth model. An example initial value is 0.1.
[0191] The coefficient representing the contribution of humidity to bacterial growth potential is a trainable scalar parameter. The initial value can be set according to the microbial growth model. An example initial value is 0.05.
[0192] This represents the prior weight scaling factor, which is a trainable scalar parameter used to control the strength of the bacterial growth prior in the attention calculation. An example initial value is 1.0.
[0193] The weight vector parameters of the attention mechanism have dimensions of . , used to map the hidden state to a scalar attention score, is a trainable parameter;
[0194] The weight matrix parameters of the attention mechanism have dimensions of . , is used to linearly transform the feature vector to the hidden space, and is a trainable parameter;
[0195] The bias vector parameters representing the attention mechanism have dimensions of . , are trainable parameters;
[0196] This represents the size of the hidden layer in the attention mechanism; it is a hyperparameter with an example value of 64.
[0197] This represents the hyperbolic tangent activation function, which maps the input to... Interval.
[0198] It should be noted that this attention mechanism integrates data-driven feature importance with risk priors based on domain knowledge, enabling the model to more sensitively identify high-risk periods when microorganisms are prone to rapid proliferation, thereby improving the relevance and interpretability of risk assessment.
[0199] It should also be noted that, inspired by bacterial growth dynamics, bacterial growth rate is related to environmental factors (such as temperature, humidity, pH value, etc.). In food safety, temperature and humidity are key factors affecting bacterial growth. Therefore, a guided attention mechanism is constructed based on the prior knowledge of temperature and humidity in bacterial growth dynamics to focus on time steps with high risk potential.
[0200] External Condition Modulation Fusion:
[0201] By employing feature vectors representing static external conditions of the supply chain, and dynamically fusing temporal risk context and external condition information through a modulation gating mechanism, a condition-aware decision feature vector adapted to complex real-world scenarios is generated, expressed as:
[0202] ;
[0203] In the formula, Indicates the first The conditional-aware decision feature vector of each sample, with dimension [ ]. It integrates dynamic temporal risks with static background information;
[0204] Indicates the first The external conditional feature vector of each sample has a dimension of . ,Include Static features, such as operational stages represented by one-hot encoding and seasonal information represented by sine and cosine encoding. and etc., among which Indicates the month;
[0205] The dimension of the external condition feature vector;
[0206] Represents the modulation gate vector, with dimension . This is used to control the mixing ratio of nonlinear and linear paths, and its calculation method is expressed as follows: ;
[0207] This represents the Sigmoid activation function, which maps the input to... interval;
[0208] The context vector transformation weight matrix used to compute the gating is a trainable parameter with dimension O(n). ;
[0209] The external feature vector transformation weight matrix used to compute the gate is a trainable parameter with dimension O(n). ;
[0210] The bias vector used in calculating the gating is a trainable parameter with dimension . ;
[0211] The context vector transformation weight matrix used for non-linear paths is a trainable parameter with dimension O(n). ;
[0212] The external eigenvector transformation weight matrix used for non-linear paths is a trainable parameter with dimension O(n). ;
[0213] The bias vector representing the non-linear path is a trainable parameter with dimension O(n). ;
[0214] The context vector transformation weight matrix used for the linear path is a trainable parameter with dimension O(n). ;
[0215] The weight matrix representing the transformation of the external feature vectors used for the linear path is a trainable parameter with dimension O(n). ;
[0216] This represents a vector whose elements are all 1s, with dimension 1. .
[0217] In one implementation, the external conditional feature vector extracts static features from the sample metadata. For example, operational stages (such as production, warehousing, and transportation) use one-hot encoding: if there are three classes of operational stages, they are encoded as 3-dimensional vectors, such as production... Seasonal information uses months Sine and cosine codes (values 1 to 12): and This yields a 2-dimensional vector, therefore, The dimension is the total dimension after encoding all static features, for example, in this implementation... .
[0218] It should be noted that the modulation gate vector It can adaptively adjust the feature fusion strategy according to the specific temporal context and external conditions. For example, it tends to retain more original linear information when the conditions are stable, and enhances nonlinear interaction capabilities when the conditions are complex.
[0219] Hierarchical risk classification output:
[0220] A multilayer perceptron structure with two hidden layers is employed, combined with an asymmetric activation function to capture the ordered and complex nonlinear relationships between risk levels. Finally, the probability distribution of samples belonging to each risk level is output through the Softmax function, expressed as:
[0221] ;
[0222] In the formula, Indicates the first The risk level probability vector of each sample has dimension . , The c-th element This represents the probability that a sample belongs to the c-th level.
[0223] The total number of risk levels is a hyperparameter, which can be 3, corresponding to low risk, medium risk, and high risk, respectively.
[0224] 'c' represents the risk level index, and the value of 'c' ranges from 1 to... ;
[0225] Let represent the weight matrix of the first hidden layer, which are trainable parameters with dimension . ;
[0226] This represents the number of neurons in the first hidden layer; it is a hyperparameter with an example value of 128.
[0227] Let $\mathbf{ ... ;
[0228] This represents the exponential linear unit activation function, used to alleviate the vanishing gradient problem and allow negative input values;
[0229] The weight matrix of the second hidden layer is a set of trainable parameters with dimension O(n). ;
[0230] The bias vector of the second hidden layer is a trainable parameter with dimension O(n). ;
[0231] This represents the Softmax function, which is used to normalize a real vector into a probability distribution vector.
[0232] It should be noted that the two-layer hidden structure can learn a hierarchical mapping from features to risk levels, while the exponential linear unit activation function helps the model learn more complex nonlinear patterns and improves its ability to distinguish risk boundaries.
[0233] S5. Define the loss function:
[0234] Food safety risk assessment faces three key challenges in practical applications: the costs of misjudging different risk levels are significantly asymmetrical; data quality and assessment reliability vary across different stages of the supply chain; and models must exercise caution in decision-making when dealing with scenarios with high uncertainty. The standard cross-entropy loss function cannot simultaneously address these challenges.
[0235] This invention integrates asymmetric misjudgment penalty, link reliability weighting, and confidence regularization term to calculate the loss function, guiding the model to be optimized to better meet actual needs. The specific steps are as follows:
[0236] Asymmetric weighted cross-entropy loss:
[0237] To reflect the severe consequences of misclassifying high-risk levels as low-risk levels, a weight matrix based on the severity of the misclassification is constructed to weight the standard cross-entropy loss, thereby imposing an asymmetric penalty during training, as shown below:
[0238] ;
[0239] In the formula, This represents the asymmetric weighted cross-entropy loss, which applies a larger penalty when the true risk level is higher than the predicted level (i.e., high risk is missed), to reflect the serious consequences of misclassifying high risk as low risk in real-world applications, thereby guiding the model to handle high-risk samples more cautiously.
[0240] This represents the total number of samples in a training batch;
[0241] Indicates the first The first true risk level label of the sample Each element is encoded using one-hot encoding. ;
[0242] The model predicts the first The sample belongs to the first The probability of each risk level, i.e., the risk level probability vector. The One element;
[0243] This represents the penalty weight, indicating the true rank of the sample. At that time, it was predicted to be the first The severity of punishment corresponding to each risk level, these weights constitute... matrix , The element in the r-th row and s-th column is defined as ;
[0244] Indicates the first The true risk level index for each sample, with a value range of [value range missing]. ;
[0245] Represents the true rank index, used to define the weight matrix;
[0246] This represents the prediction level index, used to define the weight matrix;
[0247] This represents the asymmetric penalty coefficient, a hyperparameter that controls the intensity of the penalty; an example value is 0.5.
[0248] It should be noted that the penalty weight Ensure only when the true risk level is reached. Higher than the forecast level Additional penalties are imposed at times, with the penalties increasing as the level difference widens, which aligns with the low tolerance for underreporting of high-risk events in actual supervision.
[0249] The combined loss of reliability weighting and confidence regularization:
[0250] To reflect the varying assessment difficulties across different supply chain stages and to encourage models to provide low-confidence predictions for high-uncertainty samples, a composite loss term combining stage weighting and entropy regularization is adopted. This loss term utilizes external condition features to identify stages and measure prediction uncertainty, and is expressed as follows:
[0251] ;
[0252] In the formula, This represents the combined loss of reliability weighting and confidence regularization, used to handle data quality differences and model prediction uncertainties across different supply chain stages.
[0253] Indicates the first The standard cross-entropy loss of each sample, through and Calculated based on the standard cross-entropy loss function;
[0254] Indicates based on the first External condition feature vectors of each sample The extracted reliability factor is a scalar used to amplify the loss weight of high-uncertainty stages. Its calculation method is expressed as follows:
[0255] ;
[0256] This represents the uncertainty amplification factor of the process, which is a hyperparameter used to control the degree to which the uncertainty of the process weights the loss. An example value is 0.3.
[0257] Indicates according to the first External condition feature vectors of each sample The uncertainty index is a scalar value that is preset according to the type of process. For example, the uncertainty index is set to 1.0 for transportation, 0.5 for warehousing, and 0.2 for production.
[0258] This represents the entropy regularization coefficient, a hyperparameter used to control the intensity of the penalty imposed on the prediction entropy of samples with high uncertainty. An example value is 0.1.
[0259] Indicates the first Risk level probability vector of each sample The Shannon entropy, used to measure the uncertainty of a prediction, is calculated as follows: ;
[0260] This represents a logarithmic function, with the default base being the natural constant.
[0261] This indicates an indicator function that outputs 1 when the condition inside the parentheses is true, and 0 otherwise.
[0262] The threshold value representing the reliability factor of a process is a hyperparameter used to activate the entropy regularization term only in processes with high uncertainty. An example value is 1.2.
[0263] It should be noted that for processes with complex external conditions and high data noise, A larger value increases the weight of its cross-entropy loss, forcing the model to focus more on learning these difficult samples. Meanwhile, The term, as an entropy regularization term, encourages the model to output a more uniform probability distribution, i.e., higher entropy, when predicting these highly uncertain samples, to reflect its lack of confidence in decision-making. In practical applications, it can indicate the need for manual review.
[0264] Total loss function calculation:
[0265] The loss function integrates the asymmetric weighted cross-entropy loss with the composite loss of link reliability weighting and confidence regularization to form the final optimization objective, which simultaneously addresses challenges such as asymmetric misjudgment costs, differences in link reliability, and model confidence calibration, and is expressed as:
[0266] ;
[0267] In the formula, It represents the total loss function, and simultaneously addresses the issues of asymmetric costs of misjudgment, differences in reliability at each stage, and model confidence calibration, thereby training a food safety risk assessment model that better meets actual needs.
[0268] The coefficient representing the weight of the balancing loss term is a hyperparameter used to adjust the relative importance between the asymmetric penalty and the link confidence constraint. An example value is 0.8.
[0269] S6. Training of Food Safety Risk Assessment Classification Model:
[0270] After data preprocessing and feature engineering are completed, the training phase of the food safety risk assessment classification model begins. The training process aims to optimize the model parameters so that the model can accurately learn and predict the corresponding food safety risk level from the input enhanced feature matrix and external conditional features.
[0271] At the start of training, all trainable parameters in the model are initialized using a random initialization method, such as sampling from a normal distribution with zero mean and small variance, to ensure sufficient randomness at the starting point of training. Then, the entire training dataset is divided into multiple batches, and training is performed iteratively. In each training iteration, a batch of sample data is sequentially taken from the dataset. This batch contains normalized attribute time-series data, external conditional feature vectors, and true risk level labels for the samples. The batch data is input into the model with the current parameter state. Forward propagation sequentially passes through feature mapping, feature selection weighting, time-series risk attention aggregation, external conditional modulation fusion, and hierarchical classification output, ultimately yielding the risk level probability prediction vectors for all samples in that batch.
[0272] Then, based on the total loss function defined in step S4, the total loss value between the model prediction and the true label is calculated. This total loss function integrates asymmetric misjudgment penalty, link reliability weighting, and confidence regularization, which can effectively guide the direction of model optimization.
[0273] After the loss value is calculated, a gradient-based optimization algorithm, such as adaptive moment estimation, is used for backpropagation. The backpropagation process automatically calculates the gradient of the total loss function with respect to each trainable parameter of the model. The optimization algorithm then updates all parameters based on these gradients, aiming to obtain a lower loss value in the next forward propagation. This process is repeated continuously, and the model parameters are gradually adjusted in each iteration, making its predicted output increasingly closer to the true risk level of the sample.
[0274] The training process is capped by a maximum number of training epochs. Simultaneously, to effectively prevent overfitting and determine the optimal stopping point, a separate validation dataset is used concurrently during training. After a certain number of training iterations or a complete training epoch, predictions are made on the validation set using the current model parameters, and performance metrics such as loss or accuracy are calculated on the validation set.
[0275] The criteria for stopping training are mainly based on monitoring the performance of the validation set: when the loss value on the validation set no longer decreases in multiple consecutive evaluation periods, or when the classification accuracy of the model on the validation set no longer improves, it is considered that the model performance has converged. Continuing training may lead to overfitting of the training data, and training iterations should be stopped in advance.
[0276] The model parameters that perform best on the validation set during the entire training process are saved as the final model after training, and used for subsequent comprehensive prediction and classification assessment of food safety risks.
[0277] S7. Comprehensive Prediction and Grading Assessment of Food Safety Risks:
[0278] Once the food safety risk assessment classification model has been trained and saved, it can be deployed and applied to the actual task of comprehensive prediction and grading assessment of safety risks in the dairy product supply chain.
[0279] For new batches of dairy products requiring evaluation or supply chain links in real-time monitoring, the data acquisition and preprocessing process is first executed in the same manner as in the training phase. Specifically, following the method in step S1, multi-attribute time-series monitoring data generated during the supply chain flow of the evaluation target is collected, and its corresponding external condition feature vectors are extracted. Then, strictly following the process in step S2, adaptive segmentation normalization and wavelet feature mapping are performed on the collected raw time-series monitoring data, followed by dimensionality reduction to obtain a preliminary feature representation. Then, the feature importance weighting method based on time-series Laplacian scores from step S3 is applied to calculate the feature importance weights and generate the enhanced feature matrix for the evaluation sample. At this point, the data of the new sample has been processed into model input with the same format and meaning as the training data.
[0280] Then, the processed enhanced feature matrix and external condition feature vector are input into the trained food safety risk assessment classification model. The model's internal forward propagation logic is triggered: the temporal risk attention module focuses on time-step features with high risk potential based on the learned attention mechanism and prior knowledge of bacterial growth; the external condition modulation and fusion module dynamically integrates temporal risk information with static background; finally, the hierarchical classifier outputs a probability distribution vector for each predefined risk level. This probability distribution vector represents the system's comprehensive prediction of the food safety risk of the sample. The final risk classification assessment decision is made based on this probability vector.
[0281] In practice, the system selects the risk level with the highest probability value as the final assessment level for that batch of dairy products, such as "high risk," "medium risk," or "low risk." Simultaneously, the system can also output a complete probability distribution to reflect the confidence level of the model's prediction. For example, if a sample is classified as "medium risk," but its "high risk" probability is also close, it indicates that the result has some uncertainty and may require manual intervention for secondary verification.
[0282] Based on this, the system constructed by the present invention can realize dynamic and comprehensive risk prediction of the entire dairy product supply chain, and provide intuitive and clear graded assessment results, providing timely and reliable data-driven decision support for food safety supervision and risk intervention.
[0283] Based on the preceding description, this embodiment:
[0284] 1. An adaptive normalization method combining dynamic time segmentation and robust statistics, along with wavelet feature mapping that integrates time-time weights, is adopted to specifically handle scale differences, non-stationarity, local fluctuations, and outlier interference in multi-source heterogeneous time series data, thus constructing a more robust time series feature representation.
[0285] 2. A feature importance weighting method based on temporal Laplacian scores is adopted. By evaluating the role of feature dimensions in preserving the local nearest neighbor structure of samples, weights are assigned, thereby suppressing redundancy and noise and enhancing the expression of key discriminative temporal features.
[0286] 3. A temporal risk attention mechanism that integrates prior knowledge of bacterial growth dynamics is adopted and combined with external condition modulation gating and hierarchical classifiers, enabling the model to actively focus on high-risk periods, dynamically integrate static environmental information, and capture the complex nonlinear and ordered relationships between risk levels.
[0287] 4. Define a composite loss function that integrates asymmetric misjudgment penalty, link reliability weighting, and confidence regularization to guide the model to handle high-risk misjudgments more carefully during training, adapt to data quality differences in different links, and remain cautious in high-uncertainty predictions.
[0288] In addition, this application Figure 4 This application provides a comprehensive food safety risk prediction and grading assessment system. For example... Figure 4 As shown in the embodiments of this application, the system mainly includes:
[0289] Data acquisition module 210 is used to collect multi-source heterogeneous raw data from various preset links in the food supply chain;
[0290] Data preprocessing module 220 is used to perform segmented normalization processing on the raw data to obtain normalized values;
[0291] The feature engineering module 230 is used to perform wavelet mapping and dimensionality reduction on the normalized values to obtain the dimensionality-reduced feature matrix; the dimensionality-reduced feature matrix is averaged in the time dimension and aggregated into a feature vector, thereby obtaining the Laplace score; the enhanced feature matrix is obtained by using the Laplace score and the dimensionality-reduced feature matrix.
[0292] The model application module 240 is used to input the enhanced feature matrix into the trained model, perform weighted aggregation of the temporal features in the enhanced feature matrix to obtain the risk perception context vector; through the modulation gating mechanism, it fuses the risk perception context vector with the preset external condition feature vector to obtain the condition perception decision feature vector; and performs hierarchical risk classification on the condition perception decision feature vector to obtain the risk level probability vector.
[0293] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A comprehensive method for predicting and grading food safety risks, characterized in that, The method includes: Collect multi-source heterogeneous raw data from each pre-defined stage of the food supply chain; The original data is segmented and normalized to obtain normalized values; The normalized values are subjected to wavelet mapping and dimensionality reduction to obtain the dimensionality-reduced feature matrix; the dimensionality-reduced feature matrix is averaged over the time dimension and aggregated into feature vectors, thereby obtaining the Laplace score; the enhanced feature matrix is obtained using the Laplace score and the dimensionality-reduced feature matrix. The enhanced feature matrix is input into the trained model, and a guided attention mechanism is constructed based on the prior knowledge of temperature and humidity in bacterial growth dynamics to focus on time steps with high risk potential. The temporal features in the enhanced feature matrix are weighted and aggregated to obtain the risk perception context vector; the risk perception context vector and the preset external condition feature vector are fused through a modulation gating mechanism to obtain the condition perception decision feature vector, wherein the preset external condition feature vector includes temperature and humidity, transportation time and storage cycle. Hierarchical risk classification is performed on the condition-aware decision feature vector to obtain the risk level probability vector; Before inputting the enhanced feature matrix into the trained model, the following is also included: Obtain the enhanced feature matrix of the original training data; Input the enhanced feature matrix into the initial model to obtain the probability vector of the enhanced feature matrix in the risk level; Calculate the asymmetric weighted cross-entropy loss using the probability distribution of each risk level; The standard cross-entropy loss is calculated using the true risk level and predicted risk level of the original training data. By utilizing the standard cross-entropy loss, the link reliability factor extracted from the external condition feature vector, the preset link uncertainty amplification coefficient, and the Shannon entropy of the risk level probability vector, a link reliability weighted and confidence regularized composite loss is obtained. The total loss is calculated using asymmetric weighted cross-entropy loss, link reliability weighted loss, and confidence regularization composite loss. Based on the total loss, a gradient-based optimization algorithm is used to perform backpropagation, calculate the gradient of the total loss function with respect to each trainable parameter of the model, and iteratively update the trainable parameters according to the gradient. When the number of iterations exceeds the preset upper limit or meets the preset requirements, the iteration stops and the trained model is obtained.
2. The method of integrated food safety risk prediction and ranking assessment according to claim 1, characterized in that, The original data is multi-source heterogeneous data, consisting of several attribute data; The original data is segmented and normalized to obtain normalized values, specifically including: Calculate the median of all data points for the m-th attribute data of the original data within the preset time period to which time step t belongs; Determine the interquartile range of all data points for the m-th attribute within the preset time period to which time step t belongs; Using the original measurement value, median, interquartile range value, and preset minimum normal number of the m-th attribute data at time step t, normalization calculation is performed to obtain the normalized value.
3. The method of claim 1, wherein the method further comprises, The normalized values are subjected to wavelet mapping and dimensionality reduction to obtain the dimensionality-reduced feature matrix, specifically including: Introduce adaptive weights for each preset time period; By using adaptive weights, the normalized time-series normalized values are mapped to the enhanced feature space that integrates local time window frequency domain information to obtain a preset high-dimensional feature matrix. The preset high-dimensional feature matrices of all attributes are concatenated along the attribute dimension to obtain the intermediate feature matrix of the current original time. Each time step vector in the intermediate feature matrix is collected as an M-dimensional vector. Kernel principal component analysis is performed using the radial basis function kernel to learn the projection matrix from M-dimensional to D-dimensional. This projection is then applied to each time step vector to obtain the dimensionality-reduced feature matrix, where D is less than M.
4. The method of claim 1, wherein the method further comprises, The reduced feature matrix is averaged over the time dimension and aggregated into a feature vector, which is then used to calculate the Laplacian score. This process includes: The reduced feature matrix is averaged over the time dimension and aggregated into a feature vector; An adjacency graph model is constructed based on the similarity between time-averaged feature vectors, and the Laplace score of the feature vectors in the graph is calculated for each feature dimension.
5. The method of claim 1, wherein the method further comprises: Using the Laplacian fraction and the reduced-dimensionality feature matrix, the enhanced feature matrix is obtained, specifically including: The Laplace score is mapped to importance weights using an exponential decay function, and each dimension of the dimensionality-reduced feature matrix is weighted element-wise to obtain the enhanced feature matrix.
6. The method of integrated food safety risk prediction and ranking assessment according to claim 1, wherein, By modulating a gating mechanism, the risk perception context vector and the preset external condition feature vector are fused to obtain the condition-aware decision feature vector, which specifically includes: In the formula, Indicates the first The conditional-aware decision feature vector of each sample, with dimension [ ]. It integrates dynamic temporal risks with static background information; Indicates the first The external conditional feature vector of each sample has a dimension of . ; Indicates the first The risk perception context vector of each sample has a dimension of . ; denotes the dimension of the external condition feature vector; denotes the modulation gating vector, of dimension ; denotes the context vector transformation weight matrix for the non-linear path, with dimensions ; denotes the external feature vector transformation weight matrix for the non-linear path, with dimension ; bias vector representing a non-linear path, dimension ; This represents the context vector transformation weight matrix used for a linear path, with dimensions of . ; This represents the external eigenvector transformation weight matrix used for the linear path, with dimension 1. ; represents a vector of all elements with value 1, dimension .
Citation Information
Patent Citations
Food safety risk level prediction method and device and electronic equipment
CN112465264A
Food safety risk prediction method and system
CN115964504A