Soil ammonium nitrogen content hyperspectral prediction method based on improved extreme learning machine
By optimizing the Extreme Learning Machine (ELM) model parameters using the improved Butterfly Optimization Algorithm (IBOA) and combining data preprocessing and feature band selection, the problems of slow model convergence speed and insufficient accuracy in soil ammonium nitrogen content prediction were solved, achieving efficient prediction results.
Patent Information
- Application Number
- CN202510752551.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-06
- Publication Date
- 2025-11-14
AI Technical Summary
Existing extreme learning machine models have limitations in parameter settings for predicting soil ammonium nitrogen content, resulting in slow model convergence and a tendency to get trapped in local optima, which affects prediction accuracy.
An improved butterfly optimization algorithm (IBOA) is used to optimize the parameters of the extreme learning machine (ELM) model. Combined with data preprocessing methods such as Savitzky-Golay smoothing, multivariate scattering correction, and first-order differentiation, a sequential forward selection algorithm is used to select feature bands to construct a hyperspectral prediction model.
It improves the prediction accuracy of soil ammonium nitrogen content, reduces noise and data redundancy, provides theoretical and technical support, and offers an important reference for soil nitrogen cycle research and management.
Smart Images

Figure CN120954549A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of hyperspectral prediction technology, and in particular to a hyperspectral prediction method for soil ammonium nitrogen content based on an improved extreme learning machine. Background Technology
[0002] Soil ammonium nitrogen (NH4) + Ammonium nitrogen (NH4+) is an important indicator for assessing soil fertility and plays a crucial role in soil resource evaluation, precision agriculture management, and ecological environmental protection. Efficient and accurate prediction of soil NH4+ content is essential for optimizing fertilization, improving crop yield and quality, and maintaining ecological balance. Traditional methods such as CO2 detection, the Kjeldahl method, and chemical oxidation methods, while accurate, are costly, complex, and environmentally impactful, making them unsuitable for large-scale rapid estimation. In recent years, hyperspectral technology, with its advantages of being pollution-free, efficient, accurate, economical, and non-destructive, has gradually become a new alternative to traditional methods, accurately predicting soil NH4+ with only a small amount of soil sample data. + -N content.
[0003] Soil NH4 based on hyperspectral technology + In NH4+ content inversion studies, optimizing and selecting modeling methods is crucial for improving prediction accuracy. This process mainly includes three core steps: data preprocessing, feature band selection, and model building. Common data preprocessing methods include SG smoothing, standard normal transformation, multivariate scattering correction, and first-order differentiation. Common feature band selection methods include competitive adaptive reweighted sampling algorithms, simulated annealing algorithms, stochastic frog jumping algorithms, Black Hawk optimization algorithms, artificial hummingbird algorithms, and starfish optimization algorithms. For model building, commonly used algorithms include partial least squares regression, support vector machines, multiple linear regression, random forests, backpropagation neural networks, and Extreme Learning Machines (ELM). Among these, ELM, with its unique advantages such as fast learning speed, ease of use, good generalization ability, and strong ability to solve small sample problems, has become the current preferred choice for soil NH4+. + -N content inversion is the mainstream modeling method, but its algorithm still has certain limitations in parameter setting. Currently, some studies have used traditional heuristic algorithms such as genetic algorithms, particle swarm optimization algorithms, and gray wolf optimization algorithms to optimize the parameters of ELM models. Although some results have been achieved, problems such as slow convergence speed and easy getting trapped in local optima still exist, which limit the further optimization and application of the model. Summary of the Invention
[0004] The technical problem this invention aims to solve is to address the shortcomings of existing technologies by providing a hyperspectral prediction method for soil ammonium nitrogen content based on an improved extreme learning machine (ELM). This method employs an improved butterfly optimization algorithm (IBOA) to optimize the parameters of the ELM model, overcoming the limitations of traditional optimization algorithms and achieving accurate prediction of soil NH4 content. + Effective prediction of -N content.
[0005] To solve the above-mentioned technical problems, the technical solution adopted by this invention is: a hyperspectral prediction method for soil ammonium nitrogen content based on an improved extreme learning machine, comprising the following steps:
[0006] Step 1: Collect and process soil samples for soil spectral measurements and NH4. + -N content determination;
[0007] Step 2: Measure soil spectral reflectance data;
[0008] Step 3: Soil spectral reflectance data preprocessing: First, the Savitzky-Golay smoothing method is used to denoise the soil spectral reflectance data to obtain the original spectral reflectance data; the original spectral reflectance data is further subjected to a first-order differential transformation to form a spectral reflectance dataset; and the KS algorithm is used to randomly divide the spectral reflectance dataset into a training set and a test set.
[0009] Step 4: Select spectral feature bands: Use a sequential forward selection algorithm to select feature bands;
[0010] The process of selecting feature bands using the sequential forward selection algorithm is as follows:
[0011] (1) Initialize feature subset: Initialize an empty feature subset. And a candidate set C = F containing all characteristic bands of the preprocessed spectral reflectance data, where F is the set of all characteristic bands of the preprocessed spectral reflectance data;
[0012] (2) Feature band selection: For each candidate feature band f in the candidate set C i ∈C, i=1,2,…,m′, where m′ is the number of candidate feature bands in the candidate set C, and the following steps are performed:
[0013] a. Select candidate feature bands f i Adding it to the feature subset S results in a new feature subset S′=S∪{f i};
[0014] b. Build an Extreme Learning Machine (ELM) model on the training set using a feature subset S′, and calculate the RMSECV value of the ELM model using 5-fold cross-validation, denoted as RMSECV. i ;
[0015] Select RMSECV i The smallest characteristic band f best , will f best Remove from candidate set C to obtain a new candidate set C′, and set f best Add it to the feature subset S to obtain a new feature subset S″;
[0016] (3) Iteration process: Repeat step (2) until the candidate set is empty or the predetermined number of feature bands is reached, and the iteration ends; in each iteration, decide whether to retain the feature band based on the improvement of the performance of the added feature band on the Extreme Learning Machine (ELM) model.
[0017] (4) Final Feature Band Selection: When the algorithm ends, the resulting feature subset is the final selected feature band set D;
[0018] Step 5: The parameters of the Extreme Learning Machine (ELM) model are optimized using the improved butterfly optimization algorithm IBOA, thereby constructing a model for predicting soil NH4. + A hyperspectral prediction model for -N content was developed, and the model was validated.
[0019] The improved butterfly optimization algorithm IBOA uses the Tent chaotic map to optimize the initial butterfly individual position and employs adaptive weight coefficients and the Cauchy mutation operator to optimize the butterfly position update process. The specific process is as follows:
[0020] 1) Initialize the population using a Tent chaotic sequence; generate chaotic sequences based on Tent mappings. The process is as shown in the following formula:
[0021]
[0022] In the formula: u k The numbers are random numbers in the range [0,1]; k is the population size; i is the current iteration number;
[0023] Based on the chaotic sequence generated above, initialize the initial position sequence of the individual butterflies. as follows:
[0024]
[0025] In the formula: These are the upper and lower limits of the initial position sequence of the individual butterflies, respectively; It is a sequence containing multiple positions that is related to both the number of iterations and the number of individuals in the population. i represents the current iteration number, and different position information will be generated as i changes; k is the population size, and different position sequences will also be generated for different population individuals.
[0026] 2) The search strategy is updated using a dynamic adjustment mechanism based on adaptive weight coefficients;
[0027] The adaptive weight coefficients change continuously with the increase of the number of iterations, and combine the position information of the current individual, the globally optimal individual, and the randomly selected individual to dynamically control the movement direction and distance of the current butterfly individual;
[0028] The expression for the adaptive weighting coefficient is:
[0029]
[0030] In the formula: t max The maximum number of iterations is given by W(t), where W(t) is the weight coefficient at the t-th iteration.
[0031] Based on adaptive weight coefficients, the formula for updating the individual position during the global search process is:
[0032]
[0033] Based on adaptive weight coefficients, the formula for updating the individual position during the local search process is:
[0034]
[0035] 3) Apply the Cauchy mutation operator to the optimal solution in the current iteration; the new optimal solution obtained after Cauchy mutation is shown in the following formula:
[0036] X newbest =X best +X best *cauchy(0,1)
[0037] In the formula: X newbest X is the new optimal solution obtained by Cauchy mutation of the optimal solution in the current iteration; best This represents the optimal solution obtained in the current iteration; cauchy(0,1) is the standard Cauchy distribution function.
[0038] The process of optimizing the parameters of the Extreme Learning Machine (ELM) model using the improved butterfly optimization algorithm IBOA is as follows:
[0039] Step S1: Define the search space and initialize the butterfly population;
[0040] Step S11: Define the search space: Set the range of the number of hidden layer nodes L in the ELM model to [L... min ,L max The weight matrix W has a dimension of L×d, where d is the dimension of the input features; the bias vector b has a dimension of L×1.
[0041] Step S12: Initialize the population: Initialize the positions of individual butterflies using the Tent chaotic map; each individual butterfly represents a set of parameters (L, W, b), and the position of the individual butterfly... As shown in the formula below:
[0042]
[0043] In the formula: It is a chaotic sequence generated by the Tent chaotic mapping;
[0044] Step S2: Set the fitness function;
[0045] Define the fitness function f(X) i ) represents the error of the ELM model on the validation set;
[0046] Step S3: Update the position of the butterfly individual using adaptive weight coefficients W(t) in both the global and local searches;
[0047] Step S4: For the current globally optimal solution X best Apply the Cauchy mutation operator to generate a new optimal solution X. newbest ;
[0048] Step S5: Update the global optimal solution;
[0049] Compare the newly generated optimal solution X newbest and the current global optimal solution X best Choose the solution with the highest fitness as the new global optimal solution;
[0050] Step S6: Repeat steps S3-S5 until the maximum number of iterations t is reached. max ;
[0051] Step S7: Output the optimal parameters (L) * W * ,b * This refers to the optimal number of hidden layer nodes, the dimension of the weight matrix W, and the dimension of the bias vector b.
[0052] Step 6: Construct a hyperspectral prediction model for NH4 using the optimized ELM model. + -N content is predicted; the feature bands selected by the feature band selection algorithm are set as independent variables, NH4 + With NH4+ content as the dependent variable, a hyperspectral prediction model for NH4+ was constructed using the optimized ELM model. + Predicting -N content;
[0053] The characteristic band combination D = {(x v ,yv ):v=1,…,s,x v ∈R e ,y v ∈R}, that is, s soil samples with feature dimension e, x v Let y represent the feature vector of the v-th sample, with dimension e, which contains all feature information related to the v-th sample; v The NH4+ of the v-th sample in the set of measured data representing the spectral characteristics of soil samples and their corresponding ammonium nitrogen content. + The true value of -N content;
[0054] definition NH4 in soil sample + Predicted values for -N content:
[0055]
[0056] Where F is the model function of ELM. The goal of ELM is to improve the prediction accuracy of the model by randomly generating hidden layer weights and biases and minimizing the objective function by minimizing the output layer weights.
[0057] The objective function of the ELM model is defined as:
[0058]
[0059] Where Obj is the objective function, and l represents the loss function used to measure the predicted value. Compared with the true value y v The difference; to avoid overfitting, Ω(f) is a regularization term that defines the complexity of the model:
[0060]
[0061] Where w represents the weights of the output layer of the ELM model, and λ is the regularization parameter;
[0062] The training process of the ELM model is completed through a single forward propagation; assuming the number of hidden layer nodes is K and the hidden layer weight matrix is W∈R e×K The hidden layer bias vector is b∈R K If the activation function of the hidden layer is h(·), then the output matrix H of the hidden layer is:
[0063] H = h(XW + b)
[0064] Where X is the input feature matrix, and H∈R s×K This is the output matrix of the hidden layer;
[0065] The output layer weights w of the ELM model are solved using the least squares method:
[0066]
[0067] in, H is the pseudo-inverse of the hidden layer output matrix H, and Y is the true value vector.
[0068] Ultimately, the predicted values output by the ELM model for:
[0069]
[0070] To avoid overfitting, a regularization term is introduced into the objective function; by introducing the regularization parameter λ, the objective function of the ELM model is rewritten as:
[0071]
[0072] Taking the derivative of the objective function above and setting it to zero yields the optimal solution w for the output layer weights. * :
[0073]
[0074] Where I is the identity matrix.
[0075] The beneficial effects of adopting the above technical solution are as follows: The hyperspectral prediction method for soil ammonium nitrogen content based on an improved extreme learning machine provided by this invention, in order to remove noise and eliminate baseline drift, preprocesses soil samples and uses indoor spectroscopic measurement methods, taking the preprocessed soil spectral reflectance data as the research object, to analyze soil NH4. + The spectral response bands of -N were used to mine spectral characteristic parameters. To reduce data redundancy and noise, the SFS algorithm was used in conjunction with spectral reflectance data for characteristic band selection. A soil ammonium nitrogen content prediction model was constructed using the ELM method with parameters optimized by IBOA, thereby improving the accuracy of the prediction model. This not only provides theoretical and technical support for soil ammonium nitrogen content monitoring but also offers important reference and guidance for soil nitrogen cycle research and soil management. Attached Figure Description
[0076] Figure 1 A flowchart of a method for predicting soil ammonium nitrogen content based on hyperspectral imaging is provided in this embodiment of the invention;
[0077] Figure 2 Soil spectral reflectance curves provided in embodiments of the present invention;
[0078] Figure 3 The NH4 provided in the embodiments of the present invention + The correlation coefficient curve between -N content and spectral reflectance is shown in Figure 1. (a) represents the original spectral data and the correlation coefficient between NH4+ and spectral reflectance. +The correlation coefficient diagram between -N content and NH4 content is shown in (b), which shows the spectral data after MSC preprocessing and NH4 content. + The correlation coefficient diagram between -N content and NH4 content is shown in (c), which is the spectral data after SNV preprocessing and NH4 content. + The correlation coefficient diagram between -N content, (d) shows the spectral data after MOVE preprocessing and NH4 content. + The correlation coefficient diagram between -N content, (e) shows the spectral data after FD preprocessing and NH4 content. + The correlation coefficient diagram between -N content, (f) shows the spectral data after SD preprocessing and NH4 content. + Correlation coefficient diagram between -N content;
[0079] Figure 4 The spectral feature band diagram screened by the SFS algorithm provided in this embodiment of the invention, wherein (a) is the selection frequency corresponding to the feature band selected by the SFS algorithm, and (b) is the RMSE value of the feature band screening process of the SFS algorithm.
[0080] Figure 5 The embodiments of this invention provide soil ammonium nitrogen content prediction results for models such as RF, SVM, ELM, SELM, BELM, and the optimized Extreme Learning Machine (IELM). Among them, (a) is the result prediction of model RF, (b) is the result prediction of model SVM, (c) is the result prediction of model ELM, (d) is the result prediction of model SELM, (e) is the result prediction of model BELM, and (f) is the result prediction of model IELM. Detailed Implementation
[0081] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0082] The soil sample collection area for this embodiment was selected in Wuxing District, Huzhou City, Zhejiang Province, China, with geographical coordinates of 119°14'44.1"~120°29'52.9"E and 30°22'56.4"~31°10'56.1"N. This region has a subtropical monsoon maritime climate, with an average annual temperature of approximately 16.9℃, an average annual precipitation of approximately 1023.3 mm, and an altitude of 3~5m. The main soil types in this region include alluvial soil and paddy soil. Sampling was conducted on November 4, 2023. All sampling points were selected from uncovered bare soil, and a total of 72 samples were collected within the study area.
[0083] In this embodiment, a hyperspectral prediction method for soil ammonium nitrogen content based on an improved extreme learning machine is used, such as... Figure 1 As shown, it includes the following steps:
[0084] Step 1: Collect and process soil samples for soil spectral measurements and NH4. + -N content determination; several soil samples were collected, air-dried, ground, and sieved through a 0.2 mm sieve; the treated soil samples were divided into two parts, one for soil spectral reflectance data measurement and the other for NH4 content measurement. + -N content determination; NH4 + The Kjeldahl method was used to determine the -N content.
[0085] In this embodiment, a handheld GPS locator was used for precise positioning during soil sample collection. The sampling depth was 0–20 cm. Five soil samples collected from each sampling point were mixed thoroughly and stored as a single soil sample in the dark. The soil samples were then air-dried, ground, and sieved through a 0.2 mm sieve. The resulting soil samples were then divided into two parts, one for measuring soil spectral reflectance data and the other for measuring NH4. + -N content determination. In this example, the Kjeldahl method was used to determine the NH4+ content in the soil sample. + -N content, NH4 + The statistical results of the -N content determination are shown in Table 1. Table 1 shows that the NH4+ content in the soil samples... + The -N content ranged from 20.14 to 37.84 mg / kg, with a coefficient of variation of 12.7%, exhibiting low variability. The mean values of the training and validation sets were 27.67 mg / kg and 28.36 mg / kg, respectively, with standard deviations of 3.69 mg / kg and 3.55 mg / kg, respectively. This indicates that the training and validation sets are unlikely to have any bias, ensuring the representativeness of the samples.
[0086] Table 1. Descriptive statistics of ammonium nitrogen content in soil samples.
[0087]
[0088]
[0089] Step 2: Measure soil spectral reflectance data: Collect spectral reflectance data of soil samples. The wavelength range of the spectral reflectance data is 350-2500 nm, and the sampling interval is 1 nm.
[0090] In this embodiment, an ASD FieldSpec4 ground object spectrometer was used to collect soil spectral reflectance data in a darkroom, with a wavelength range of 350–2500 nm and a sampling interval of 1 nm. A probe with a 25° field of view was placed vertically above the soil sample, 10 cm away. A 200W halogen lamp was used as the sole light source, 45 cm from the soil sample, at a zenith angle of 15° to simulate sunlight. An appropriate amount of soil sample was poured into a weighing dish, slightly compacted with glass, and leveled. Whiteboard calibration was performed before each measurement. Ten spectral curves were obtained for each sample, and the average value was used to obtain the spectral reflectance of the soil sample. All spectral curves were uniformly processed by removing the first and last wavelengths (350-400 nm and 2400-2500 nm) which were significantly affected by noise. In this embodiment, NH4… + The spectral reflectance curve of -N content is shown in the figure. Figure 2 As shown in the figure, within the 400-2400nm spectral range, the soil spectral reflectance increases with the amount of NH4+. + -N content decreases with increasing NH4+ content, different NH4+ content + The spectral reflectance of -N content generally shows a consistent trend, with the lowest reflectance in the 450–470 nm band, and more pronounced troughs at 1400 nm and 1900 nm, mainly due to soil moisture molecules. Reflectance shows a significant increasing trend in the 450–1000 nm band, while the increase is slower in the 1000–1900 nm band, and continues to increase in the 2000–2160 nm band. The soil spectral reflectance curve exhibits distinct moisture absorption troughs near 1400, 1900, and 2200 nm. These troughs are typically related to the vibration and stretching of water molecules, and the vibrations of chemical bonds such as hydroxyl (-OH), carbonyl (-CO), and methyl (-CH) groups in organic matter.
[0091] Step 3: Soil Spectral Reflectance Data Preprocessing: To eliminate spectral noise and redundant information, the Savitzky-Golay smoothing method was first used to denoise the soil spectral reflectance data, obtaining the original spectral reflectance data; to further enhance the relationship between the soil spectral reflectance data and NH4... + The correlation between -N content was used to further perform a first-order differential transformation on the original spectral reflectance data to form a spectral reflectance dataset; and the Kennard-Stone (KS) algorithm was used to randomly divide the spectral reflectance dataset into training and test sets.
[0092] To eliminate spectral noise and redundant information, the Savitzky-Golay (SG) smoothing method was first used to denoise the soil spectral reflectance data, obtaining the original spectral reflectance data (R). Further steps were taken to enhance the relationship between the soil spectral reflectance data and NH4+. +The correlation between -N content was investigated, and the original spectral reflectance data R was further subjected to multivariate scattering correction transformation (MSC), standard normal variable transformation (SNV), matrix vector extraction transformation (MOVE), first-order differential (FD) transformation and second-order differential (SD) transformation.
[0093] The formulas for processing soil spectral reflectance data using MSC, SNV, MOVE, FD, and SD are as follows:
[0094]
[0095]
[0096] R′(λ i )=[R(λ i+1 )-R(λ i-1 )] / (Δλ)
[0097]
[0098] Among them, Y k,i This indicates that the k-th sample is at wavelength λ. i The original spectral reflectance value at point Y, where a and b are the intercept and slope determined by the least squares method, respectively; k,SNV Y represents the spectral reflectance value of the k-th soil sample after SNV transformation. k,SD Y represents the spectral reflectance value of the k-th soil sample after SD processing. k Y' is the filtered output at the current time k, N is the sliding window size, and Y' is the filtered output at the current time k. k-i These are historical data points; λ is the average spectral reflectance of the k-th soil sample, where n is the number of spectral bands in the soil sample; i Let R(λ) be the wavelength value of band i. i Let λ be the spectral reflectance coefficient of band i, and Δλ be the spectral reflectance coefficient of band λ. i-1 to λ i+1 The interval; R′(λ) i ) represents the first-order differential spectral reflectance value s of band i. k It is the standard deviation of the sample.
[0099] In this embodiment, R is pretreated using standard MSC, SNV, MOVE, FD, and SD methods, respectively, and NH4 is treated under different conditions. + The correlation coefficient curve between -N content and spectral reflectance is shown in the figure. Figure 3 As shown, by Figure 3 The correlation analysis results show that both the original spectral reflectance data and the spectral reflectance data preprocessed using four different methods are consistent with NH4. + There is a high correlation between -N content and the content of -N.
[0100] Figure 3 (a) shows the original spectral reflectance data and NH4. + Correlation coefficient diagram between -N content, NH4 + -N content is negatively correlated with spectral reflectance, with a relatively smooth correlation in the 400-1900nm band and fluctuating in the 1900-2400nm band. The maximum absolute value of the correlation coefficient (|r|) is 0.58 (P<0.01).
[0101] Figure 3 (b) is the spectral reflectance data after MSC preprocessing and NH4. + Correlation coefficient diagram between -N content, NH4 + -N content and spectral reflectance show a positive correlation in the 400-550nm band and a negative correlation in the 550-750nm band. In the 750-2400nm band, there is both a positive and a negative correlation, with large fluctuations and no regularity. The maximum absolute value of the correlation coefficient (|r|) is 0.61 (P<0.01).
[0102] Figure 3 (c) shows the spectral reflectance data after SNV preprocessing and NH4. + Correlation coefficient diagram between -N content, NH4 + -N content and spectral reflectance are roughly consistent with the results after MSC preprocessing, showing both positive and negative correlations with large fluctuations and a lack of regularity. The maximum absolute value of the correlation coefficient (|r|) is 0.60 (P<0.01).
[0103] Figure 3 (d) shows the spectral reflectance data after MOVE preprocessing and NH4. + Correlation coefficient diagram between -N content, NH4 + -N content and spectral reflectance are roughly consistent with the original spectral reflectance, and the maximum absolute value of the correlation coefficient (|r|) is 0.59 (P<0.01).
[0104] Figure 3 (e) is the spectral reflectance data after FD preprocessing and NH4 + The correlation coefficient graph between -N content and the curve makes it easier to find the inflection point of the curve compared to Figure a. The maximum absolute value of the correlation coefficient (|r|) is 0.62 (P<0.01).
[0105] Figure 3 (f) shows the spectral reflectance data after SD preprocessing and NH4. +The correlation coefficient graph between -N content and other parameters shows more inflection points compared to Figure b, but the correlation is not obvious, and the maximum absolute value of the correlation coefficient (|r|) is 0.56 (P<0.01). In summary, this embodiment selects the spectral reflectance data preprocessed by FD for subsequent selection of characteristic bands.
[0106] Step 4: Selecting Spectral Feature Bands: Selecting feature bands from the processed soil spectral reflectance data is crucial. This helps extract the most relevant and important information from the large array of spectral bands, thereby reducing data redundancy and noise. For soil NH4... + The complex nonlinear relationship between -N content and spectral reflectance leads to problems such as model overfitting, high computational complexity, and insufficient prediction accuracy. To address these issues, the Sequential Forward Selection (SFS) algorithm is used to select feature bands, thereby removing useless and interfering information bands.
[0107] The process of selecting feature bands using the sequential forward selection algorithm is as follows:
[0108] (1) Initialize feature subset: Initialize an empty feature subset. And a candidate set C = F containing all characteristic bands of the preprocessed spectral reflectance data, where F is the set of all characteristic bands of the preprocessed spectral reflectance data;
[0109] (2) Feature band selection: For each candidate feature band f in the candidate set C i ∈C, i=1,2,…,m′, where m′ is the number of candidate feature bands in the candidate set C, and the following steps are performed:
[0110] a. Select candidate feature bands f i Adding it to the feature subset S results in a new feature subset S′=S∪{f i};
[0111] b. Build an Extreme Learning Machine (ELM) model on the training set using a feature subset S′, and calculate the RMSECV value of the ELM model using 5-fold cross-validation, denoted as RMSECV. i ;
[0112] Select RMSECV i The smallest characteristic band f best ,Right now:
[0113]
[0114] f best Remove from candidate set C to obtain a new candidate set C′, and set f best Adding it to the feature subset S results in a new feature subset S″:
[0115] S″=S∪{f best}, C = C\{f best} (2)
[0116] (3) Iteration process: Repeat step (2) until the candidate set is empty or the predetermined number of feature bands is reached; in each iteration, the SFS algorithm will decide whether to retain the feature band based on the improvement of the performance of the added feature band on the Extreme Learning Machine (ELM) model.
[0117] (4) Final Feature Band Selection: When the SFS algorithm ends, the resulting feature subset is the final selected feature band set D;
[0118] Because the sequential forward selection algorithm, a heuristic algorithm, has a certain degree of randomness in feature band selection, the results of each selection vary slightly. Therefore, this embodiment runs the algorithm 100 times and performs statistical analysis on the results. The average selection probability is recorded as the threshold T, which is used as the basis for feature band selection. Bands with a selection probability higher than the threshold are selected as feature bands. The SFS algorithm is used to select feature bands, with the number of iterations set to 100. The selection frequency and RMSE value changes of each band during the execution of the SFS algorithm are shown below. Figure 4 As shown. 41 variables with probabilities exceeding the threshold (T = 0.03) were selected as feature bands. The number of feature bands obtained by the SFS algorithm was significantly reduced, accounting for only 2.05% of the entire band, mainly concentrated in 417–596 nm, 674–926 nm, and 1010–1312 nm.
[0119] Step 5: The parameters of the Extreme Learning Machine (ELM) model are optimized using the improved butterfly optimization algorithm IBOA, thereby constructing a model for predicting soil NH4. + A hyperspectral prediction model for -N content was developed, and the model was validated.
[0120] The Butterfly Optimization Algorithm (BOA) mimics the four processes of a butterfly's foraging mechanism: initialization, global search, local search, and position update. A mathematical model is built based on these four processes to achieve the target optimization, as follows:
[0121] (1) Initialization
[0122] Before BOA enters the local and global search phases, the algorithm randomly generates the locations of individuals in the population and generates their respective scents accordingly; the scent intensity f is expressed as the physical strength of the stimulus:
[0123] f = cI α (3)
[0124] Where: I is the stimulation intensity, which is related to the optimization fitness; c is the sensory factor, usually taking a value of 0.01; α is the power exponent dependent on f, usually taking a value of 0.1.
[0125] (2) Global search
[0126] BOA determines the jump direction by comparing the size relationship between the random number r and the switching probability P. When r ≥ P (where P = (t / Maxiter) 2 , t is the number of iterations, and Maxiter is the maximum number of iterations), the algorithm enters the global search stage, updates the individual position, and the individual variable moves towards the current global optimal solution. The formula is expressed as:
[0127]
[0128] Where: is the position vector of the i-th individual at the t-th iteration; g best is the optimal position of the individual in the previous iteration; f i t is the fragrance of the i-th individual at the t-th iteration.
[0129] (3) Local search
[0130] During the BOA search process, the value of r changes continuously within the range of [0, 1], and the value of p also changes accordingly. When r < P, the algorithm enters the local search stage, updates the individual position, and determines whether the current individual variable should approach or move away from the target. The formula is expressed as:
[0131]
[0132] Where: and are the position vectors of the j-th individual and the k-th individual during the t-th iteration.
[0133] The result calculated by this formula makes the distance between the current individual position vector and the target position vector (such as the global optimal solution position vector) continuously shrink, which means the individual is approaching the target; conversely, if the distance is continuously increasing, it means the individual is moving away from the target;
[0134] (4) Position update
[0135] According to processes (2) and (3), update the position of the individuals in BOA. If the algorithm has not reached the maximum number of iterations, update the sensory factor c and continue with global search and local search until the algorithm ends.
[0136]
[0137] Where: ct Let be the sensory factor in the t-th iteration; Maxiter is the maximum number of iterations.
[0138] The improved butterfly optimization algorithm IBOA uses the Tent chaotic map to optimize the initial butterfly individual position and employs adaptive weight coefficients and the Cauchy mutation operator to optimize the butterfly position update process. The specific process is as follows:
[0139] (1) The population is initialized using a Tent chaotic sequence. Using a Tent chaotic sequence to initialize the population ensures that the population is more evenly distributed in the solution space in the early stages of the algorithm, avoiding the algorithm from getting trapped in local optima and helping to find the optimal solution more efficiently. The chaotic sequence is generated based on the Tent mapping. The process is as follows:
[0140]
[0141] In the formula: u k The numbers are random numbers in the range [0,1]; k is the population size; i is the current iteration number;
[0142] Based on the chaotic sequence generated above, initialize the initial position sequence of the individual butterflies. as follows:
[0143]
[0144] In the formula: These represent the upper and lower limits of the initial position sequence of individual butterflies. It is a sequence containing multiple positions that is related to both the number of iterations and the number of individuals in the population. i represents the current iteration number, and different position information will be generated as i changes; k is the population size, and different position sequences will also be generated for different population individuals.
[0145] (2) The search strategy is updated by adopting a dynamic adjustment mechanism based on adaptive weight coefficients;
[0146] In BOA, a switching probability P is used to balance the global search and local search processes. However, a reasonable search strategy usually requires extensive global search in the early stages of the algorithm to locate potential regions of high-quality solutions, while in-depth local search is needed in the later stages to converge to the optimal solution. Therefore, a constant switching probability p cannot meet the requirements of algorithm iteration. To address this, a dynamic adjustment mechanism based on adaptive weight coefficients is adopted to update the search strategy. The adaptive weight coefficients change continuously with the number of iterations and are combined with the positional information of three types of individuals—the current individual, the globally optimal individual, and the randomly selected individual—to dynamically control the movement direction and distance of the current butterfly individual.
[0147] The expression for the adaptive weighting coefficient is:
[0148]
[0149] In the formula: t max The maximum number of iterations is given by W(t), where W(t) is the weight coefficient at the t-th iteration.
[0150] Based on adaptive weight coefficients, the formula for updating the individual position during the global search process is:
[0151]
[0152] Based on adaptive weight coefficients, the formula for updating the individual position during the local search process is:
[0153]
[0154] (3) Apply the Cauchy mutation operator to the optimal solution in the current iteration; the new optimal solution obtained after Cauchy mutation is shown in the following formula:
[0155] X newbest =X best +X best *cauchy(0,1) (12)
[0156] In the formula: X newbest X is the new optimal solution obtained by Cauchy mutation of the optimal solution in the current iteration; best This represents the optimal solution obtained in the current iteration; cauchy(0,1) is the standard Cauchy distribution function.
[0157] By applying the Cauchy mutation operator to the optimal solution in the current iteration, we can not only increase the diversity of the population, but also make the population more widely distributed in the search space, thereby effectively escaping local optima.
[0158] The process of optimizing the parameters of the Extreme Learning Machine (ELM) model using the improved butterfly optimization algorithm IBOA is as follows:
[0159] Step S1: Define the search space and initialize the butterfly population;
[0160] (1) Define the search space: Set the range of the number of hidden layer nodes L in the ELM model to [L min ,L max The weight matrix W has a dimension of L×d, where d is the dimension of the input features; the bias vector b has a dimension of L×1.
[0161] (2) Population initialization: The positions of individual butterflies are initialized using the Tent chaotic map; each individual butterfly represents a set of parameters (L, W, b), and the position of the individual butterfly... It is generated by the following formula:
[0162]
[0163] In the formula: It is a chaotic sequence generated by the Tent chaotic mapping.
[0164] Step S2: Set the fitness function;
[0165] Define the fitness function f(X) i The error (e.g., root mean square error, MSE) of the ELM model on the validation set is as follows:
[0166]
[0167] In the formula: y j It is the actual value. This is the predicted value from the ELM model, N. val X is the number of samples in the validation set. i It is a set of parameters corresponding to the i-th butterfly individual, that is, a parameter combination (L,W,b) of the Extreme Learning Machine (ELM) model.
[0168] Step S3: Update the individual butterfly position;
[0169] Adaptive weight coefficient W(t): The weight coefficient W(t) is dynamically adjusted with the number of iterations.
[0170]
[0171] In the formula, W initial α is the initial weight, and α is the decay coefficient.
[0172] Global search: Update the position of individual butterflies using adaptive weight coefficients W(t):
[0173]
[0174] In the formula: r is a random number, f i It refers to the intensity of the scent of an individual butterfly.
[0175] Local search: Update the position of individual butterflies using adaptive weight coefficients W(t):
[0176]
[0177] In the formula: and It refers to the positions of two randomly selected butterfly individuals;
[0178] Step S4: For the current globally optimal solution X bestApply the Cauchy mutation operator to generate a new optimal solution X. newbest :
[0179] X newbest =X best +cauchy(0,1) (18)
[0180] In the formula: cauchy(0,1) is the standard Cauchy distribution function.
[0181] This process fine-tunes the currently found global optimal solution to make it converge to the optimal parameters more accurately, so the variation is small and avoids excessive perturbation that could lead to deviation from the optimal solution.
[0182] Step S5: Update the global optimal solution;
[0183] Compare the newly generated optimal solution X newbest and the current global optimal solution X best Choose the solution with the highest fitness as the new global optimal solution;
[0184] Step S6: Repeat steps 3-5 until the maximum number of iterations t is reached. max .
[0185] Step S7: Output the optimal parameters (L) * W * ,b * The optimal number of hidden layer nodes, L, is... * Weight matrix W * The dimension and bias vector b * The dimension. In this embodiment, the number of hidden layer nodes in the optimized Extreme Learning Machine (ELM) model is L. * =50, weight matrix W * The dimension is 10×50 and the bias vector is b. * The dimension is 50×1.
[0186] Step 6: Construct a hyperspectral prediction model for NH4 using the optimized ELM model. + -N content is predicted; the feature bands selected by the feature band selection algorithm are set as independent variables, NH4 + With NH4+ content as the dependent variable, a hyperspectral prediction model for NH4+ was constructed using the optimized ELM model. + Predicting -N content;
[0187] The characteristic band combination D = {(x v ,y v ):v=1,…,s,x v ∈R e ,y v∈R}, that is, s soil samples with feature dimension e, x v Let y represent the feature vector of the v-th sample, with dimension e, which contains all feature information related to the v-th sample; v The NH4+ of the v-th sample in the set of measured data representing the spectral characteristics of soil samples and their corresponding ammonium nitrogen content. + The true value of -N content;
[0188] definition NH4 in soil sample + Predicted values for -N content:
[0189]
[0190] Where F is the model function of ELM. The goal of ELM is to improve the prediction accuracy of the model by randomly generating hidden layer weights and biases and minimizing the objective function by minimizing the output layer weights.
[0191] The objective function of ELM is defined as:
[0192]
[0193] Where Obj is the objective function, and l represents the loss function used to measure the predicted value. Compared with the true value y v The difference; to avoid overfitting, Ω(f) is a regularization term that defines the complexity of the model:
[0194]
[0195] Where w represents the weights of the output layer of the ELM model, and λ is the regularization parameter.
[0196] The training process of ELM is completed through a single forward propagation; assuming the number of hidden layer nodes is K and the hidden layer weight matrix is W∈R e×K The hidden layer bias vector is b∈R K If the activation function of the hidden layer is h(·), then the output matrix H of the hidden layer is:
[0197]
[0198] Where X is the input feature matrix, and H∈R s×K This is the output matrix of the hidden layer;
[0199] The output layer weights w of the ELM model are solved using the least squares method:
[0200]
[0201] in, H is the pseudo-inverse of the hidden layer output matrix H, and Y is the true value vector.
[0202] Ultimately, the predicted values output by the ELM model for:
[0203]
[0204] To avoid overfitting, a regularization term is introduced into the objective function. By introducing the regularization parameter λ, the objective function of ELM is rewritten as:
[0205]
[0206] Taking the derivative of the objective function above and setting it to zero yields the optimal solution w for the output layer weights. * :
[0207]
[0208] Where I is the identity matrix.
[0209] In this embodiment, in order to evaluate NH4 + The performance of the hyperspectral prediction model for -N content was evaluated using root mean square error (RMSE) and coefficient of determination (R²). 2 R and relative percentage deviation (RPD) are used as indicators to evaluate the accuracy and stability of the model. 2 The primary quantification is the correlation between the model's predicted and actual values. A value closer to 1 indicates a stronger correlation and better model performance. RMSE measures the root mean square of the difference between predicted and observed values. A smaller RMSE value indicates smaller prediction errors and better model performance. RPD provides a measure of model accuracy. When RPD ≤ 1.4, the model's accuracy is low, making it almost impossible to accurately estimate the sample. When 1.4 ≤ RPD < 2, the model's accuracy allows for a rough estimate of the sample. When RPD ≥ 2, the model's accuracy is higher, enabling better estimation of the sample. The theoretical formula is as follows:
[0210]
[0211] Where n is the number of samples, y i It is a measured value, Y i It is a predicted value. SD is the average of the measured values, and SD is the standard deviation of the analyzed sample.
[0212] ELM is an efficient single-hidden-layer feedforward neural network model suitable for solving regression problems. The ELM method is used to construct NH4. +The process of developing a hyperspectral prediction model for NH4 content is as follows: First, the feature variables used to train the model are determined, and key parameters such as the number of hidden layer neurons and the type of activation function in the ELM algorithm are set. Then, the model is trained using a training set. This is achieved by randomly generating connection weights and biases from the input layer to the hidden layer and analytically calculating the weights from the hidden layer to the output layer, thus rapidly building the model. During training, the ELM algorithm does not require iterative weight adjustments, resulting in extremely fast training speed. Finally, cross-validation is used to evaluate the model's performance, and model parameters such as the number of hidden layer neurons and the type of activation function are adjusted to improve prediction accuracy, ultimately yielding a reliable NH4 content prediction model. + -N content hyperspectral prediction model.
[0213] This embodiment also compares the RF, SVM, and ELM models with the ELM model after parameter optimization using the SA, BOA, and IBOA algorithms. The model construction results based on the SFS dataset are shown in Table 2.
[0214] Table 2 Modeling Results
[0215]
[0216] By optimizing the model parameters, the IELM model exhibits excellent performance on both the training and validation sets. Specifically, the optimized IELM model achieves higher R-values on the training set. 2 The R-value reached 0.89 on the validation set. 2 The value increased to 0.92, both of which significantly outperformed the other three comparative models. This result indicates that the optimized model has stronger generalization ability and can better adapt to new data. In error analysis, the root mean square error (RMSE) of the optimized model on the training and validation sets decreased to 0.95 and 1.04, respectively, indicating a significant improvement in prediction accuracy. Furthermore, the relative analysis error (RPD) of the model significantly increased from 1.58 for the SELM model to 3.48, further confirming the significant improvement in the model's predictive performance. The parameter optimization process not only improved the prediction accuracy of the IELM model but also enhanced its generalization ability, enabling the model to exhibit better stability and reliability in practical applications. Figure 5 The model prediction results based on the SFS dataset are presented, intuitively reflecting the superior performance of the optimized model.
[0217] In summary, the IELM model with optimized parameters using the IBOA algorithm significantly outperforms models on other datasets on the validation set, demonstrating better prediction performance and generalization ability.
[0218] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.
Claims
1. A hyperspectral prediction method for soil ammonium nitrogen content based on an improved extreme learning machine, characterized in that: Includes the following steps: Step 1: Collect and process soil samples for soil spectral measurements and NH4. + -N content determination; Step 2: Measure soil spectral reflectance data; Step 3: Preprocess the soil spectral reflectance data to form a spectral reflectance dataset; and use the KS algorithm to randomly divide the spectral reflectance dataset into a training set and a test set. Step 4: Select spectral feature bands: Use a sequential forward selection algorithm to select feature bands; Step 5: The parameters of the Extreme Learning Machine (ELM) model are optimized using the improved butterfly optimization algorithm IBOA, thereby constructing a model for predicting soil NH4. + A hyperspectral prediction model for -N content was developed, and the model was validated. Step 6: Construct a hyperspectral prediction model for NH4 using the optimized ELM model. + Predicting -N content; The characteristic bands selected by the characteristic band selection algorithm are set as independent variables, NH4 + With NH4+ content as the dependent variable, a hyperspectral prediction model for NH4+ was constructed using the optimized ELM model. + -N content is predicted.
2. The method for hyperspectral prediction of soil ammonium nitrogen content based on improved extreme learning machine according to claim 1, characterized in that: Step 3, the preprocessing of soil spectral reflectance data, includes: firstly, using the Savitzky-Golay smoothing method to denoise the soil spectral reflectance data to obtain the original spectral reflectance data; and then further performing a first-order differential transform on the original spectral reflectance data.
3. The method for hyperspectral prediction of soil ammonium nitrogen content based on improved extreme learning machine according to claim 2, characterized in that: Step 4 describes the process of selecting feature bands using the sequential forward selection algorithm: (1) Initialize feature subset: Initialize an empty feature subset. And a candidate set C = F containing all characteristic bands of the preprocessed spectral reflectance data, where F is the set of all characteristic bands of the preprocessed spectral reflectance data; (2) Feature band selection: For each candidate feature band f in the candidate set C i ∈C, i=1,2,…,m′, where m′ is the number of candidate feature bands in the candidate set C, and the following steps are performed: a. Select candidate feature bands f i Adding it to the feature subset S results in a new feature subset S′=S∪{f i }; b. Build an Extreme Learning Machine (ELM) model on the training set using a feature subset S′, and calculate the RMSECV value of the ELM model using 5-fold cross-validation, denoted as RMSECV. i ; Select RMSECV i The smallest characteristic band f best , will f best Remove from candidate set C to obtain a new candidate set C′, and set f best Add it to the feature subset S to obtain a new feature subset S″; (3) Iteration process: Repeat step (2) until the candidate set is empty or the predetermined number of feature bands is reached, and the iteration ends; in each iteration, decide whether to retain the feature band based on the improvement of the performance of the added feature band on the Extreme Learning Machine (ELM) model. (4) Final feature band selection: When the algorithm ends, the feature subset obtained is the final selected feature band set D.
4. The method for hyperspectral prediction of soil ammonium nitrogen content based on improved extreme learning machine according to claim 3, characterized in that: The improved butterfly optimization algorithm uses the Tent chaotic map to optimize the initial butterfly individual position and employs adaptive weight coefficients and the Cauchy mutation operator to optimize the butterfly position update process. The specific process is as follows: 1) Initialize the population using a Tent chaotic sequence; generate chaotic sequences based on Tent mappings. The process is as shown in the following formula: In the formula: u k The numbers are random numbers in the range [0,1]; k is the population size; i is the current iteration number; Based on the chaotic sequence generated above, initialize the initial position sequence of the individual butterflies. as follows: In the formula: These are the upper and lower limits of the initial position sequence of the individual butterflies, respectively; It is a sequence containing multiple positions that is related to both the number of iterations and the number of individuals in the population. i represents the current iteration number, and different position information will be generated as i changes; k is the population size, and different position sequences will also be generated for different population individuals. 2) The search strategy is updated using a dynamic adjustment mechanism based on adaptive weight coefficients; The adaptive weight coefficients change continuously with the increase of the number of iterations, and combine the position information of the current individual, the globally optimal individual, and the randomly selected individual to dynamically control the movement direction and distance of the current butterfly individual; The expression for the adaptive weighting coefficient is: In the formula: t max The maximum number of iterations is given by W(t), where W(t) is the weight coefficient at the t-th iteration. Based on adaptive weight coefficients, the formula for updating the individual position during the global search process is: Based on adaptive weight coefficients, the formula for updating the individual position during the local search process is: 3) Apply the Cauchy mutation operator to the optimal solution in the current iteration; the new optimal solution obtained after Cauchy mutation is shown in the following formula: X newbest =X best +X best *cauchy(0,1) In the formula: X newbest X is the new optimal solution obtained by Cauchy mutation of the optimal solution in the current iteration; best This represents the optimal solution obtained in the current iteration; cauchy(0,1) is the standard Cauchy distribution function.
5. The method for hyperspectral prediction of soil ammonium nitrogen content based on improved extreme learning machine according to claim 4, characterized in that: The process of optimizing the parameters of the Extreme Learning Machine (ELM) model using the improved butterfly optimization algorithm IBOA is as follows: Step S1: Define the search space and initialize the butterfly population; Step S11: Define the search space: Set the range of the number of hidden layer nodes L in the ELM model to [L... min ,L max The weight matrix W has a dimension of L×d, where d is the dimension of the input features. The dimension of the bias vector b is L×1; Step S12: Initialize the population: Initialize the positions of individual butterflies using the Tent chaotic map; each individual butterfly represents a set of parameters (L, W, b), and the position of the individual butterfly... As shown in the formula below: In the formula: It is a chaotic sequence generated by the Tent chaotic mapping; Step S2: Set the fitness function; Define the fitness function f(X) i ) represents the error of the ELM model on the validation set; Step S3: Update the position of the butterfly individual using adaptive weight coefficients W(t) in both the global and local searches; Step S4: For the current globally optimal solution X best Apply the Cauchy mutation operator to generate a new optimal solution X. newbest ; Step S5: Update the global optimal solution; Compare the newly generated optimal solution X newbest and the current global optimal solution X best Choose the solution with the highest fitness as the new global optimal solution; Step S6: Repeat steps S3-S5 until the maximum number of iterations t is reached. max ; Step S7: Output the optimal parameters (L) * W * ,b * ), which refers to the optimal number of hidden layer nodes, the dimension of the weight matrix W, and the dimension of the bias vector b.
6. The method for hyperspectral prediction of soil ammonium nitrogen content based on improved extreme learning machine according to claim 5, characterized in that: The specific method for step 6 is as follows: The characteristic band combination D = {(x v ,y v ):v=1,…,s,x v ∈R e ,y v ∈R}, that is, s soil samples with feature dimension e, x v Let y represent the feature vector of the v-th sample, with dimension e, which contains all feature information related to the v-th sample; v The NH4+ of the v-th sample in the set of measured data representing the spectral characteristics of soil samples and their corresponding ammonium nitrogen content. + The true value of -N content; definition NH4 in soil sample + Predicted values for -N content: Where F is the model function of ELM. The goal of ELM is to improve the prediction accuracy of the model by randomly generating hidden layer weights and biases and minimizing the objective function by minimizing the output layer weights. The objective function of the ELM model is defined as: Where Obj is the objective function, and l represents the loss function used to measure the predicted value. Compared with the true value y v The difference; to avoid overfitting, Ω(f) is a regularization term that defines the complexity of the model: Where w represents the weights of the output layer of the ELM model, and λ is the regularization parameter; The training process of the ELM model is completed through a single forward propagation; assuming the number of hidden layer nodes is K and the hidden layer weight matrix is W∈R e×K The hidden layer bias vector is b∈R K If the activation function of the hidden layer is h(·), then the output matrix H of the hidden layer is: H = h(XW + b) Where X is the input feature matrix, and H∈R s×K This is the output matrix of the hidden layer; The output layer weights w of the ELM model are solved using the least squares method: in, H is the pseudo-inverse of the hidden layer output matrix H, and Y is the true value vector. Ultimately, the predicted values output by the ELM model for: To avoid overfitting, a regularization term is introduced into the objective function; by introducing the regularization parameter λ, the objective function of the ELM model is rewritten as: Taking the derivative of the objective function above and setting it to zero yields the optimal solution w for the output layer weights. * : Where I is the identity matrix.
Citation Information
Cited By
Polarization hyperspectral water quality monitoring system and method
CN121740763A