Soil heavy metal prediction method, device, equipment and storage medium
By analyzing the soil heavy metal sample data set, the hidden layer center point and width vector of the neural network model were determined. Combined with the genetic algorithm to optimize the parameters, the problem of the radial basis function neural network falling into the local minimum was solved, and the accuracy of soil heavy metal prediction was improved.
Patent Information
- Application Number
- CN202210868024.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-22
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2042-07-22
AI Technical Summary
The existing radial basis function neural network is prone to fall into local minimum in soil heavy metal prediction, which causes the parameters to be unable to be updated to the optimal solution and the prediction results are not accurate.
By obtaining a soil heavy metal sample data set and performing sample analysis to obtain the optimal individual, the center point and width vector of the hidden layer of the initial neural network model are determined, an optimized neural network model is generated, and the model parameters are optimized using genetic algorithms and adaptive methods to avoid local optimal solutions.
The prediction accuracy of the neural network model is improved, ensuring that small errors are avoided during the parameter update process and obtaining more accurate prediction results.
Smart Images

Figure CN115376623B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of soil detection technology, and in particular to a soil heavy metal prediction method, device, equipment and storage medium. Background Art
[0002] Determining the specific content of heavy metals in the soil of a specific area has become an indispensable part of controlling soil heavy metal pollution.
[0003] Currently, data prediction is often performed using neural networks. Radial basis function neural networks (RBFNs) have been widely used in data prediction due to their strong nonlinear fitting capabilities. However, current RBFNs suffer from the drawback of being easily trapped in local minima during convergence and unable to escape from the local optimal solution. This prevents the neural network parameters from being updated to the optimal solution, ultimately resulting in low prediction accuracy.
[0004] The above content is only used to assist in understanding the technical solution of the present invention and does not constitute an admission that the above content is prior art. Summary of the Invention
[0005] The main purpose of the present invention is to provide a soil heavy metal prediction method, device, equipment and storage medium, aiming to solve the technical problems in the prior art that the radial basis function neural network cannot jump out of the local optimal solution and the parameters of the radial basis function neural network cannot be updated to the optimal solution, resulting in low accuracy of the prediction results.
[0006] To achieve the above object, the present invention provides a method for predicting heavy metals in soil, comprising the following steps:
[0007] Obtain soil heavy metal sample dataset;
[0008] Performing sample analysis on the soil heavy metal sample data set to obtain the optimal individual;
[0009] Determining the center point of the hidden layer of the initial neural network model, generating a width vector based on the soil heavy metal sample data set, and obtaining an optimized neural network model based on the center point and the width vector;
[0010] Acquire soil heavy metal data to be predicted, and predict the soil heavy metal data to be predicted based on the optimized neural network model to obtain a prediction result.
[0011] Optionally, performing sample analysis on the soil heavy metal sample dataset to obtain the optimal individual includes:
[0012] Performing sample analysis on the soil heavy metal sample data set to obtain characteristic values;
[0013] Initially encoding the characteristic values to obtain parent population individuals;
[0014] Obtaining a transformation factor of the individual in the parent population, and obtaining the fitness of the individual in the parent population according to the transformation factor;
[0015] Determining the cumulative probability of the individual in the parent population according to the fitness of the individual in the parent population;
[0016] Selecting the population individuals according to the cumulative probability, and using the selected population individuals as new parent population individuals;
[0017] The optimal individual is obtained according to the new parent population individuals.
[0018] Optionally, obtaining the optimal individual according to the new parent population individuals includes:
[0019] Obtaining fitness values corresponding to two individuals participating in the crossover, comparing the fitness values corresponding to the two individuals participating in the crossover, and setting the larger fitness value as the crossover fitness value;
[0020] Obtaining a preset crossover probability, a crossover fitness value, and an average fitness value of individuals in the new parent population;
[0021] Obtaining a crossover probability according to the preset crossover probability, the crossover fitness value, and the average fitness value of the individuals in the new parent population;
[0022] A crossover operation is performed on the individuals of the new parent population according to the crossover probability, and when a preset end condition is reached, the optimal individual is obtained.
[0023] Optionally, after selecting the population individuals according to the cumulative probability and using the selected population individuals as new parent population individuals, the method further includes:
[0024] Obtaining fitness values corresponding to two individuals participating in the mutation, comparing the fitness values corresponding to the two individuals participating in the mutation, and setting the larger fitness value as the mutation fitness value;
[0025] Obtaining a preset mutation probability, a mutation fitness value, and an average fitness value of individuals in the new parent population;
[0026] Obtaining a mutation probability according to the preset mutation probability, the mutation fitness value, and the average fitness value of the individuals in the new parent population;
[0027] The mutation operation is performed on the individuals of the new parent population according to the mutation probability, and the optimal individual is obtained when the preset end condition is reached.
[0028] Optionally, determining the center point of the hidden layer of the initial neural network model includes:
[0029] Selecting a target eigenvalue from the eigenvalues of the soil heavy metal sample data set;
[0030] determining the distance between the target eigenvalue and other eigenvalues in the eigenvalues,
[0031] Obtaining a sample density of the eigenvalue according to the distance;
[0032] Determining a cluster center according to the sample density;
[0033] The center point of the hidden layer is obtained according to the cluster center.
[0034] Optionally, generating a width vector according to the soil heavy metal sample dataset includes:
[0035] Obtaining a clustering data set according to the soil heavy metal sample data set and the cluster center;
[0036] Obtaining the number of samples and sample data of the clustering data set;
[0037] Obtaining a distance between the sample data and the cluster center;
[0038] Obtaining the cluster variance of each cluster according to the distance and the number of samples;
[0039] obtaining a scaling factor according to the cluster variance;
[0040] A width vector is obtained according to the scaling factor.
[0041] Optionally, after obtaining the optimized neural network model according to the center point and the width vector, the method further includes:
[0042] Obtaining the current weight of the output layer in the optimized neural network model;
[0043] Obtaining the updated value of the previous iteration, and obtaining the updated weight according to the updated value of the previous iteration, the weight of the output layer and the momentum coefficient;
[0044] Obtaining an updated gradient according to the updated weight;
[0045] Obtaining a cumulative gradient value and a cumulative gradient square according to the updated gradient;
[0046] Obtaining a learning rate based on the accumulated gradient value;
[0047] An updated weight is obtained according to the current weight, the last iterative update value, the updated gradient, and the cumulative gradient square, and the weight of the output layer in the optimized neural network model is updated.
[0048] In addition, to achieve the above-mentioned purpose, the present invention also proposes a soil heavy metal prediction device, which comprises:
[0049] Data acquisition module, used to obtain soil heavy metal sample data set;
[0050] An individual selection module is used to perform sample analysis on the soil heavy metal sample data set to obtain the optimal individual;
[0051] A model optimization module is used to determine the center point of the hidden layer of the initial neural network model, generate a width vector based on the soil heavy metal sample data set, and obtain an optimized neural network model based on the center point and the width vector;
[0052] The data prediction module is used to obtain the soil heavy metal data to be predicted, and predict the soil heavy metal data to be predicted according to the optimized neural network model to obtain a prediction result.
[0053] In addition, to achieve the above-mentioned purpose, the present invention also proposes a soil heavy metal prediction device, which includes: a memory, a processor, and a soil heavy metal prediction program stored on the memory and runnable on the processor, and the soil heavy metal prediction program is configured to implement the steps of the soil heavy metal prediction method described above.
[0054] In addition, to achieve the above-mentioned purpose, the present invention also proposes a storage medium, on which a soil heavy metal prediction program is stored. When the soil heavy metal prediction program is executed by a processor, the steps of the soil heavy metal prediction method described above are implemented.
[0055] The present invention obtains a soil heavy metal sample dataset, performs sample analysis on the soil heavy metal sample dataset, obtains the optimal individual, determines the center point of the hidden layer of the initial neural network model, and generates a width vector based on the soil heavy metal sample dataset. An optimized neural network model is obtained based on the center point and the width vector, and the soil heavy metal data to be predicted is obtained. The soil heavy metal data to be predicted is predicted based on the optimized neural network model to obtain a prediction result. By screening the sample data and using the obtained optimal individual as a training sample for the neural network, it is possible to avoid being unable to jump out of the local optimal solution during the prediction process and to avoid the parameters in the initial neural network model from being unable to update to the optimal solution, thereby ensuring a smaller error when the parameters are updated, and ultimately obtaining a more accurate prediction result. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 It is a structural diagram of a soil heavy metal prediction device in a hardware operating environment involved in an embodiment of the present invention;
[0057] Figure 2 This is a flow chart of the first embodiment of the soil heavy metal prediction method of the present invention;
[0058] Figure 3 Schematic diagram of the overall process of the soil heavy metal prediction method of the present invention;
[0059] Figure 4 This is a flow chart of a second embodiment of the soil heavy metal prediction method of the present invention;
[0060] Figure 5 This is a flow chart of a third embodiment of the soil heavy metal prediction method of the present invention;
[0061] Figure 6 Schematic diagram of radial basis neural network structure;
[0062] Figure 7 This is a flow chart of a fourth embodiment of the soil heavy metal prediction method of the present invention;
[0063] Figure 8 This is a structural block diagram of the first embodiment of the soil heavy metal prediction device of the present invention.
[0064] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION
[0065] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0066] Reference Figure 1 , Figure 1 This is a schematic diagram of the structure of a soil heavy metal prediction device in the hardware operating environment involved in an embodiment of the present invention.
[0067] like Figure 1As shown, the soil heavy metal prediction device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and optionally the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a wireless fidelity (WI-FI) interface). The memory 1005 may be a high-speed random access memory (RAM) memory or a stable non-volatile memory (NVM), such as a disk storage. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0068] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the soil heavy metal prediction device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0069] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a soil heavy metal prediction program.
[0070] exist Figure 1 In the soil heavy metal prediction device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the soil heavy metal prediction device of the present invention can be set in the soil heavy metal prediction device, and the soil heavy metal prediction device calls the soil heavy metal prediction program stored in the memory 1005 through the processor 1001, and executes the soil heavy metal prediction method provided by the embodiment of the present invention.
[0071] The embodiment of the present invention provides a soil heavy metal prediction method, referring to Figure 2 , Figure 2 This is a flow chart of a first embodiment of a soil heavy metal prediction method according to the present invention.
[0072] In this embodiment, the soil heavy metal prediction method includes the following steps:
[0073] Step S10: Obtain a soil heavy metal sample dataset.
[0074] It should be noted that the executor of this embodiment is a soil heavy metal prediction device, wherein the soil heavy metal prediction device has functions such as soil detection, data communication and program running. The soil heavy metal prediction device can be an integrated controller, a control computer, a handheld computer and other devices. Of course, it can also be other devices with similar functions. This embodiment does not make specific restrictions.
[0075] It can be understood that the soil heavy metal sample dataset can be a data set obtained by fixed-point sampling based on information such as crop distribution and soil type; wherein the soil heavy metal sample dataset includes characteristic values such as longitude, latitude, altitude, crop type, and also includes target values such as heavy metal arsenic (As) content.
[0076] In a specific implementation, the soil heavy metal sample dataset can be obtained directly from local storage, or uploaded to a cloud server and then downloaded. This embodiment does not impose any restrictions on this.
[0077] Step S20: performing sample analysis on the soil heavy metal sample dataset to obtain the optimal individual.
[0078] It should be noted that the optimal individual can be an optimized sample data set obtained after performing a decontamination operation on the soil heavy metal sample data set.
[0079] It is understandable that the sample analysis of the soil heavy metal sample data set can be an analysis of the crop distribution and soil type in the soil heavy metal sample data set, or an analysis based on longitude, latitude, altitude, and crop type. This embodiment does not limit this.
[0080] In a specific implementation, the optimal individual obtained by performing sample analysis on the soil heavy metal sample data set can be determined by a mapping relationship between the soil heavy metal data set and the optimal individual, or by a formula for obtaining the optimal individual based on the data in the soil heavy metal data set. This embodiment does not impose any restrictions on this.
[0081] It should be understood that the optimal individual refers to the set of individuals that can make the final result the global optimal solution after multiple iterations of the algorithm.
[0082] In a specific implementation, when a soil heavy metal sample data set is obtained, the data in the soil heavy metal sample data set is preprocessed to obtain preprocessed data, and an adaptive operation is performed on the preprocessed data to determine the optimal individual based on the correspondence between the soil heavy metal data set and the optimal individual.
[0083] Step S30: Determine the center point of the hidden layer of the initial neural network model, generate a width vector based on the soil heavy metal sample data set, and obtain an optimized neural network model based on the center point and the width vector.
[0084] It should be understood that the hidden layer can be a component of the radial basis neural network model, and the center point of the hidden layer refers to the neuron in the hidden layer that implements the actual function in the radial basis neural network algorithm model.
[0085] It can be understood that the width vector may be a concept describing the size of the center point, and serves to limit the range of the center point.
[0086] In a specific implementation, the width vector is generated based on the soil heavy metal sample data set. This can be achieved by distributing the data in the soil heavy metal sample data set, determining the density of the data based on the degree of dispersion of the data and the distance between each data, and determining the width vector based on the distance between the center points. It can also be determined based on the correspondence between the soil heavy metal data set and the width vector. This embodiment does not impose any restrictions on this.
[0087] In a specific implementation, the optimized neural network model is obtained based on the center point and the width vector. The center point of the hidden layer is first determined, and then the width vector is obtained based on the soil heavy metal sample data set. The width range of the center corresponding to the center point is constrained according to the width vector, thereby obtaining the optimized neural network model.
[0088] Step S40: obtaining soil heavy metal data to be predicted, and predicting the soil heavy metal data to be predicted based on the optimized neural network model to obtain a prediction result.
[0089] It should be understood that the soil heavy metal data to be predicted is data used to predict the heavy metal content in the soil. The soil data to be predicted can be directly obtained from local storage or from the cloud, and this embodiment does not impose any restrictions on this.
[0090] In the specific implementation, the obtained soil heavy metal data to be predicted is input into the optimized neural network model, and the prediction result is obtained according to the correspondence between the soil heavy metal data to be predicted contained in the optimized neural network model and the prediction result, and the content of the heavy metal in the soil to be predicted is determined.
[0091] Reference Figure 3 , Figure 3The following is a schematic diagram of the overall process of this embodiment. The collected samples are normalized to obtain population individuals. These individuals are initialized and encoded using a genetic algorithm, and their fitness values are calculated. Selection is performed based on these fitness values, and adaptive crossover, mutation, and simulated annealing are performed. The received data is then determined to be optimal. When the data meets the requirements, it is output as the optimal individual. First, an initial neural network model is determined. A basic neural network model is then determined using the density clustering peak algorithm and the adaptive variance metric. The optimal individual obtained from the previous sample processing is then incorporated into the model. A reverse update is performed to obtain a trained neural network model, and simulation predictions are performed.
[0092] This embodiment obtains a soil heavy metal sample dataset from a local or cloud source, performs sample analysis on the obtained soil heavy metal sample dataset, obtains the optimal individual, determines the center point of the hidden layer in the initial neural network model based on the soil heavy metal sample dataset, determines a width vector based on the soil heavy metal sample dataset, determines the width range of the center corresponding to the center point based on the width vector, obtains an optimized neural network model based on the determined center point width range and the optimal individual, and then inputs the data to be predicted into the optimized neural network model to obtain predicted data. This embodiment obtains a neural network model by determining the center point and vector width of the hidden layer of the initial neural network, then obtains the optimal individual by performing sample analysis on the data of the soil heavy metal sample dataset, inputs the obtained optimal individual into the neural network model, determines the model parameters of the output layer of the neural network model, and obtains an optimized neural network model, thereby improving the accuracy of the neural network model prediction.
[0093] refer to Figure 4 , Figure 4 This is a flow chart of a second embodiment of a soil heavy metal prediction method according to the present invention.
[0094] Based on the first embodiment above, in the soil heavy metal prediction method of this embodiment, step S20 includes:
[0095] Step S201: performing sample analysis on the soil heavy metal sample dataset to obtain characteristic values.
[0096] It should be noted that the eigenvalues are the input values in the soil heavy metal sample data used as model training, including longitude, latitude, altitude, crop type, etc.
[0097] Step S202: Initialize and encode the characteristic values to obtain individuals of the parent population.
[0098] It should be noted that, treating each eigenvalue as an individual of the parent population, encoding the eigenvalue is actually encoding the chromosome of each individual of the parent population.
[0099] It should be noted that the purpose of initializing the chromosome encoding is to convert complex chromosome data into easily processable data. Commonly used encoding methods include real number encoding, floating point encoding, and binary encoding, etc. This embodiment does not impose any restrictions on this.
[0100] In a specific implementation, the chromosomes of the parent population individuals are first normalized. The normalization method can be maximum-minimum normalization, Z-score normalization method, etc. This embodiment does not limit this. The normalized data is initialized and encoded to obtain the parent population individuals. This embodiment uses maximum-minimum normalization as an example to illustrate. The maximum sample value and the minimum sample value in the sample data are selected and calculated according to the formula:
[0101] PN=(PP min ) / (P max -P min )
[0102] Where PN is the result of normalization, P is the original data, and P max With P min are the maximum and minimum values in the original data, respectively.
[0103] Step S203: Obtain the transformation factor of the individual in the parent population, and obtain the fitness of the individual in the parent population according to the transformation factor.
[0104] It should be noted that fitness is a measure used to identify the degree of advantage of individuals in the parent population in the survival of the population, and is used to distinguish between "good" and "bad" individuals.
[0105] It can be understood that the transformation factor is a tool quantity for converting the objective function value into a non-negative value.
[0106] It should be understood that fitness is calculated through the fitness function, which is usually used to convert the objective function into a relative fitness value. The fitness function formula is as follows:
[0107] F(x)=gf(x)
[0108] Where f is the objective function, g is the transformation factor that converts the objective function value into a non-negative value, and F is the resulting relative fitness.
[0109] Step S204: determining the cumulative probability of the parent population individuals according to the fitness of the parent population individuals.
[0110] It should be noted that the cumulative probability refers to the sum of the probability values of all individuals in the population being selected, and the probability of an individual being selected is determined by the individual's fitness. The higher the individual's fitness, the greater the probability of being selected. The formula for calculating the probability of an individual being selected is as follows:
[0111]
[0112] Among them, f(x i ) is represented by individual x i The fitness of the individual is selected with a probability of p(x i ).
[0113] The cumulative probability calculation formula is as follows:
[0114]
[0115] Among them, p(x j ) represents the probability of an individual being selected, q(x i ) represents the cumulative probability.
[0116] Step S205: selecting the population individuals according to the cumulative probability, and using the selected population individuals as new parent population individuals.
[0117] It should be noted that the cumulative probability is used to select the population individuals, and the selected population individuals are used as the new parent population individuals in a manner that can be roulette wheel selection, random competitive selection, best-retained selection, etc., which is not limited in this embodiment. This embodiment uses roulette wheel selection as an example for explanation.
[0118] In the specific implementation, first obtain the fitness corresponding to each chromosome and calculate their total fitness. Then calculate the proportion of each chromosome in the total fitness. The obtained proportion is used as the probability of each individual being selected. For example, there are 5 chromosomes with fitness of 5, 8, 3, 7, and 2 respectively. Then the total fitness is: F = 5 + 8 + 3 + 7 + 2 = 25. Then the probability of each individual being selected is:
[0119] α1=(5 / 25)*100%=20%
[0120] α2 = (8 / 25) * 100% = 32%
[0121] α3 = (3 / 25) * 100% = 12%
[0122] α4 = (7 / 25) * 100% = 28%
[0123] α5=(2 / 25)*100%=8%
[0124] Step S206: Obtain the optimal individual based on the new parent population individuals.
[0125] It should be noted that the new parent population individuals refer to the population individuals selected according to the selection probability of each chromosome. The new population individuals here are not new individuals generated, but are produced after screening based on the original parent population individuals. In essence, they are part of the original parent population.
[0126] Furthermore, in a specific implementation, when selecting the best individual based on the new parent population individuals, in order to make the best individual finally obtained better, step S206 includes:
[0127] Obtaining fitness values corresponding to two individuals participating in the crossover, comparing the fitness values corresponding to the two individuals participating in the crossover, and setting the larger fitness value as the crossover fitness value;
[0128] Obtaining a preset crossover probability, a crossover fitness value, and an average fitness value of individuals in the new parent population;
[0129] Obtaining a crossover probability according to the preset crossover probability, the crossover fitness value, and the average fitness value of the individuals in the new parent population;
[0130] A crossover operation is performed on the individuals of the new parent population according to the crossover probability, and when a preset end condition is reached, the optimal individual is obtained.
[0131] It should be noted that crossover operation refers to exchanging some of the genes of two mutually paired chromosomes by a crossover operator, thereby forming two new individuals. The crossover operator here can be single-point crossover, two-point crossover and multi-point crossover, uniform crossover, arithmetic crossover etc., and the present embodiment does not limit this. In the present embodiment, single-point crossover (One-pointCrossover) is used to illustrate that single-point crossover refers to only randomly setting an intersection in the individual coding string, and then exchanging some of the chromosomes of two paired individuals at this intersection. When carrying out crossover operation, in order to allow the individual with lower fitness to participate in crossover as much as possible, the individual with higher fitness value is maintained at a slightly lower value that is not 0 in crossover probability as much as possible, therefore it is necessary to obtain the fitness value of the individual participating in crossover, and determine the probability of crossover according to the fitness of the two individuals participating in crossover, therefore adopt Sigmoid function to construct the probability adjustment formula of crossover, Sigmoid function formula is as follows:
[0132]
[0133] Will The independent variable x in is replaced by the cosine part to form the composite function as follows:
[0134]
[0135] From the properties of the Sigmoid function, we know that when x≥9.903438, Close to 1; when x≤-9.903438, Close to 0. The value range is in the interval [0, 1], then A = 9.903438.
[0136] Therefore, the adaptive probability adjustment method proposed in this paper is as follows:
[0137]
[0138] Among them, P c is the crossover probability, ranging from 0.5 to 0.9, P cmax is the maximum crossover rate, P cmin is the minimum crossover rate, f′ is the larger fitness value of the two individuals participating in the crossover operation, and f avg is the average fitness value of the entire population.
[0139] In order to make the optimal individual finally obtained better, step S206 includes:
[0140] Obtaining fitness values corresponding to two individuals participating in the mutation, comparing the fitness values corresponding to the two individuals participating in the mutation, and setting the larger fitness value as the mutation fitness value;
[0141] Obtaining a preset mutation probability, a mutation fitness value, and an average fitness value of individuals in the new parent population;
[0142] Obtaining a mutation probability according to the preset mutation probability, the mutation fitness value, and the average fitness value of the individuals in the new parent population;
[0143] The mutation operation is performed on the individuals of the new parent population according to the mutation probability, and the optimal individual is obtained when the preset end condition is reached.
[0144] It should be noted that the mutation operation refers to replacing certain genes in the individual chromosome code with other genes. No new individuals are generated in this process. The mutation operator used here changes the gene. The mutation operator can be basic bit mutation, mean mutation, boundary mutation, non-uniform mutation and Gaussian approximation mutation, etc. This embodiment does not limit this. When performing the mutation operation, in order to allow individuals with lower fitness to participate in the mutation as much as possible, and to allow individuals with higher fitness to be kept at a slightly lower value where the mutation probability is not 0, it is necessary to obtain the fitness value of the individuals participating in the mutation, and determine the probability of mutation based on the fitness of the two individuals participating in the mutation. Therefore, the adaptive mutation formula proposed in this article is as follows:
[0145]
[0146] Among them, P m is the mutation probability, ranging from 0.01 to 0.1, P mmax is the maximum crossover rate, P mmin is the minimum crossover rate, and f is the fitness value of the mutation individual participating in the mutation operation.
[0147] This embodiment encodes the chromosomes of the parent population individuals and assigns fitness to the chromosomes of each individual. Based on the fitness of each individual, the surviving population individuals are selected to form new parent population individuals. The obtained new parent population individuals are screened, and the individuals that meet the conditions are output as the optimal population individuals according to the set tolerance value. This avoids inputting a large amount of poor quality data into the neural network model, so that the finally trained neural network model can be more accurate.
[0148] refer to Figure 5 , Figure 5 This is a flow chart of a third embodiment of a soil heavy metal prediction method according to the present invention.
[0149] Based on the above embodiments, step S30 of the soil heavy metal prediction method of this embodiment includes:
[0150] Step S301: selecting a target eigenvalue from the eigenvalues of the soil heavy metal sample dataset.
[0151] It should be noted that the target eigenvalue is one of the eigenvalues in the soil heavy metal sample data set, and each of the eigenvalues will become the target eigenvalue.
[0152] Step S302: Determine the distance between the target eigenvalue and other eigenvalues in the eigenvalues.
[0153] It should be noted that the distance between the target eigenvalue and other eigenvalues in the eigenvalue set refers to the Euclidean distance between the target eigenvalue and the other eigenvalues in the eigenvalue set. For example, if there is a eigenvalue set {a, b, c, d, e} and the currently selected target eigenvalue is a, then the other eigenvalues are b, c, d, and e. The distance between the target eigenvalue and other eigenvalues is the Euclidean distance between the eigenvalues.
[0154] Step S303: Obtain the sample density of the eigenvalue according to the distance.
[0155] It should be noted that sample density refers to the density of each sample in the data sample. The density can be used to distinguish normal data points from outliers. The formula for determining the density of sample points is as follows:
[0156]
[0157] Among them, M(p) is the density of data sample points, k is the number of neighboring points, d(p, x i ) is the data sample point p to x i The Euclidean distance, δ k (x i ) is the data sample point x i The Euclidean distance to its kth nearest neighbor point, KNN(p) is the k nearest neighbor set of the data sample point p.
[0158] Step S304: determining the cluster center according to the sample density.
[0159] It should be noted that, based on the sample density of the sample data, it is possible to determine which data show a clustering trend and obtain the clustering area, so the cluster center is determined based on the sample density.
[0160] Step S305: Obtain the center point of the hidden layer according to the cluster center.
[0161] It is important to understand that if Figure 6 As shown in the figure, the radial basis neural network has an input layer, a hidden layer, and an output layer. The number of nodes in the input and output layers is determined by the number of eigenvalues and target values in the sample data. The input sample data includes four eigenvalues: longitude, latitude, altitude, and crop type. The corresponding input layer nodes are 4. The output sample data is the content of heavy metal As, so the corresponding output node number is 1. The number of nodes in the hidden layer corresponds to the number of center points in the hidden layer, and the cluster center corresponds to the location of the center point of the hidden layer.
[0162] In order to further obtain the optimized neural network model, the following steps are also included:
[0163] A clustering data set is obtained according to the soil heavy metal sample data set and the cluster center.
[0164] It should be noted that the data in the cluster dataset comes from the soil heavy metal sample dataset, and the data in the cluster dataset tends to cluster toward the cluster center.
[0165] Obtaining the number of samples and sample data of the clustering data set;
[0166] It should be noted that the number of samples refers to the number of data in the clustering data set, and the sample data refers to the specific data contained in the clustering data set.
[0167] Obtaining a distance between the sample data and the cluster center;
[0168] It should be noted that the distance between the sample data and the cluster center refers to the Euclidean distance between the sample data and the cluster center.
[0169] Obtaining the cluster variance of each cluster according to the distance and the number of samples;
[0170] It should be noted that the cluster variance represents the density of the sample data distribution, which can reflect the width of the cluster to a certain extent. Even if the formula of the cluster variance is:
[0171]
[0172] Among them, S i is the variance of each cluster, size(C i ) belongs to the cluster center u i The number of samples, dist(x,u i ) is the Euclidean distance, C i The denser the data in the clustered dataset, the smaller the cluster variance will be. The sparser the data in the clustered dataset, the larger the cluster variance will be. The density and sparseness are expressed by the Euclidean distance between the data, dist(x, u i ) reaction to obtain
[0173] obtaining a scaling factor according to the cluster variance;
[0174] It should be noted that the scaling factor determines the change in the width of the cluster center and is determined based on the data in the cluster dataset. The specific calculation formula is:
[0175]
[0176] The smaller the cluster variance, the smaller the scaling factor ε i will also become smaller, and the width of the center point will also decrease. On the contrary, the cluster variance will be larger, and the resulting scaling factor ε i It will also get bigger, and the width of the center point will also decrease.
[0177] A width vector is obtained according to the scaling factor.
[0178] It should be noted that the width vector determines the width of the current cluster center, which is specifically determined by the scaling factor and the distance between cluster centers.
[0179] In the specific implementation, the Euclidean distance between cluster centers is first calculated. The distance cardinality is obtained based on the Euclidean distance between cluster centers. The distance cardinality is the average value of the average distance between each cluster center point. The specific calculation formula is as follows:
[0180]
[0181] Among them, meanD(u i ) is the average distance between each cluster center point, k is the number of neighboring points, dist(u i ,u j ) is the Euclidean distance. The width of each cluster center is determined based on the obtained distance base and scaling factor. The specific calculation formula is:
[0182] σ i =ε i ·meanD(u i )
[0183] This example selects a target value from a soil heavy metal dataset, calculates the distance between the target value and other characteristic values, and determines the overall sample density. Based on the obtained sample density, several cluster centers are obtained, with the number of cluster centers corresponding to the number of center points in the hidden layer. After obtaining the cluster centers, the distances between them are calculated to determine the width vectors of the cluster centers. This results in specific, appropriately sized cluster centers and optimizes the neural network model. This ensures more accurate determination of center point widths than traditional methods, thereby improving the accuracy of the final prediction results.
[0184] Reference Figure 7 , Figure 7 This is a flow chart of a third embodiment of a soil heavy metal prediction method according to the present invention.
[0185] Based on the above embodiments, the soil heavy metal prediction method of this embodiment further includes, after step S30:
[0186] Step S306: Obtain the current weight of the output layer in the optimized neural network model;
[0187] Step S307: Obtain the updated value of the previous iteration, and obtain the updated weight according to the updated value of the previous iteration, the weight of the output layer and the momentum coefficient.
[0188] Step S308: Obtaining an updated gradient according to the updated weight.
[0189] Step S309: Obtaining a cumulative gradient value and a cumulative gradient square according to the updated gradient.
[0190] It should be noted that the current weight is the weight corresponding to the output layer of the current training state of the optimized neural network. When an input value is input into the neural network model, the input value and the current weight are calculated to obtain the final output result.
[0191] It can be understood that the last iteration update value refers to the change in the weight when the weight is iterated last time. In the initial iteration, the corresponding last iteration update value is 0.
[0192] In the specific implementation, when updating the current weight, it is necessary to obtain the weight w of the tth iteration and the updated value of the weight from the t-1th to the tth iteration. The update formula is as follows:
[0193] w′=w t +α*v t-1
[0194] Among them, w t is the weight corresponding to the current number of iterations, α is the momentum coefficient, v t-1 Update the value for the previous iteration, with the initial value being 0.
[0195] It should be noted that the gradient describes the degree of growth of the weight and can reflect the speed of the weight change.
[0196] It can be understood that the cumulative gradient value is obtained by accumulating the gradient after each weight iteration, and the square of the gradient after each weight iteration is obtained.
[0197] Step S310: Obtaining a learning rate according to the accumulated gradient value.
[0198] It should be noted that the learning rate represents the magnitude of each weight update. If the learning rate is too large, the parameters to be optimized will fluctuate around the minimum value and will not converge; if the learning rate is too small, the parameters to be optimized will converge slowly.
[0199] It should be understood that during the iterative optimization process, if the gradient changes in sign, it means that the extreme point has been crossed during the iteration. Therefore, in the next iteration, it is necessary not only to adjust the learning direction but also to reduce the learning step size. Similarly, if the sign of the gradient does not change between two iterations, it means that the distance to the extreme point is too far, so it is only necessary to increase the learning step size accordingly.
[0200] In the specific implementation, the current learning rate is calculated by obtaining the cumulative gradient value during the iteration and selecting the corresponding formula based on the product of the gradient value of the current iteration and the previous iteration. The calculation formula is as follows:
[0201]
[0202] Calculate the learning rate of the current iteration, where u represents the learning rate, u0 is a fixed value, and s tis the cumulative gradient value, the initial value is 0, that is, if the positive and negative values of the gradient change before and after the iteration, the learning rate decreases, otherwise the learning rate increases. In addition, as the number of iterations increases, s t As increases, the change in learning rate decreases.
[0203] Step S311: obtaining an updated weight according to the current weight, the last iterative update value, the updated gradient, and the cumulative gradient square, and updating the weight of the output layer in the optimized neural network model.
[0204] In the specific implementation, the updated weight is obtained based on the current weight, the last iterative update value, the updated gradient, and the cumulative gradient square, and the weight at the time of this weight update is calculated. The specific update formula is:
[0205]
[0206] w t+1 =w t +v t
[0207] where w t+1 It represents the updated value of the weight in the current iteration, that is, the weight step size and learning direction are adjusted. After the weight adjustment is completed, it is necessary to check whether the termination condition has been met. If the termination condition is not met, the forward error needs to be recalculated. The specific forward error calculation formula is as follows:
[0208] net=W T x+b
[0209] h=g(net)
[0210]
[0211] Where W and b are the weights and thresholds of the hidden layer and the output layer, x is the input data of the hidden layer and the output layer, g is the activation function, h is the output, E is the error, and y i is the target value, is the actual value.
[0212] If the termination condition is met, the optimized neural network model can be output as a prediction model.
[0213] In this embodiment, the forward error is first calculated, and then all parameters are updated using an adaptive root mean square backpropagation algorithm. Traditional gradient descent algorithms use a fixed learning rate as the learning step size, which significantly affects the results of each iterative optimization, resulting in slow convergence and low convergence accuracy. In this example, by adjusting the learning direction and learning step size based on the positive and negative gradient values between iterations, the weights can be updated more flexibly and accurately, thereby ensuring the accuracy of all parameters in the optimized neural network model and, in turn, the accuracy of the final prediction results.
[0214] In addition, an embodiment of the present invention further provides a storage medium on which a soil heavy metal prediction program is stored. When the soil heavy metal prediction program is executed by a processor, the steps of the soil heavy metal prediction method described above are implemented.
[0215] Reference Figure 8 , Figure 8 This is a structural block diagram of the first embodiment of the soil heavy metal prediction device of the present invention.
[0216] like Figure 8 As shown, the soil heavy metal prediction device proposed in the embodiment of the present invention includes:
[0217] The data acquisition module 10 is used to acquire a soil heavy metal sample dataset.
[0218] The individual selection module 20 is used to perform sample analysis on the soil heavy metal sample data set to obtain the optimal individual.
[0219] The model optimization module 30 is used to determine the center point of the hidden layer of the initialized neural network model, generate a width vector according to the soil heavy metal sample data set, and obtain an optimized neural network model according to the center point and the width vector.
[0220] The data prediction module 40 is used to obtain the soil heavy metal data to be predicted, and predict the soil heavy metal data to be predicted based on the optimized neural network model to obtain a prediction result.
[0221] This embodiment obtains a soil heavy metal sample data set; performs sample analysis on the soil heavy metal sample data set to obtain the optimal individual; determines the center point of the hidden layer of the initialized neural network model, and generates a width vector based on the soil heavy metal sample data set, and obtains an optimized neural network model based on the center point and the width vector; obtains the soil heavy metal data to be predicted, and predicts the soil heavy metal data to be predicted based on the optimized neural network model to obtain a prediction result. Since this embodiment is based on pre-screening of training samples, the quality of the training samples is guaranteed. Compared with traditional training methods, the present invention guarantees the accuracy of the training results, and the accuracy of the parameters in the obtained optimized neural network model is high, thereby ensuring the high accuracy of the final prediction result.
[0222] In one embodiment, the individual selection module 20 is further used to perform sample analysis on the soil heavy metal sample data set to obtain characteristic values; perform initial encoding on the characteristic values to obtain parent population individuals; obtain a transformation factor of the parent population individual, and obtain the fitness of the parent population individual based on the transformation factor; determine the cumulative probability of the parent population individual based on the fitness of the parent population individual; select the population individual based on the cumulative probability, and use the selected population individual as the new parent population individual; and obtain the optimal individual based on the new parent population individual.
[0223] In one embodiment, the individual selection module 20 is further used to obtain the fitness values corresponding to the two individuals participating in the crossover, compare the fitness values corresponding to the two individuals participating in the crossover, and set the larger fitness value as the crossover fitness value; obtain the preset crossover probability, the crossover fitness value and the average fitness value of the new parent population individuals; obtain the crossover probability according to the preset crossover probability, the crossover fitness value and the average fitness value of the new parent population individuals; perform a crossover operation on the new parent population individuals according to the crossover probability, and obtain the optimal individual when the preset end condition is reached.
[0224] In one embodiment, the individual selection module 20 is further used to obtain the fitness values corresponding to the two individuals participating in the mutation, compare the fitness values corresponding to the two individuals participating in the mutation, and set the larger fitness value as the mutation fitness value; obtain the preset mutation probability, the mutation fitness value and the average fitness value of the new parent population individuals; obtain the mutation probability according to the preset mutation probability, the mutation fitness value and the average fitness value of the new parent population individuals; perform a mutation operation on the new parent population individuals according to the mutation probability, and obtain the optimal individual when the preset end condition is reached.
[0225] In one embodiment, the model optimization module 30 is further used to select a target eigenvalue from the eigenvalues of the soil heavy metal sample data set; determine the distance between the target eigenvalue and other eigenvalues in the eigenvalues, and obtain the sample density of the eigenvalue based on the distance; determine the cluster center based on the sample density; and obtain the center point of the hidden layer based on the cluster center.
[0226] In one embodiment, the model optimization module 30 is further used to obtain a cluster data set based on the soil heavy metal sample data set and the cluster center; obtain the number of samples and sample data of the cluster data set; obtain the distance based on the sample data and the cluster center; obtain the cluster variance of each cluster based on the distance and the number of samples; obtain a scaling factor based on the cluster variance; and obtain a width vector based on the scaling factor.
[0227] In one embodiment, the model optimization module 30 is further used to obtain the current weight of the output layer in the optimized neural network model; obtain the updated value of the previous iteration, and obtain the updated weight based on the updated value of the previous iteration, the weight of the output layer and the momentum coefficient; obtain the updated gradient based on the updated weight; obtain the cumulative gradient value and the cumulative gradient square based on the updated gradient; obtain the learning rate based on the cumulative gradient value; obtain the updated weight based on the current weight, the updated value of the previous iteration, the updated gradient, and the cumulative gradient square, and update the weight of the output layer in the optimized neural network model.
[0228] It should be understood that the above is only an example and does not constitute any limitation to the technical solution of the present invention. In specific applications, those skilled in the art can make settings as needed, and the present invention does not impose any limitation on this.
[0229] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of it according to actual needs to achieve the purpose of the embodiment scheme, and no limitation is made here.
[0230] In addition, it should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.
[0231] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0232] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, or of course by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0233] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A soil heavy metal prediction method, characterized in that: The soil heavy metal prediction method comprises: Obtain soil heavy metal sample dataset; performing sample analysis on the soil heavy metal sample data set to obtain an optimal individual, specifically comprising: performing sample analysis on the soil heavy metal sample data set to obtain a characteristic value, performing initial encoding on the characteristic value to obtain a parent population individual, obtaining a transformation factor of the parent population individual, and obtaining a fitness of the parent population individual according to the transformation factor, determining a cumulative probability of the parent population individual according to the fitness of the parent population individual, selecting the population individual according to the cumulative probability, using the selected population individual as a new parent population individual, and obtaining an optimal individual based on the new parent population individual; Determine the center point of the hidden layer of the initial neural network model, generate a width vector based on the soil heavy metal sample data set, and obtain an optimized neural network model based on the optimal individual, the center point, and the width vector, specifically including: selecting a target eigenvalue from the eigenvalues of the soil heavy metal sample data set, determining the distance between the target eigenvalue and other eigenvalues in the eigenvalues, and obtaining the sample density of the eigenvalue based on the distance; determine the cluster center based on the sample density, obtain the center point of the hidden layer based on the cluster center, obtain a cluster data set based on the soil heavy metal sample data set and the cluster center, obtain the number of samples and sample data of the cluster data set, obtain the distance based on the sample data and the cluster center, obtain the cluster variance of each cluster based on the distance and the number of samples, obtain a scaling factor based on the cluster variance, and obtain the width vector based on the scaling factor; Acquire soil heavy metal data to be predicted, and predict the soil heavy metal data to be predicted based on the optimized neural network model to obtain a prediction result.
2. The method according to claim 1, wherein The step of obtaining the optimal individual according to the new parent population individuals includes: Obtaining fitness values corresponding to two individuals participating in the crossover, comparing the fitness values corresponding to the two individuals participating in the crossover, and setting the larger fitness value as the crossover fitness value; Obtaining a preset crossover probability, a crossover fitness value, and an average fitness value of individuals in the new parent population; Obtaining a crossover probability according to the preset crossover probability, the crossover fitness value, and the average fitness value of the individuals in the new parent population; A crossover operation is performed on the individuals of the new parent population according to the crossover probability, and when a preset end condition is reached, the optimal individual is obtained.
3. The method according to claim 1, wherein After selecting the population individuals according to the cumulative probability and using the selected population individuals as new parent population individuals, the method further includes: Obtaining fitness values corresponding to two individuals participating in the mutation, comparing the fitness values corresponding to the two individuals participating in the mutation, and setting the larger fitness value as the mutation fitness value; Obtaining a preset mutation probability, a mutation fitness value, and an average fitness value of individuals in the new parent population; Obtaining a mutation probability according to the preset mutation probability, the mutation fitness value, and the average fitness value of the individuals in the new parent population; The mutation operation is performed on the individuals of the new parent population according to the mutation probability, and the optimal individual is obtained when the preset end condition is reached.
4. The method according to any one of claims 1 to 3, characterized in that After obtaining the optimized neural network model according to the optimal individual, center point and width vector, the method further includes: Obtaining the current weight of the output layer in the optimized neural network model; Obtaining the updated value of the previous iteration, and obtaining the updated weight according to the updated value of the previous iteration, the weight of the output layer and the momentum coefficient; Obtaining an updated gradient according to the updated weight; Obtaining a cumulative gradient value and a cumulative gradient square according to the updated gradient; Obtaining a learning rate based on the accumulated gradient value; An updated weight is obtained according to the current weight, the last iterative update value, the updated gradient, and the cumulative gradient square, and the weight of the output layer in the optimized neural network model is updated.
5. A soil heavy metal prediction device, characterized in that: The soil heavy metal prediction device comprises: Data acquisition module, used to obtain soil heavy metal sample data set; an individual selection module, configured to perform sample analysis on the soil heavy metal sample dataset to obtain an optimal individual, specifically comprising: performing sample analysis on the soil heavy metal sample dataset to obtain characteristic values, performing initial encoding on the characteristic values to obtain a parent population individual, obtaining a transformation factor of the parent population individual, and obtaining the fitness of the parent population individual based on the transformation factor, determining a cumulative probability of the parent population individual based on the fitness of the parent population individual, selecting the population individual based on the cumulative probability, using the selected population individual as a new parent population individual, and obtaining an optimal individual based on the new parent population individual; A model optimization module is used to determine the center point of the hidden layer of the initial neural network model, generate a width vector based on the soil heavy metal sample data set, and obtain an optimized neural network model based on the center point and the width vector, specifically including: selecting a target eigenvalue from the eigenvalues of the soil heavy metal sample data set, determining the distance between the target eigenvalue and other eigenvalues in the eigenvalues, and obtaining the sample density of the eigenvalue based on the distance; determining a cluster center based on the sample density, obtaining the center point of the hidden layer based on the cluster center, obtaining a cluster data set based on the soil heavy metal sample data set and the cluster center, obtaining the number of samples and sample data of the cluster data set, obtaining the distance between the sample data and the cluster center, obtaining the cluster variance of each cluster based on the distance and the number of samples, obtaining a scaling factor based on the cluster variance, and obtaining the width vector based on the scaling factor; The data prediction module is used to obtain the soil heavy metal data to be predicted, and predict the soil heavy metal data to be predicted according to the optimized neural network model to obtain a prediction result.
6. A soil heavy metal prediction device, characterized in that: The device includes: a memory, a processor, and a soil heavy metal prediction program stored in the memory and executable on the processor, wherein the soil heavy metal prediction program is configured to implement the steps of the soil heavy metal prediction method according to any one of claims 1 to 4.
7. A storage medium, characterized in that: The storage medium stores a soil heavy metal prediction program, which, when executed by a processor, implements the steps of the soil heavy metal prediction method according to any one of claims 1 to 4.