Auxiliary diet water content prediction method based on artificial intelligence
Through the auxiliary diet moisture prediction method based on artificial intelligence, the neural network parameter optimization algorithm and autoencoder that generates adversarial networks and fusion phenomena principles are solved, and the problems of inlet and exit recording error and measurement efficiency in the existing technology are achieved. More efficient and accurate dietary moisture content prediction.
Patent Information
- Application Number
- CN202411394740.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-08
- Publication Date
- 2025-02-14
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art has errors in recording patient inlet and exit data, and lacks unified measurement methods and equipment, which causes nurses to spend time and effort estimate the water content in their diet.
A method of auxiliary diet moisture content prediction based on artificial intelligence is adopted. By collecting and labeling auxiliary diet data, data augmentation is used to expand the data, and neural network parameter optimization algorithm combined with the principle of fusion phenomenon and autoencoder for feature extraction and dimensionality reduction. , and finally use support vector machine to perform classification prediction.
It reduces the error of inlet and exit recording, saves manpower and time-consuming, and improves work efficiency and data accuracy.
Smart Images

Figure CN119444108A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an artificial intelligence-based auxiliary diet water content prediction method. Background Art
[0002] Liquid is the body fluid part of human substances. It constitutes the internal environment of the human body. Normal body fluid maintains a constant dynamic balance and is a necessary condition for maintaining life activities. Clinically, it is of great significance to record the intake and output of patients with kidney disease, shock, infection, heart disease, ascites due to liver cirrhosis, and after major surgery. The intake and output are of great significance for detecting the body's water balance, evaluating the treatment effect, preventing complications, and providing important reference information for doctors. Accurate recording of intake and output can directly reflect changes in the patient's condition and is an important basis for assisting clinical diagnosis and treatment. However, the workload of clinical nursing is heavy, resulting in most of the intake and output data being provided by patients or their families. At the same time, there is a lack of unified measurement methods and instruments in the clinic. Nurses often estimate the water content in the diet based on their personal past experience, which is time-consuming and labor-intensive, resulting in errors in intake and output records and poor accuracy.
[0003] With the improvement of people's living standards and the increasing attention to health and nutrition, consumers and food producers increasingly need to accurately understand food ingredients to ensure food quality and nutritional balance. Traditional food testing methods often rely on chemical analysis and biochemical methods. Although these methods can provide accurate data, they are usually destructive, and the process is cumbersome, time-consuming and inefficient, and are not suitable for rapid testing of large numbers of samples. Traditional deep learning models are prone to gradient vanishing or exploding problems, which affect the training effect and the practicality of the model. When processing high-dimensional data, the lack of effective dimensionality reduction methods may lead to inefficient model processing. When processing complex or uneven data, the decision boundary adjustment is not flexible enough, affecting the final classification accuracy. Existing data processing methods and machine learning models often show insufficient processing capabilities when facing large-scale and high-dimensional food data, and there are obvious deficiencies in the generalization ability, stability and accuracy of the model. Summary of the invention
[0004] In view of this, the present invention provides an auxiliary dietary water content prediction method based on artificial intelligence, which is used to reduce the error of intake and output records, save manpower and time, and improve work efficiency and data accuracy.
[0005] In a first aspect, the present invention provides an artificial intelligence-based auxiliary diet water content prediction method, the method comprising:
[0006] Step 1: Collect supplementary dietary data, label the supplementary dietary data, and expand the labeled data set to obtain an expanded data set;
[0007] Step 2: Use the expanded data set to train the feature extraction model to obtain the trained feature extraction model and feature-extracted data;
[0008] Step 3: Input the feature-extracted data into the feature dimension reduction model, train the feature dimension reduction model, and obtain the trained feature dimension reduction model and the feature dimension reduction data;
[0009] Step 4: Input the data after feature dimension reduction into the classifier model, train the classifier model, and obtain the trained classifier model;
[0010] Step 5: Use the trained feature extraction model, feature dimension reduction model and classifier model to process new samples and predict their moisture content.
[0011] Optionally, collecting supplementary dietary data and labeling the supplementary dietary data include:
[0012] The water content and other nutrients in food are detected by infrared spectroscopy scanning equipment. Spectral data is obtained by non-invasive scanning of food samples. The obtained data is stored in vector form in the specific format of JSON.
[0013] The marked categories include various levels of moisture content prediction, including Level I moisture content, Level II moisture content, Level III moisture content, Level IV moisture content, and Level V moisture content.
[0014] Optionally, the labeled data is expanded to obtain an expanded data set, including:
[0015] A generative adversarial network based on robustness enhancement is used to generate samples, thereby realizing data expansion; the generative adversarial network based on robustness enhancement consists of two parts: a generator G and a discriminator D; the generator G is used to generate new data close to the real data, and the discriminator D is used to distinguish the generated new data from the real data;
[0016] The training process of the robustness-enhanced generative adversarial network includes:
[0017] S101, initialize the parameters of the generator G and the discriminator D, using random value initialization, the expression is:
[0018]
[0019] In the formula, θ g represents the parameters of the generator, θ d represents the parameters of the discriminator; Indicates that the parameter value is drawn from a normal distribution with a mean of 0 and a standard deviation of 0.01; ~ indicates that the symbol obeys a specific distribution;
[0020] S102. Randomly select samples from the labeled data set, that is, select real data samples, and use them to train the discriminator to distinguish the generated new data from the real data. The expression is:
[0021] x (i) ~p data ;
[0022] In the formula, x (i) represents the selected i-th real data sample; p data Represents the real data distribution;
[0023] S103, inputting the random noise vector and the conditional variable into the generator G to generate a sample of new data, the expression of which is:
[0024]
[0025] In the formula, z (i) represents a random noise vector; p z represents the noise distribution; Represents a sample of generating new data;
[0026] S104, compare the samples of real data and the samples of generated new data through the discriminator, and update its parameters. The goal is to maximize its classification accuracy, which is expressed as:
[0027]
[0028] In the formula, α cf represents the learning rate; Represents the d The gradient of cf Set to 0.01;
[0029] Among them, the gradient The calculation expression is:
[0030]
[0031] In the formula, Represents the gradient effect of real data on the discriminator weights; Represents the gradient effect of the generated new data on the discriminator weights;
[0032] S105. Update the parameters of the generator according to the feedback of the discriminator. The parameters of the generator are updated, and the expression is:
[0033]
[0034] In the formula, Represents the gThe gradient of
[0035] Among them, the gradient The calculation expression is:
[0036]
[0037] gradient Used to reflect the impact of the generator parameters on the possibility of the generated new data being identified as false by the discriminator;
[0038] S106. Calculate and record the loss of each step to monitor the training process and make adjustments. The loss function is calculated as follows:
[0039]
[0040] In the formula, L(θ g ,θ d ) represents the total loss function; λ se Represents the weight of the regular term; Reg(θ g ) represents the regular term applied to the generator, which is used to increase the diversity of generated samples; λ se Set to 0.3;
[0041] Among them, the regular term Reg(θ g ) is calculated as follows:
[0042] Reg(θ g )=β se ∥∥θ g ∥∥ 2 ;
[0043] In the formula, β se is the regularization coefficient, ∥∥θ g ∥∥ 2 is the L2 norm of the generator weight;
[0044] S107, repeating the above steps until a preset stop iteration condition is met, indicating that the training of the generative adversarial network with enhanced robustness is completed.
[0045] Optionally, the step 2 includes:
[0046] A 3-layer fully connected neural network is used for feature extraction. The weights and biases of the fully connected neural network are optimized by simulating the fusion process through a neural network parameter optimization algorithm based on the fusion phenomenon principle.
[0047] The training process of the neural network parameter optimization algorithm based on the fusion phenomenon principle includes:
[0048] S201, define the structure of a fully connected neural network, wherein the 3-layer fully connected neural network includes an input layer and 2 hidden layers, and a preset 1-layer output layer is used for category supervised training, which are defined as follows:
[0049] Input layer, assuming the dimension of the input vector is d, then the input layer has d neurons, corresponding to the d elements in the vector;
[0050] Hidden layer, both hidden layers have 128 neurons, and ReLU is used as the activation function; the output of the feature extraction model is the output of the second hidden layer of the fully connected neural network, that is, the feature vector after feature extraction;
[0051] Output layer: The output layer uses the softmax function as the activation function to supervise the energy state during training;
[0052] Initialize the parameters of the fully connected neural network and assign it a random energy state; assign initial values of the weight w and bias b of the fully connected neural network, and define the energy state E(w,b) to describe the potential optimization ability of the parameters, which is expressed as:
[0053]
[0054] In the formula, x i Represents the input data, y i Represents the corresponding target output, N represents the number of samples in the data set, and K represents the number of feature scales; α k (t) represents the adaptive weight of the k-th scale, which depends on the training time t and the current performance state of the network, ensuring that the focus of the loss function is adjusted at different stages of training;
[0055] Among them, α k (t) is dynamically updated at each iteration, which allows the model to focus on different feature levels at different training stages, thereby more effectively learning the multi-level structure of complex data; specifically, the weight α of each scale k The update of (t) depends on the effect of the current scale under the current training state and the update of the adaptive weight, which is expressed as:
[0056]
[0057] In the formula, E k (t) represents the loss value of the k-th scale at time t, which is calculated by the cross entropy loss function; β k represents the importance adjustment coefficient of the kth scale;
[0058] S202, perform a nuclear synthesis cycle operation, for each pair of parameters, i.e., weights w j and bias bk , perform fusion candidate checks. If the synthesis of two parameters can reduce the overall system energy, fusion is allowed, otherwise it remains independent. Specifically, for each pair of parameters w j and b k An evaluation is made to determine whether the total energy of the system can be reduced through fusion, and the expression is:
[0059] ΔE=E(w j ′ ,b ′ k )-E(w j ,b k );
[0060] And, the fusion behavior of the parameters is expressed as:
[0061] w j ′ =w j +δ tr ;
[0062] b ′ k =b k +∈ tr ;
[0063] In the formula, w j ′ and b ′ k are the updated neural network parameters respectively. If ΔE<Θ(t), the new parameter w is accepted. j j and b ′ k , otherwise keep the original parameters unchanged; Θ(t) is the energy threshold of the current iteration;
[0064] The energy threshold Θ(t) is updated at each iteration. The energy changes during the training process are monitored in real time, and the energy threshold is adjusted dynamically to control the sensitivity and frequency of parameter updates. Specifically, the update rule of the energy threshold is defined, and its expression is:
[0065]
[0066] Where Θ(t) and Θ(t+1) are the energy thresholds for the current and next time steps respectively; ν eo is the learning rate of threshold adjustment, which controls the speed of adjustment; E(t) is the average energy of the current time step; E target is the target energy, which is preset according to the task requirements; σ E is the standard deviation of energy change; tanh is the hyperbolic tangent function; ν eo Set to 0.01, Etarget Set to 0.1;
[0067] Among them, the weight adjustment amount δ tr and bias adjustment ∈ tr The calculation expression is:
[0068]
[0069] In the formula, σ to and η to Sensitivity and scaling factor adjusted for fusion; σ to and η to Set to 0.1 and 0.3 respectively;
[0070] S203, perform energy evaluation on the synthesized parameter set, update the parameter state, and push the parameter group in the high energy state to the low energy state to stabilize the desired state; specifically, re-evaluate the synthesized parameter set through the energy function E to ensure energy minimization, and its expression is:
[0071]
[0072] In the formula, p(y i |x i ; w, b) means that given the input x i With parameters w, b, output y i probability;
[0073] Among them, for logp(y i |x i ; w, b) calculation, its expression is:
[0074]
[0075] In the formula, σ std Indicates the standard deviation of the output data;
[0076] S204. Adjust the nuclear reaction temperature according to the current network performance and stability, simulate the temperature control in physical fusion, and adjust the fusion temperature T, which is expressed as:
[0077] T new =T old ·exp(-α te Δex);
[0078] In the formula, α te is the temperature adjustment factor, T new and T old are the temperatures before and after adjustment, ΔE is the energy change;
[0079] Among them, α teDynamic adjustment based on energy changes is expressed as:
[0080]
[0081] Among them, κ te is a preset adjustment coefficient, |ΔE| is the absolute energy change, E avg is the average value of all current parameter energies;
[0082] S205, detecting whether the energy of the network parameters has reached a dynamic equilibrium state; if the energy of the network parameters has reached a dynamic equilibrium state, continuing the optimization process; if the energy of the network parameters has not reached a dynamic equilibrium state, performing a re-fusion process of the parameters, and the judgment condition expression is:
[0083] Var(E)<∈ mr ;
[0084] Where Var(E) is the variance function of energy E, ∈ mr Set to 10 -5 ;
[0085] S206: Determine whether to update the current parameter configuration according to the energy optimization principle, and the expression is:
[0086]
[0087] b new =b ′ k +β rate Δa;
[0088] In the formula, β rate To update the learning rate, As the fusion adjustment factor, the learning rate β is set to 0.001;
[0089] Among them, the update of weight and bias parameters is updated using momentum terms, and its expression is:
[0090]
[0091] In the formula, μ ea is the momentum coefficient, Δw prev and Δb prev are the weight and bias updates of the previous iteration respectively;
[0092] Among them, the fusion adjustment factor It is dynamically set according to the historical changes of weights and the error rate of the current layer, and its expression is:
[0093]
[0094] In the formula, is the difference between the current weight and the weight of the previous iteration; is the standard deviation of the weight change of the current layer; E l is the error rate of the current layer; ρ yt and λ yt is the adjustment coefficient, which controls the influence intensity of weight change rate and error rate respectively; tanh is the hyperbolic tangent function; ρ yt and λ yt Set to 0.3 and 0.5 respectively;
[0095] S207, after multiple iterations, the parameter energy variation range is determined to determine whether the algorithm converges. If the parameter energy variation range is determined to converge, the final optimized parameters are output; if the parameter energy variation range is determined to converge, the algorithm returns to step 202 to continue iterating; the expression for convergence determination is:
[0096]
[0097] In the formula, E new is the energy state after parameter update, E old is the energy state before parameter update, γ ew is the convergence threshold; the convergence threshold γ ew Set to 10 -6 .
[0098] Optionally, the step 3 includes:
[0099] An autoencoder is used for feature dimensionality reduction, and the autoencoder includes two parts: an encoder and a decoder; the encoder is used to convert high-dimensional feature data into low-dimensional feature data, and the decoder is used to reconstruct the original data from the low-dimensional feature data; the total loss is calculated by using the mean square error based on L2 regularization to avoid overfitting and ensure that the feature dimensionality reduction model can learn effective data compression;
[0100] The training process of the adopted autoencoder includes:
[0101] S301, randomly initialize the weights of the encoder and decoder according to a preset distribution, and the weight pW and bias pb of the autoencoder are randomly initialized using a Gaussian distribution, and the expression is:
[0102]
[0103] Where, pW (l) is the weight of the lth layer; pb (l) is the bias of the lth layer; Indicates that the mean is 0 and the variance is σ 2 Normal distribution; σ is the standard deviation; σ is set to 0.1;
[0104] S302, by means of forward propagation, the input data px is converted into low-dimensional feature data by the encoder, and the low-dimensional feature data is input into the decoder to reconstruct the original data; specifically, the output pz of the encoder and the output reconstructed by the decoder The expressions are:
[0105] pz=Sig(pW enc ·px+pb enc );
[0106]
[0107] In the formula, px is the input data; pz is the output of the encoder, that is, the feature representation; is the decoder reconstructed output; pW enc and pb enc are the weight and bias of the encoder respectively; pW dec and pb dec are the weight and bias of the decoder respectively; Sig(·) is the Sigmoid activation function;
[0108] S303, using the mean square error based on L2 regularization to calculate the total loss, the loss function pL is expressed as:
[0109]
[0110] In the formula, is the reconstruction error term, calculated using the Euclidean distance; λ is the regularization parameter; ∥pW enc ∥ 2 and ∥pW dec ∥ 2 is the L2 regularization term of the weight;
[0111] Among them, the reconstruction error term The calculation expression is:
[0112]
[0113] In the formula, px i is the i-th element of the input data vector px; To reconstruct the data vector The i-th element of ; n is the number of elements in the data vector;
[0114] Among them, the regularization term ∥pW enc ∥ 2 and ∥pW dec ∥ 2 They are expressed as the sum of the squares of all encoder and decoder weights, respectively, and their expressions are:
[0115] ∥pWenc ∥ 2 =∑ j,k (pW enc,jk ) 2 ;
[0116] ∥pW dec ∥ 2 =∑ j,k (pW dec,jk ) 2 ;
[0117] Where, pW enc,jk is the encoder weight matrix pW enc The element in row j and column k in pW dec,jk is the decoder weight matrix pW dec The element at row j and column k in ;
[0118] S304. In the process of back propagation, the network weights are updated by the gradient descent algorithm according to the loss function, and its expression is:
[0119]
[0120] In the formula, α cf is the learning rate; and are the gradients of the loss function with respect to the encoder and decoder weights respectively; α cf The adaptive adjustment method is set, and the initial learning rate is set to 0.01;
[0121] S305, adaptively adjust the learning rate according to the training progress, and use the exponential decay strategy to optimize the learning process, the expression is:
[0122]
[0123] Where e is the base of natural logarithm; γ cfd is the decay rate; t is the number of iterations;
[0124] Among them, the decay rate γ cfd is the rate of change related to time, and its expression is:
[0125]
[0126] In the formula, α initial is the initial learning rate, α initial Set to 0.01; T cf To achieve the specified learning rate α cf The number of iterations required;
[0127] S306, repeat the above steps until the preset stop iteration condition is met, which means that the autoencoder training is completed.
[0128] Optionally, step 4 includes:
[0129] The decision-enhancement-based support vector machine classification algorithm is adopted. The decision-enhancement mechanism is adopted in the traditional support vector machine model, and the reward system is used to adjust the decision boundary according to the accuracy of the classification results, so as to improve the classification performance.
[0130] The training process of the support vector machine classification algorithm based on decision reinforcement includes:
[0131] S401, initialize the classifier model parameters, including the weight and bias of the support vector machine, and the initialization expression is:
[0132]
[0133] In the formula, θ q Represents the parameters of the classifier model; It means that the mean is 0 and the standard deviation is σ q Draw parameter values from a normal distribution of ;
[0134] S402: Rewards are distributed according to the correctness of the classification results. Correctly classified results receive positive rewards, and incorrectly classified results receive negative rewards. This is used in the subsequent reinforcement learning process. The expression of the reward mechanism is:
[0135]
[0136] Where R(qx) is the reward function, which distributes rewards according to the accuracy of classification; y true is the true label; y pred Predict labels for the model; correct classifications receive positive rewards, and incorrect classifications receive negative rewards;
[0137] S403, using the selected kernel function to process the training data, and then classifying it through the support vector machine. After each iteration, the model parameters are adjusted according to the classification results. The expression of the adjustment method is:
[0138]
[0139] Where η q is the learning rate; is the loss function J with respect to parameter θ q The gradient of ; J represents the loss function based on support vector machine; the loss function adopts hinge loss, η q Set to 0.03;
[0140] Among them, the loss function J(θ q ,qx,qy) about the parameter θ q Gradient Calculate, the expression is:
[0141]
[0142] In the formula, qx is the feature vector, qy is the corresponding label, and b q is the bias term; if the classification is correct and the confidence is sufficient, then qy·(qx·θ q +b q )≥1, the gradient is 0; otherwise, the gradient is -qy·qx to promote the parameter θ q Adjust in the direction of correct classification;
[0143] S404, using the collected reward information, optimize the classification boundary through the reinforcement learning algorithm; specifically, adjust the decision boundary of the support vector machine according to the reward and penalty to make the model more robust, and its expression is:
[0144]
[0145] In the formula, λ q is the reinforcement learning step length; R(qx) is the defined reward function; represents the loss function of the discriminator; the loss function of the discriminator adopts hinge loss, λ q Set to 0.55;
[0146] Among them, the loss function The gradient calculation expression is:
[0147]
[0148] In the formula, the numerator qy·qx represents the product of the label and the feature vector to determine the direction of the gradient;
[0149] S405, repeating the above steps until the preset stop iteration condition is met, which means that the training of the decision-enhanced support vector machine classification algorithm is completed.
[0150] Optionally, the prediction method in step 5 includes:
[0151] S501, data collection: a new food sample is scanned by an infrared spectrum scanner to generate spectrum data;
[0152] S502, feature extraction: using the trained feature extraction model to extract key features from the scanned spectral data;
[0153] S503, data dimension reduction: through the trained feature dimension reduction model, high-dimensional feature data is converted into low-dimensional feature data for more efficient subsequent processing; the feature vector is reduced from 100 dimensions to 10 dimensions using an autoencoder;
[0154] S504, classification prediction: input the vector of low-dimensional feature data into the classifier model, and the classifier model performs classification based on a support vector machine to predict the moisture content category of the food. In a second aspect, an embodiment of the present invention provides a computer-readable storage medium, the computer-readable storage medium comprising a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the artificial intelligence-based auxiliary dietary moisture content prediction method in the first aspect or any possible implementation of the first aspect.
[0155] In a third aspect, an embodiment of the present invention provides an electronic device comprising: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and the one or more computer programs include instructions that, when executed by the device, enable the device to execute the artificial intelligence-based auxiliary dietary water content prediction method in the first aspect or any possible implementation of the first aspect.
[0156] In the technical solution provided by the present invention, the method includes collecting supplementary dietary data, labeling the supplementary dietary data, and expanding the labeled data set to obtain an expanded data set; using the expanded data set to train a feature extraction model to obtain a trained feature extraction model and feature-extracted data; inputting the feature-extracted data into a feature dimension reduction model to train the feature dimension reduction model to obtain a trained feature dimension reduction model and feature-extracted data; inputting the feature-reduced data into a classifier model to train the classifier model to obtain a trained classifier model; using the trained feature extraction model, feature dimension reduction model and classifier model to process new samples and predict their moisture content. The method reduces the error of input and output records, saves manpower and time, and improves work efficiency and data accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0157] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0158] Figure 1 A flow chart of a method for predicting water content of a supplementary diet provided by an embodiment of the present invention;
[0159] Figure 2 A training flow chart of a neural network parameter optimization algorithm based on the fusion phenomenon principle provided by an embodiment of the present invention;
[0160] Figure 3 A training flow chart of the autoencoder algorithm provided in an embodiment of the present invention;
[0161] Figure 4 A flow chart for predicting moisture content provided by an embodiment of the present invention;
[0162] Figure 5 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0163] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0164] It should be clear that the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0165] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention are also intended to include plural forms, unless the context clearly indicates other meanings.
[0166] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0167] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0168] Machine learning is a subfield of artificial intelligence (AI) that gives computer systems the ability to learn through experience and improve their performance without being explicitly programmed. This means that machine learning models are able to automatically identify patterns and regularities in data and use this knowledge to make decisions or predictions.
[0169] Data-driven: Machine learning relies on large amounts of data to train models. Data can be labeled (supervised learning), unlabeled (unsupervised learning), or acquired through interaction with the environment (reinforcement learning).
[0170] Model: In machine learning, models are mathematical representations of real-world problems that are able to learn from data. Common models include decision trees, neural networks, support vector machines, etc.
[0171] Learning Algorithms: Learning algorithms define how a model is tuned or "learned." The algorithm is run on the data and optimizes based on how well the model performs, for example, by minimizing the difference between predicted and actual outcomes.
[0172] Figure 1 A flowchart of a method for predicting water content of a supplementary diet provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method includes:
[0173] Step 1: Collect supplementary dietary data, label the supplementary dietary data, and expand the labeled data set to obtain an expanded data set.
[0174] In the embodiment of the present invention, collecting the supplementary diet data and labeling the supplementary diet data include:
[0175] The water content and other nutrients in food are detected by infrared spectroscopy scanning equipment. Spectral data is obtained by non-invasive scanning of food samples. The obtained data is stored in vector form in the specific format of JSON.
[0176] In one embodiment, the attributes of the data include: ax (moisture content): represents the moisture percentage of the food sample; ay (energy value): the caloric content of the food, in calories; az (sodium content): the sodium content in the food, in milligrams; aw (potassium content): the potassium content in the food, in milligrams; av (calcium content): the calcium content in the food, in milligrams; au (phosphorus content): the phosphorus content in the food, in milligrams; at (protein content): the protein content in the food, in grams; as (fat content): the fat content in the food, in grams; ar (carbohydrate content): the carbohydrate content in the food, in grams; aq (cellulose content): the cellulose content in the food, in grams.
[0177] In the embodiment of the present invention, one of the example data is: ax: 84%; ay: 52 calories; az: 1 mg; aw: 107 mg; av: 6 mg; au: 11 mg; at: 0.3 g; as: 0.2 g; ar: 14 g; aq: 2.4 g.
[0178] The collected data are annotated, and the annotating method of the present invention is manual annotating. The annotated categories include various levels of water content prediction, including level I water content, level II water content, level III water content, level IV water content, and level V water content.
[0179] In the embodiment of the present invention, the annotated data is expanded to obtain an expanded data set, including:
[0180] The acquisition, labeling and preprocessing of training data are time-consuming and labor-intensive, and insufficient training samples can easily lead to poor generalization ability of the model, while affecting the accuracy of the model. A robustness-enhanced generative adversarial network is used to generate samples, thereby achieving data expansion; the robustness-enhanced generative adversarial network consists of two parts: a generator G and a discriminator D; the generator G is used to generate new data close to the real data, and the discriminator D is used to distinguish the generated new data from the real data; in view of the mode collapse problem that may occur in the traditional generative adversarial network during the training process, the present invention optimizes the network structure and uses conditional variables to better control the generation process.
[0181] The training process of the robustness-enhanced generative adversarial network includes:
[0182] S101, initialize the parameters of the generator G and the discriminator D, using random value initialization, the expression is:
[0183]
[0184] In the formula, θ g represents the parameters of the generator, θ d represents the parameters of the discriminator; Indicates that the parameter value is drawn from a normal distribution with a mean of 0 and a standard deviation of 0.01; ~ indicates that the symbol obeys a specific distribution;
[0185] S102. Randomly select samples from the labeled data set, that is, select real data samples, and use them to train the discriminator to distinguish the generated new data from the real data. The expression is:
[0186] x (i) ~p data ;
[0187] In the formula, x (i) represents the selected i-th real data sample; p dataRepresents the real data distribution;
[0188] S103, inputting the random noise vector and the conditional variable into the generator G to generate a sample of new data, the expression of which is:
[0189]
[0190] In the formula, z (i) represents a random noise vector; p z represents the noise distribution; Represents a sample of generating new data;
[0191] S104, compare the samples of real data and the samples of generated new data through the discriminator, and update its parameters. The goal is to maximize its classification accuracy, which is expressed as:
[0192]
[0193] In the formula, α cf represents the learning rate; Represents the d The gradient of cf Set to 0.01;
[0194] Among them, the gradient The calculation expression is:
[0195]
[0196] In the formula, Represents the gradient effect of real data on the discriminator weights; Represents the gradient effect of the generated new data on the discriminator weights;
[0197] S105. Update the parameters of the generator according to the feedback of the discriminator, and use the innovative loss function to adjust so as to generate data that is more difficult for the discriminator to recognize. Specifically, the parameter update of the generator is expressed as:
[0198]
[0199] In the formula, Represents the g The gradient of
[0200] Among them, the gradient The calculation expression is:
[0201]
[0202] gradient Used to reflect the impact of the generator parameters on the possibility of the generated new data being identified as false by the discriminator;
[0203] S106. Calculate and record the loss of each step to monitor the training process and make adjustments. The loss function is calculated as follows:
[0204]
[0205] In the formula, L(θ g ,θ d ) represents the total loss function; λ se Represents the weight of the regular term; Reg(θ g ) represents the regular term applied to the generator, which is used to increase the diversity of generated samples; λ se Set to 0.3;
[0206] Among them, the regular term Reg(θ g ) is calculated as follows:
[0207] Reg(θ g )=β se ∥∥θ g ∥∥ 2 ;
[0208] In the formula, β se is the regularization coefficient, ∥∥θ g ∥∥ 2 is the L2 norm of the generator weight;
[0209] S107, repeat the above steps until the preset stop iteration condition is met, indicating that the robustness enhanced generative adversarial network training is completed. In one embodiment, the preset stop iteration condition is reaching a preset maximum number of iterations, preferably, the preset maximum number of iterations is set to 1000 times.
[0210] Step 2: Use the expanded data set to train the feature extraction model to obtain the trained feature extraction model and feature extracted data.
[0211] Currently, some solutions use neural networks for feature extraction. In some neural network structures, they may encounter problems such as gradient vanishing, gradient exploding, or falling into local optimal solutions, which will affect the stability of training and the performance of the model.
[0212] The neural network parameter optimization algorithm based on the principle of fusion phenomenon is inspired by the fusion phenomenon in nature. Lighter atomic nuclei merge under high temperature and high pressure to form more stable heavy atomic nuclei, while releasing huge energy. The neural network parameter optimization algorithm based on the principle of fusion phenomenon optimizes the weights and biases of the network by simulating the fusion process. The weights and biases are regarded as atomic nuclei, and their merging and transformation processes are aimed at achieving the optimal state of the loss function. Unlike the traditional optimization algorithm based on gradient descent, the neural network parameter optimization algorithm based on the principle of fusion phenomenon does not rely on gradient information, thus avoiding the problem of gradient disappearance or explosion.
[0213] In the embodiment of the present invention, step 2 includes:
[0214] A 3-layer fully connected neural network is used for feature extraction. The weights and biases of the fully connected neural network are optimized by simulating the fusion process through a neural network parameter optimization algorithm based on the fusion phenomenon principle.
[0215] In the embodiment of the present invention, Figure 2 As shown in FIG. 1 , the training process of the neural network parameter optimization algorithm based on the fusion phenomenon principle includes:
[0216] S201, define the structure of a fully connected neural network, wherein the 3-layer fully connected neural network includes an input layer and 2 hidden layers, and a preset 1-layer output layer is used for category supervised training, which are defined as follows:
[0217] Input layer, assuming the dimension of the input vector is d, then the input layer has d neurons, corresponding to the d elements in the vector;
[0218] Hidden layer, both hidden layers have 128 neurons, and ReLU is used as the activation function; the output of the feature extraction model is the output of the second hidden layer of the fully connected neural network, that is, the feature vector after feature extraction;
[0219] Output layer: The output layer uses the softmax function as the activation function to supervise the energy state during training;
[0220] Initialize the parameters of the fully connected neural network and assign it a random energy state; assign initial values of the weight w and bias b of the fully connected neural network, and define the energy state E(w,b) to describe the potential optimization ability of the parameters, which is expressed as:
[0221]
[0222] In the formula, x i Represents the input data, y i Represents the corresponding target output, N represents the number of samples in the data set, and K represents the number of feature scales; α k(t) represents the adaptive weight of the k-th scale, which depends on the training time t and the current performance state of the network, ensuring that the focus of the loss function is adjusted at different stages of training;
[0223] Among them, α k (t) is dynamically updated at each iteration, which allows the model to focus on different feature levels at different training stages, thereby more effectively learning the multi-level structure of complex data; specifically, the weight α of each scale k The update of (t) depends on the effect of the current scale under the current training state and the update of the adaptive weight, which is expressed as:
[0224]
[0225] In the formula, E k (t) represents the loss value of the k-th scale at time t, which is calculated by the cross entropy loss function; β k It represents the importance adjustment coefficient of the kth scale, which is preset artificially according to the characteristics of the scale. For example, the adjustment coefficients of the 1st, 2nd, and 3rd scales are set to 0.1, 0.05, and 0.3 respectively.
[0226] S202, perform a nuclear synthesis cycle operation, for each pair of parameters, i.e., weights w j and bias b k , perform fusion candidate checks. If the synthesis of two parameters can reduce the overall system energy, fusion is allowed, otherwise it remains independent. Specifically, for each pair of parameters w j and b k An evaluation is made to determine whether the total energy of the system can be reduced through fusion, and the expression is:
[0227] ΔE=E(w j ′ ,b ′ k )-E(w j ,b k );
[0228] And, the fusion behavior of the parameters is expressed as:
[0229] w j ′ =w j +δ tr ;
[0230] b ′ k =b k +∈ tr ;
[0231] In the formula, w j ′ and b′ k are the updated neural network parameters respectively. If ΔE<Θ(t), the new parameter w is accepted. j ′ and b ′ k , otherwise keep the original parameters unchanged; Θ(t) is the energy threshold of the current iteration;
[0232] The energy threshold Θ(t) is updated at each iteration. The energy changes during the training process are monitored in real time, and the energy threshold is adjusted dynamically to control the sensitivity and frequency of parameter updates. Specifically, the update rule of the energy threshold is defined, and its expression is:
[0233]
[0234] Where Θ(t) and Θ(t+1) are the energy thresholds for the current and next time steps respectively; ν eo is the learning rate of threshold adjustment, which controls the speed of adjustment; E(t) is the average energy of the current time step; E target is the target energy, which is preset according to the task requirements; σ E is the standard deviation of energy change; tanh is the hyperbolic tangent function; ν eo Set to 0.01, E target Set to 0.1;
[0235] Among them, the weight adjustment amount δ tr and bias adjustment ∈ tr The calculation expression is:
[0236]
[0237] In the formula, σ to and η to Sensitivity and scaling factor adjusted for fusion; σ to and η to Set to 0.1 and 0.3 respectively;
[0238] S203, perform energy evaluation on the synthesized parameter set, update the parameter state, and push the parameter group in the high energy state to the low energy state to stabilize the desired state; specifically, re-evaluate the synthesized parameter set through the energy function E to ensure energy minimization, and its expression is:
[0239]
[0240] In the formula, p(y i |x i ; w, b) means that given the input x i With parameters w, b, output y iThe probability of
[0241] Among them, for logp(y i |x i ; w, b) calculation, its expression is:
[0242]
[0243] In the formula, σ std Indicates the standard deviation of the output data;
[0244] S204. Adjust the nuclear reaction temperature according to the current network performance and stability, simulate the temperature control in physical fusion, and adjust the fusion temperature T, which is expressed as:
[0245] T new =T old ·exp(-α te Δex);
[0246] In the formula, α te is the temperature adjustment factor, T new and T old are the temperatures before and after adjustment, ΔE is the energy change;
[0247] Among them, α te Dynamic adjustment based on energy changes is expressed as:
[0248]
[0249] Among them, κ te is a preset adjustment coefficient, |ΔE| is the absolute energy change, E avg is the average value of all current parameter energies;
[0250] S205, detecting whether the energy of the network parameters has reached a dynamic equilibrium state; if the energy of the network parameters has reached a dynamic equilibrium state, continuing the optimization process; if the energy of the network parameters has not reached a dynamic equilibrium state, performing a re-fusion process of the parameters, and the judgment condition expression is:
[0251] Var(E)<∈ mr ;
[0252] Where Var(E) is the variance function of energy E, ∈ mr Set to 10 -5 ;
[0253] S206: Determine whether to update the current parameter configuration according to the energy optimization principle, and the expression is:
[0254]
[0255] bnew =b ′ k +β rate Δa;
[0256] In the formula, β rate To update the learning rate, As the fusion adjustment factor, the learning rate β is set to 0.001;
[0257] Among them, the update of weight and bias parameters is updated using momentum terms, and its expression is:
[0258]
[0259] In the formula, μ ea is the momentum coefficient, Δw prev and Δb prev are the weight and bias updates of the previous iteration respectively;
[0260] Among them, the fusion adjustment factor It is dynamically set according to the historical changes of weights and the error rate of the current layer, and its expression is:
[0261]
[0262] In the formula, is the difference between the current weight and the weight of the previous iteration; is the standard deviation of the weight change of the current layer; E l is the error rate of the current layer; ρ yt and λ yt is the adjustment coefficient, which controls the influence intensity of weight change rate and error rate respectively; tanh is the hyperbolic tangent function; ρ yt and λ yt Set to 0.3 and 0.5 respectively;
[0263] S207, after multiple iterations, the parameter energy variation range is determined to determine whether the algorithm converges. If the parameter energy variation range is determined to converge, the final optimized parameters are output; if the parameter energy variation range is determined to converge, the algorithm returns to step 202 to continue iterating; the expression for convergence determination is:
[0264]
[0265] In the formula, E new is the energy state after parameter update, E old is the energy state before parameter update, γ ew is the convergence threshold; the convergence threshold γ ew Set to 10 -6 .
[0266] Step 3: Input the feature-extracted data into the feature dimension reduction model, train the feature dimension reduction model, and obtain the trained feature dimension reduction model and the feature dimension reduction data.
[0267] In the embodiment of the present invention, step 3 includes:
[0268] An autoencoder is used for feature dimensionality reduction, and the autoencoder includes two parts: an encoder and a decoder; the encoder is used to convert high-dimensional feature data into low-dimensional feature data, and the decoder is used to reconstruct the original data from the low-dimensional feature data; the total loss is calculated by using the mean square error based on L2 regularization to avoid overfitting and ensure that the feature dimensionality reduction model can learn effective data compression;
[0269] In the embodiment of the present invention, Figure 3 As shown, the training process of the autoencoder used includes:
[0270] S301, randomly initialize the weights of the encoder and decoder according to a preset distribution, and the weight pW and bias pb of the autoencoder are randomly initialized using a Gaussian distribution, and the expression is:
[0271]
[0272] Where, pW (l) is the weight of the lth layer; pb (l) is the bias of the lth layer; Indicates that the mean is 0 and the variance is σ 2 Normal distribution; σ is the standard deviation; σ is set to 0.1;
[0273] S302, by means of forward propagation, the input data px is converted into low-dimensional feature data by the encoder, and the low-dimensional feature data is input into the decoder to reconstruct the original data; specifically, the output pz of the encoder and the output reconstructed by the decoder The expressions are:
[0274] pz=Sig(pW enc ·px+pb enc );
[0275]
[0276] In the formula, px is the input data; pz is the output of the encoder, that is, the feature representation; is the decoder reconstructed output; pW enc and pb enc are the weight and bias of the encoder respectively; pW dec and pb dec are the weight and bias of the decoder respectively; Sig(·) is the Sigmoid activation function;
[0277] S303, using the mean square error based on L2 regularization to calculate the total loss, the loss function pL is expressed as:
[0278]
[0279] In the formula, is the reconstruction error term, calculated using the Euclidean distance; λ is the regularization parameter; ∥pW enc ∥ 2 and ∥pW dec ∥ 2 is the L2 regularization term of the weight;
[0280] Among them, the reconstruction error term The calculation expression is:
[0281]
[0282] In the formula, px i is the i-th element of the input data vector px; To reconstruct the data vector The i-th element of ; n is the number of elements in the data vector;
[0283] Among them, the regularization term ∥pW enc ∥ 2 and ∥pW dec ∥ 2 They are expressed as the sum of the squares of all encoder and decoder weights, respectively, and their expressions are:
[0284] ∥pW enc ∥ 2 =∑ j,k (pW enc,jk ) 2 ;
[0285] ∥pW dec ∥ 2 =∑ j,k (pW dec,jk ) 2 ;
[0286] Where, pW enc,jk is the encoder weight matrix pW enc The element in row j and column k in pW dec,jk is the decoder weight matrix pW dec The element at row j and column k in ;
[0287] S304. In the process of back propagation, the network weights are updated by the gradient descent algorithm according to the loss function, and its expression is:
[0288]
[0289] In the formula, α cf is the learning rate; and are the gradients of the loss function with respect to the encoder and decoder weights respectively; α cf The adaptive adjustment method is set, and the initial learning rate is set to 0.01;
[0290] S305, adaptively adjust the learning rate according to the training progress, and use the exponential decay strategy to optimize the learning process, the expression is:
[0291]
[0292] Where e is the base of natural logarithm; γ cfd is the decay rate; t is the number of iterations;
[0293] Among them, the decay rate γ cfd is the rate of change related to time, and its expression is:
[0294]
[0295] In the formula, α initial is the initial learning rate, α initial Set to 0.01; T cf To achieve the specified learning rate α cf The number of iterations required;
[0296] S306, repeat the above steps until the preset stop iteration condition is met, indicating that the autoencoder training is completed. In one embodiment, the preset stop iteration condition is reaching a preset maximum number of iterations, preferably, the preset maximum number of iterations is set to 1000 times.
[0297] Step 4: Input the data after feature dimension reduction into the classifier model, train the classifier model, and obtain the trained classifier model.
[0298] In the embodiment of the present invention, step 4 includes:
[0299] The decision-enhancement-based support vector machine classification algorithm is adopted. The decision-enhancement mechanism is adopted in the traditional support vector machine model, and the reward system is used to adjust the decision boundary according to the accuracy of the classification results, so as to improve the classification performance.
[0300] The training process of the support vector machine classification algorithm based on decision reinforcement includes:
[0301] S401, initialize the classifier model parameters, including the weight and bias of the support vector machine, and the initialization expression is:
[0302]
[0303] In the formula, θ q Represents the parameters of the classifier model; It means that the mean is 0 and the standard deviation is σ q Draw parameter values from a normal distribution of ;
[0304] S402: Rewards are distributed according to the correctness of the classification results. Correctly classified results receive positive rewards, and incorrectly classified results receive negative rewards. This is used in the subsequent reinforcement learning process. The expression of the reward mechanism is:
[0305]
[0306] Where R(qx) is the reward function, which distributes rewards according to the accuracy of classification; y true is the true label; y pred Predict labels for the model; correct classifications receive positive rewards, and incorrect classifications receive negative rewards;
[0307] S403, using the selected kernel function to process the training data, and then classifying it through the support vector machine. After each iteration, the model parameters are adjusted according to the classification results. The expression of the adjustment method is:
[0308]
[0309] Where η q is the learning rate; is the loss function J with respect to parameter θ q The gradient of ; J represents the loss function based on support vector machine; the loss function adopts hinge loss, η q Set to 0.03;
[0310] Among them, the loss function J(θ q ,qx,qy) about the parameter θ q Gradient Calculate, the expression is:
[0311]
[0312] In the formula, qx is the feature vector, qy is the corresponding label, and b q is the bias term; if the classification is correct and the confidence is sufficient, then qy·(qx·θ q +b q )≥1, the gradient is 0; otherwise, the gradient is -qy·qx to promote the parameter θ q Adjust in the direction of correct classification;
[0313] S404, using the collected reward information, optimize the classification boundary through the reinforcement learning algorithm; specifically, adjust the decision boundary of the support vector machine according to the reward and penalty to make the model more robust, and its expression is:
[0314]
[0315] In the formula, λ q is the reinforcement learning step length; R(qx) is the defined reward function; represents the loss function of the discriminator; the loss function of the discriminator adopts hinge loss, λ q Set to 0.55;
[0316] Among them, the loss function The gradient calculation expression is:
[0317]
[0318] In the formula, the numerator qy·qx represents the product of the label and the feature vector to determine the direction of the gradient;
[0319] S405, repeat the above steps until the preset stop iteration condition is met, indicating that the decision-enhanced support vector machine classification algorithm training is completed. In one embodiment, the preset stop iteration condition is reaching a preset maximum number of iterations, preferably, the preset maximum number of iterations is set to 1000 times.
[0320] Step 5: Use the trained feature extraction model, feature dimension reduction model and classifier model to process new samples and predict their moisture content.
[0321] In the embodiment of the present invention, Figure 4 As shown, the prediction methods in step 5 include:
[0322] S501, data collection: a new food sample is scanned by an infrared spectrum scanner to generate spectrum data;
[0323] In the embodiment of the present invention, the spectral data includes but is not limited to spectral data of nutrients such as water, sodium, potassium, etc.
[0324] S502, feature extraction: using the trained feature extraction model to extract key features from the scanned spectral data;
[0325] S503, data dimension reduction: through the trained feature dimension reduction model, high-dimensional feature data is converted into low-dimensional feature data for more efficient subsequent processing; the feature vector is reduced from 100 dimensions to 10 dimensions using an autoencoder;
[0326] S504, classification prediction: input the vector of low-dimensional feature data into the classifier model, and the classifier model performs classification based on the support vector machine to predict the moisture content category of the food.
[0327] Compared with the prior art, the present invention has the following beneficial effects:
[0328] 1. By combining infrared spectroscopy technology with efficient AI algorithms, the accuracy of food water content and nutritional composition prediction is improved.
[0329] 2. Non-destructive testing and rapid data processing capabilities significantly reduce sample processing time and improve testing efficiency.
[0330] 3. The optimization algorithm based on the fusion principle and the robust generative adversarial network structure enhance the stability of network training and reduce the risks in model training.
[0331] 4. Through data expansion and parameter optimization algorithms, the model's predictive ability for new samples is improved, and its application scope on different food types is enhanced.
[0332] In addition, traditional data augmentation techniques such as rotation, flipping, scaling, noise injection, etc. are used. These methods are not as effective as generative adversarial networks on forging process data, but are simpler and easier to implement.
[0333] In order to solve the problem of insufficient data volume, the present invention adopts the robustness-enhanced generative adversarial network technology to generate training samples close to reality, which effectively improves the generalization ability and accuracy of the model; applies the principle of nuclear fusion phenomenon in nature to the parameter optimization of neural network, avoids the problem of gradient disappearance or explosion, and significantly improves the stability and effect of network training; adopts autoencoder to reduce the feature dimension of data, avoids overfitting, ensures that low-dimensional features can effectively represent the original data, and is conducive to improving the accuracy of subsequent classification; adopts decision reinforcement mechanism to optimize the decision boundary of support vector machine, and uses reward system to adjust model parameters according to the accuracy of classification results, thereby improving classification performance.
[0334] Each step of the embodiment of the present invention may be performed by an electronic device, which includes but is not limited to a tablet computer, a portable PC, a desktop computer, etc.
[0335] In the technical solution provided by the present invention, the method includes collecting supplementary dietary data, labeling the supplementary dietary data, and expanding the labeled data set to obtain an expanded data set; using the expanded data set to train a feature extraction model to obtain a trained feature extraction model and feature-extracted data; inputting the feature-extracted data into a feature dimension reduction model to train the feature dimension reduction model to obtain a trained feature dimension reduction model and feature-extracted data; inputting the feature-reduced data into a classifier model to train the classifier model to obtain a trained classifier model; using the trained feature extraction model, feature dimension reduction model and classifier model to process new samples and predict their moisture content. The method reduces the error of input and output records, saves manpower and time, and improves work efficiency and data accuracy.
[0336] An embodiment of the present invention provides a computer-readable storage medium, which includes a stored program, wherein when the program is running, the electronic device where the computer-readable storage medium is located is controlled to execute the above-mentioned embodiment of the artificial intelligence-based auxiliary dietary water content prediction method.
[0337] Figure 5 A schematic diagram of an electronic device provided by an embodiment of the present invention, such as Figure 5 As shown, the electronic device 21 includes: a processor 211, a memory 212, and a computer program 213 stored in the memory 212 and executable on the processor 211. When the computer program 213 is executed by the processor 211, the method for auxiliary dietary water content prediction based on artificial intelligence in the embodiment is implemented. To avoid repetition, they are not described one by one here.
[0338] The electronic device 21 includes, but is not limited to, a processor 211 and a memory 212. Those skilled in the art will appreciate that Figure 5 It is only an example of the electronic device 21 and does not constitute a limitation of the electronic device 21. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.
[0339] The processor 211 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0340] The memory 212 may be an internal storage unit of the electronic device 21, such as a hard disk or memory of the electronic device 21. The memory 212 may also be an external storage device of the electronic device 21, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 21. Further, the memory 212 may also include both an internal storage unit of the electronic device 21 and an external storage device. The memory 212 is used to store computer programs and other programs and data required by network devices. The memory 212 may also be used to temporarily store data that has been output or is to be output.
[0341] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0342] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. An artificial intelligence-based auxiliary diet water content prediction method, characterized in that: The method comprises: Step 1: Collect supplementary dietary data, label the supplementary dietary data, and expand the labeled data set to obtain an expanded data set; Step 2: Use the expanded data set to train the feature extraction model to obtain the trained feature extraction model and feature-extracted data; Step 3: Input the feature-extracted data into the feature dimension reduction model, train the feature dimension reduction model, and obtain the trained feature dimension reduction model and the feature dimension reduction data; Step 4: Input the data after feature dimension reduction into the classifier model, train the classifier model, and obtain the trained classifier model; Step 5: Use the trained feature extraction model, feature dimension reduction model and classifier model to process new samples and predict their moisture content.
2. The method according to claim 1, characterized in that Collect supplementary dietary data and label the supplementary dietary data, including: The water content and other nutrients in food are detected by infrared spectroscopy scanning equipment. Spectral data is obtained by non-invasive scanning of food samples. The obtained data is stored in vector form in the specific format of JSON. The marked categories include various levels of moisture content prediction, including Level I moisture content, Level II moisture content, Level III moisture content, Level IV moisture content, and Level V moisture content.
3. The method according to claim 1, characterized in that The annotated data is expanded to obtain an expanded data set, including: A generative adversarial network based on robustness enhancement is used to generate samples, thereby realizing data expansion; the generative adversarial network based on robustness enhancement consists of two parts: a generator G and a discriminator D; the generator G is used to generate new data close to the real data, and the discriminator D is used to distinguish the generated new data from the real data; The training process of the robustness-enhanced generative adversarial network includes: S101, initialize the parameters of the generator G and the discriminator D, using random value initialization, the expression is: In the formula, θ g represents the parameters of the generator, θ d represents the parameters of the discriminator; Indicates that the parameter value is drawn from a normal distribution with a mean of 0 and a standard deviation of 0.01; ~ indicates that the symbol obeys a specific distribution; S102. Randomly select samples from the labeled data set, that is, select real data samples, and use them to train the discriminator to distinguish the generated new data from the real data. The expression is: x (i) ~p data ; In the formula, x (i) represents the selected i-th real data sample; p data Represents the real data distribution; S103, inputting the random noise vector and the conditional variable into the generator G to generate a sample of new data, the expression of which is: In the formula, z (i) represents a random noise vector; p z represents the noise distribution; Represents a sample of generating new data; S104, compare the samples of real data and the samples of generated new data through the discriminator, and update its parameters. The goal is to maximize its classification accuracy, which is expressed as: In the formula, α cf represents the learning rate; Represents the d The gradient of cf Set to 0.01; Among them, the gradient The calculation expression is: In the formula, Represents the gradient effect of real data on the discriminator weights; Represents the gradient effect of the generated new data on the discriminator weights; S105. Update the parameters of the generator according to the feedback of the discriminator. The parameters of the generator are updated, and the expression is: In the formula, Represents the g The gradient of Among them, the gradient The calculation expression is: gradient Used to reflect the impact of the generator parameters on the possibility of the generated new data being identified as false by the discriminator; S106. Calculate and record the loss of each step to monitor the training process and make adjustments. The loss function is calculated as follows: In the formula, L(θ g ,θ d ) represents the total loss function; λ se Represents the weight of the regular term; Reg(θ g ) represents the regular term applied to the generator to increase the diversity of generated samples; λ se Set to 0.3; Among them, the regular term Reg(θ g ) is calculated as follows: Reg(θ g )=β se ∥∥θ g ∥∥ 2 ; In the formula, β se is the regularization coefficient, ∥∥θ g ∥∥ 2 is the L2 norm of the generator weight; S107, repeating the above steps until a preset stop iteration condition is met, indicating that the training of the generative adversarial network with enhanced robustness is completed.
4. The method according to claim 1, characterized in that: The step 2 comprises: A 3-layer fully connected neural network is used for feature extraction. The weights and biases of the fully connected neural network are optimized by simulating the fusion process through a neural network parameter optimization algorithm based on the fusion phenomenon principle. The training process of the neural network parameter optimization algorithm based on the fusion phenomenon principle includes: S201, define the structure of a fully connected neural network, wherein the three-layer fully connected neural network includes an input layer and two hidden layers, and a preset output layer is used for category supervised training, which are defined as follows: Input layer, assuming the dimension of the input vector is d, then the input layer has d neurons, corresponding to the d elements in the vector; Hidden layer, both hidden layers have 128 neurons, and ReLU is used as the activation function; the output of the feature extraction model is the output of the second hidden layer of the fully connected neural network, that is, the feature vector after feature extraction; Output layer: The output layer uses the softmax function as the activation function to supervise the energy state during training; Initialize the parameters of the fully connected neural network and assign it a random energy state; assign initial values of the weight w and bias b of the fully connected neural network, and define the energy state E(w,b) to describe the potential optimization ability of the parameters, which is expressed as: In the formula, x i Represents input data, y i Represents the corresponding target output, N represents the number of samples in the data set, and K represents the number of feature scales; α k (t) represents the adaptive weight of the k-th scale, which depends on the training time t and the current performance state of the network, ensuring that the focus of the loss function is adjusted at different stages of training; Among them, α k (t) is dynamically updated at each iteration, which allows the model to focus on different feature levels at different training stages, thereby more effectively learning the multi-level structure of complex data; specifically, the weight α of each scale k The update of (t) depends on the effect of the current scale under the current training state and the update of the adaptive weight, which is expressed as: In the formula, E k (t) represents the loss value of the k-th scale at time t, which is calculated by the cross entropy loss function; β k represents the importance adjustment coefficient of the kth scale; S202, perform a kernel synthesis cycle operation, for each pair of parameters, i.e., weights w j and bias b k , perform fusion candidate checks. If the synthesis of two parameters can reduce the overall system energy, fusion is allowed, otherwise it remains independent. Specifically, for each pair of parameters w j and b k An evaluation is made to determine whether the total energy of the system can be reduced through fusion, and the expression is: ΔE=E(w′ j ,b′ k )-E(w j ,b k ); And, the fusion behavior of the parameters is expressed as: w′ j =w j +δ tr ; b′ k =b k +∈ tr ; Where w′ j and b′ k are the updated neural network parameters respectively. If ΔE<Θ(t), the new parameter w′ is accepted. j and b′ k , otherwise keep the original parameters unchanged; Θ(t) is the energy threshold of the current iteration; The energy threshold Θ(t) is updated at each iteration. The energy changes during the training process are monitored in real time, and the energy threshold is adjusted dynamically to control the sensitivity and frequency of parameter updates. Specifically, the update rule of the energy threshold is defined, and its expression is: Where Θ(t) and Θ(t+1) are the energy thresholds for the current and next time steps respectively; ν eo is the learning rate of threshold adjustment, which controls the speed of adjustment; E(t) is the average energy of the current time step; E target is the target energy, which is preset according to the task requirements; σ E is the standard deviation of energy change; tanh is the hyperbolic tangent function; ν eo Set to 0.01, E target Set to 0.1; Among them, the weight adjustment amount δ tr and bias adjustment ∈ tr The calculation expression is: In the formula, σ to and η to Sensitivity and scaling factor adjusted for fusion; σ to and η to Set to 0.1 and 0.3 respectively; S203, perform energy evaluation on the synthesized parameter set, update the parameter state, and push the parameter group in the high energy state to the low energy state to stabilize the desired state; specifically, re-evaluate the synthesized parameter set through the energy function E to ensure energy minimization, and its expression is: In the formula, p(y i |x i ; w, b) means that given the input x i With parameters w, b, output y i probability; Among them, for logp(y i |x i ; w, b) calculation, its expression is: In the formula, σ std Indicates the standard deviation of the output data; S204. Adjust the nuclear reaction temperature according to the current network performance and stability, simulate the temperature control in physical fusion, and adjust the fusion temperature T, which is expressed as: T new =T old ·exp(-α te Δex); In the formula, α te is the temperature adjustment factor, T new and T old are the temperatures before and after adjustment, ΔE is the energy change; Among them, α te Dynamic adjustment based on energy changes is expressed as: Among them, κ te is a preset adjustment coefficient, |ΔE| is the absolute energy change, E avg is the average value of all current parameter energies; S205, detecting whether the energy of the network parameters has reached a dynamic equilibrium state; if the energy of the network parameters has reached a dynamic equilibrium state, continuing the optimization process; if the energy of the network parameters has not reached a dynamic equilibrium state, performing a re-fusion process of the parameters, the judgment condition expression is: Var(E)<∈ mr ; Where Var(E) is the variance function of energy E, ∈ mr Set to 10 -5 ; S206: Determine whether to update the current parameter configuration according to the energy optimization principle, and the expression is: b new =b′ k +β rate Δa; In the formula, β rate To update the learning rate, As the fusion adjustment factor, the learning rate β is set to 0.001; Among them, the update of weight and bias parameters is updated using momentum terms, and its expression is: In the formula, μ ea is the momentum coefficient, Δw prev and Δb prev are the weight and bias updates of the previous iteration respectively; Among them, the fusion adjustment factor It is dynamically set according to the historical changes of weights and the error rate of the current layer, and its expression is: In the formula, is the difference between the current weight and the weight of the previous iteration; is the standard deviation of the weight change of the current layer; E l is the error rate of the current layer; ρ yt and λ yt is the adjustment coefficient, which controls the influence intensity of weight change rate and error rate respectively; tanh is the hyperbolic tangent function; ρ yt and λ yt Set to 0.3 and 0.5 respectively; S207, after multiple iterations, the parameter energy variation range is determined to determine whether the algorithm converges. If the parameter energy variation range is determined to converge, the final optimized parameters are output; if the parameter energy variation range is determined to converge, the algorithm returns to step 202 to continue iterating; the expression for convergence determination is: In the formula, E new is the energy state after parameter update, E old is the energy state before parameter update, γ ew is the convergence threshold; the convergence threshold γ ew Set to 10 -6 .
5. The method according to claim 1, characterized in that: The step 3 comprises: An autoencoder is used for feature dimensionality reduction, and the autoencoder includes two parts: an encoder and a decoder; the encoder is used to convert high-dimensional feature data into low-dimensional feature data, and the decoder is used to reconstruct the original data from the low-dimensional feature data; the total loss is calculated by using the mean square error based on L2 regularization to avoid overfitting and ensure that the feature dimensionality reduction model can learn effective data compression; The training process of the adopted autoencoder includes: S301, randomly initialize the weights of the encoder and decoder according to a preset distribution, and the weight pW and bias pb of the autoencoder are randomly initialized using a Gaussian distribution, and the expression is: Where, pW (l) is the weight of the lth layer; pb (l) is the bias of the lth layer; Indicates that the mean is 0 and the variance is σ 2 Normal distribution; σ is the standard deviation; σ is set to 0.1; S302, by means of forward propagation, the input data px is converted into low-dimensional feature data by the encoder, and the low-dimensional feature data is input into the decoder to reconstruct the original data; specifically, the output pz of the encoder and the output reconstructed by the decoder The expressions are: pz=Sig(pW enc ·px+pb enc ); In the formula, px is the input data; pz is the output of the encoder, that is, the feature representation; is the decoder reconstructed output; pW enc and pb enc are the weight and bias of the encoder respectively; pW dec and pb dec are the weight and bias of the decoder respectively; Sig(·) is the Sigmoid activation function; S303, using the mean square error based on L2 regularization to calculate the total loss, the loss function pL is expressed as: In the formula, is the reconstruction error term, calculated using the Euclidean distance; λ is the regularization parameter; ∥pW enc ∥ 2 and ∥pW dec ∥ 2 is the L2 regularization term of the weight; Among them, the reconstruction error term The calculation expression is: In the formula, px i is the i-th element of the input data vector px; To reconstruct the data vector The i-th element of ; n is the number of elements in the data vector; Among them, the regularization term ||pW enc || 2 and ||pW dec || 2 They are expressed as the sum of the squares of all encoder and decoder weights, respectively, and their expressions are: ||pW enc || 2 =∑ j,k (pW enc,jk ) 2 ; ||pW dec || 2 =∑ j,k (pW dec,jk ) 2 ; Where, pW enc,jk is the encoder weight matrix pW enc The element in row j and column k in pW dec,jk is the decoder weight matrix pW dec The element at row j and column k in ; S304. In the process of back propagation, the network weights are updated by the gradient descent algorithm according to the loss function, and its expression is: In the formula, α cf is the learning rate; and are the gradients of the loss function with respect to the encoder and decoder weights respectively; α cf The adaptive adjustment method is set, and the initial learning rate is set to 0.01; S305, adaptively adjust the learning rate according to the training progress, and use the exponential decay strategy to optimize the learning process, the expression is: Where e is the base of natural logarithm; γ cfd is the decay rate; t is the number of iterations; Among them, the decay rate γ cfd is the rate of change related to time, and its expression is: In the formula, α initial is the initial learning rate, α initial Set to 0.01; T cf To achieve the specified learning rate α cf The number of iterations required; S306, repeat the above steps until the preset stop iteration condition is met, which means that the autoencoder training is completed.
6. The method according to claim 1, characterized in that The step 4 comprises: The decision-enhancement-based support vector machine classification algorithm is adopted. The decision-enhancement mechanism is adopted in the traditional support vector machine model, and the reward system is used to adjust the decision boundary according to the accuracy of the classification results, so as to improve the classification performance. The training process of the support vector machine classification algorithm based on decision reinforcement includes: S401, initialize the classifier model parameters, including the weight and bias of the support vector machine, and the initialization expression is: In the formula, θ q Represents the parameters of the classifier model; It means that the mean is 0 and the standard deviation is σ q Draw parameter values from a normal distribution of ; S402: Rewards are distributed according to the correctness of the classification results. Correctly classified results receive positive rewards, and incorrectly classified results receive negative rewards. This is used in the subsequent reinforcement learning process. The expression of the reward mechanism is: Where R(qx) is the reward function, which distributes rewards according to the accuracy of classification; y true is the true label; y pred Predict labels for the model; correct classifications receive positive rewards, and incorrect classifications receive negative rewards; S403, using the selected kernel function to process the training data, and then classifying it through the support vector machine. After each iteration, the model parameters are adjusted according to the classification results. The expression of the adjustment method is: Where η q is the learning rate; is the loss function J with respect to parameter θ q The gradient of ; J represents the loss function based on support vector machine; the loss function adopts hinge loss, η q Set to 0.03; Among them, the loss function J(θ q ,qx,qy) about the parameter θ q Gradient Calculate, the expression is: In the formula, qx is the feature vector, qy is the corresponding label, and b q is the bias term; if the classification is correct and the confidence is sufficient, then qy·(qx·θ q +b q )≥1, the gradient is 0; otherwise, the gradient is -qy·qx to promote the parameter θ q Adjust in the direction of correct classification; S404, using the collected reward information, optimize the classification boundary through the reinforcement learning algorithm; specifically, adjust the decision boundary of the support vector machine according to the reward and penalty to make the model more robust, and its expression is: In the formula, λ q is the reinforcement learning step length; R(qx) is the defined reward function; L represents the loss function of the discriminator; the loss function of the discriminator adopts hinge loss, λ q Set to 0.55; Among them, the loss function The gradient calculation expression is: In the formula, the numerator qy·qx represents the product of the label and the feature vector to determine the direction of the gradient; S405, repeating the above steps until the preset stop iteration condition is met, which means that the training of the decision-enhanced support vector machine classification algorithm is completed.
7. The method according to claim 1, characterized in that The prediction method in step 5 includes: S501, data collection: a new food sample is scanned by an infrared spectrum scanner to generate spectrum data; S502, feature extraction: using the trained feature extraction model to extract key features from the scanned spectral data; S503, data dimension reduction: through the trained feature dimension reduction model, high-dimensional feature data is converted into low-dimensional feature data for more efficient subsequent processing; the feature vector is reduced from 100 dimensions to 10 dimensions using an autoencoder; S504, classification prediction: input the vector of low-dimensional feature data into the classifier model, and the classifier model performs classification based on the support vector machine to predict the moisture content category of the food.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is running, the computer-readable storage medium is controlled to execute the artificial intelligence-based auxiliary dietary water content prediction method described in any one of claims 1 to 7.
9. An electronic device, characterized in that: include: one or more processors; Memory; And one or more computer programs, wherein the one or more computer programs are stored in the memory, and the one or more computer programs include instructions, which, when executed by the device, enable the device to perform the artificial intelligence-based auxiliary dietary water content prediction method described in any one of claims 1 to 7.