Water quality evaluation model construction method based on fruit fly-whale collaborative optimization algorithm
By introducing the fruit fly-whale collaborative optimization algorithm in water quality evaluation, and optimizing the parameter combination of the support vector machine model, the problem of time-consuming and difficult to achieve real-time monitoring of traditional water quality evaluation methods is solved, and efficient and accurate water quality evaluation is achieved.
Patent Information
- Application Number
- CN202510179523.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-18
- Publication Date
- 2025-06-06
AI Technical Summary
Traditional water quality evaluation methods have problems such as long analysis, large resource investment and difficulty in real-time monitoring. The application of machine learning technology in water quality evaluation is limited by feature selection and model parameter tuning.
The water quality evaluation model construction method based on the fruit fly-whale collaborative optimization algorithm is adopted to screen key water quality parameter characteristics through information gain, and the parameter combination of the support vector machine model is optimized using the fruit fly-whale collaborative optimization algorithm.
It significantly improves the accuracy and efficiency of water quality evaluation, can complete the evaluation task of a large number of samples in a short time, is suitable for large-scale real-time monitoring scenarios, and enhances the adaptability and stability of the model.
Smart Images

Figure CN120106665A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of water quality evaluation, and in particular relates to a method for constructing a water quality evaluation model based on a fruit fly-whale collaborative optimization algorithm, which can be widely used in quality assessment and monitoring of various water bodies such as drinking water, surface water, and groundwater. Background Art
[0002] In today's context of accelerated industrialization and urbanization, water pollution is becoming increasingly severe, and accurate and efficient evaluation of water quality has become a key link in ensuring public health and ecological environmental stability. Traditional water quality evaluation methods mainly rely on laboratory chemical analysis, which has significant drawbacks. Not only is the analysis process time-consuming and requires a lot of manpower and material resources, but it is also difficult to meet the needs of real-time dynamic monitoring of water quality and cannot reflect sudden changes in water quality in a timely manner.
[0003] In recent years, the vigorous development of machine learning technology has brought new opportunities and changes to water quality assessment. Machine learning has shown great potential in data mining and prediction, and can handle complex multi-parameter data relationships. However, its effectiveness in water quality assessment applications is severely restricted by two key factors: one is feature selection. If the parameters that play a key role in water quality assessment cannot be accurately screened, the model will easily become complex and inefficient due to data redundancy; the other is model parameter tuning. Unreasonable parameter settings will lead to poor model performance.
[0004] Information gain, as an effective feature importance measurement tool, can identify the parameters that have a key influence on water quality classification based on the change in information entropy of the data, thereby simplifying the model structure and improving the prediction performance. As an emerging meta-heuristic global search algorithm, the whale optimization algorithm (WOA) has attracted attention for its advantages of simple operation and few control parameters, but in practical applications, it has problems such as slow convergence speed and difficulty in achieving the ideal convergence accuracy. In order to effectively overcome these defects, the present invention innovatively introduces the fruit fly optimization algorithm (FOA), and optimizes and improves the WOA with its fast convergence characteristics and excellent global search capabilities, thereby providing a new idea and method for the optimization of the core parameters of the support vector machine model (SVM), aiming to build an efficient and accurate water quality evaluation model. Summary of the invention
[0005] In order to overcome the shortcomings of the prior art, the purpose of the present invention is to provide a method for constructing a water quality assessment model based on the fruit fly-whale collaborative optimization algorithm, which can improve the accuracy and efficiency of water quality assessment, solve the shortcomings of traditional water quality assessment methods, and overcome the problems faced by existing machine learning technologies in water quality assessment applications, thereby being suitable for quality assessment of various water bodies and meeting the needs of large-scale real-time monitoring scenarios.
[0006] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0007] The present invention discloses a method for constructing a water quality evaluation model based on a fruit fly-whale collaborative optimization algorithm, comprising the following steps: S1, collecting water quality data containing multiple water quality parameters, and preprocessing the collected water quality data; S2, calculating the preprocessed water quality data through information gain and obtaining the information gain value of each water quality parameter, and determining key water quality parameter characteristics based on the obtained water quality parameter information gain value; S3, constructing a sample data set based on the determined key water quality parameter characteristics, and dividing the sample data set into a training sample set and a test sample set; S4, establishing a support vector machine model, and setting the penalty coefficient and kernel function parameters of the support vector machine as the parameter combination to be optimized; S5, based on the fruit fly-whale collaborative optimization algorithm, The method optimizes the parameter combination, which includes: S51, using the fruit fly optimization algorithm to optimize the penalty coefficient and kernel function parameters of the support vector machine, and obtaining the optimal solution of the fruit fly algorithm in a global range; S52, using the optimal solution of the fruit fly algorithm obtained based on the fruit fly optimization algorithm as the initial solution of the whale algorithm, and then using the spatial position corresponding to the best whale individual obtained based on the output of the whale algorithm as the optimal solution of the parameter combination of the support vector machine; S6, using the optimized parameter combination to configure the support vector machine to construct an original water quality evaluation model based on the support vector machine; S7, training and testing the original water quality evaluation model based on the training sample set and the test sample set in step S3 until the final water quality evaluation model is obtained.
[0008] Based on the above-disclosed steps, the water quality evaluation model constructed by the present invention has achieved significant breakthroughs in multiple core dimensions. In terms of accuracy improvement, on the one hand, information gain is used to accurately screen key water quality parameter features and remove redundant information, so that the model can focus on core influencing factors, effectively reduce interference, and significantly improve the accuracy of water quality evaluation. On the other hand, the parameters of the support vector machine are optimized by the fruit fly-whale collaborative optimization algorithm; the fruit fly optimization algorithm obtains a better solution with its global fast search capability, providing a good initial value for the whale algorithm, and the whale algorithm then simulates a variety of predation behaviors for in-depth search. The optimal parameter combination found by the synergistic effect of the two greatly improves the fitting effect of the support vector machine on water quality data, thereby greatly improving the accuracy of water quality classification and identification.
[0009] In terms of actual application performance, this model construction method uses machine learning algorithms to achieve automated evaluation. After the information gain screening feature is used, the model structure is simplified. The optimized support vector machine model has reduced computational complexity and greatly improved processing speed. It can complete the evaluation task of a large number of samples in a short time, providing strong support for large-scale real-time monitoring scenarios. At the same time, the adaptability and stability of the model have also been enhanced. The whale optimization algorithm originally had the problem of slow convergence and easy to fall into local optimality. The fruit fly optimization algorithm has fast convergence and good global search capabilities. After the combination of the two, the fruit fly optimization algorithm widely explores the solution space in the early stage, helping the whale optimization algorithm to avoid falling into local optimality too early, accelerating the convergence speed, and significantly enhancing the adaptability of the model to different water quality conditions and complex data. It improves the stability and reliability of the algorithm and ensures that it can maintain high performance in various water quality evaluation tasks. In addition, the original model is repeatedly trained and tested through the training sample set and the test sample set, and the model parameters are continuously adjusted, which effectively improves the generalization ability of the model and makes it more capable of predicting new collected data.
[0010] At the system integration level, the water quality evaluation model of the present invention can be seamlessly connected to the existing water quality monitoring platform, effectively solving the problem of poor compatibility between the model and the monitoring platform in the existing technology, and providing the possibility of realizing the integration of water quality monitoring and evaluation. This will not only help promote the development of water resources management towards informatization and intelligence, but also further improve the efficiency and accuracy of water resources management, and provide more powerful technical support for water resources protection and rational utilization.
[0011] Furthermore, step S51 includes: S5101, setting the penalty coefficient of the support vector machine and the value range of the kernel function parameter, and setting the fruit fly population size and the initial flight radius; S5102, randomly generating the position of the fruit fly individual according to the set initial flight radius, and each fruit fly individual represents a set of parameter combinations; S5103, training the support vector machine for each fruit fly individual using the key water quality parameter characteristic sample data set of step S3, and calculating its fitness value; S5104, sorting all the fruit fly individuals according to the size of the fitness value, recording the parameter combination with the smallest fitness value, and taking it as the optimal solution of the fruit fly algorithm.
[0012] In the present invention, the parameter value range, the size of the fruit fly population and the initial flight radius are set to provide a basis for the generation of fruit fly individuals. The representative parameter combination of the fruit fly individual position is randomly generated, and the support vector machine is trained using the key water quality parameter characteristic sample data set and the fitness value is calculated. The optimal solution is obtained according to the fitness sorting, and the global preliminary optimization of the support vector machine parameters is achieved, providing a better initial solution for the whale algorithm.
[0013] Further, step S52 includes: S5201, setting the initialization whale population size and the maximum number of iterations; S5202, based on the optimal solution of the fruit fly algorithm determined in step S5104, updating and iterating the position of each whale individual according to the whale algorithm update rule; S5203, recalculating the new fitness value of each whale individual after each iterative update, and comparing the new fitness value with the previous old fitness value, updating the global optimal whale individual spatial position as the global optimal parameter combination; S5204, judging whether the iteration reaches the preset maximum number of iterations, when it is judged as yes, outputting the current global optimal parameter combination as the optimal solution of the parameter combination, and when it is judged as no, starting step S5202 again.
[0014] In the present invention, the whale population size and the maximum number of iterations are set, the optimal solution of the fruit fly algorithm is used as the initial value, the individual position is updated according to the whale algorithm rules, the new fitness value is calculated and compared after each iteration, the global optimal position is updated, and a better solution is searched through multiple iterations. When the maximum number of iterations is reached, the optimal parameter combination is output, so as to achieve deep optimization of the support vector machine parameters and improve the model performance.
[0015] Furthermore, in step S5204, the fitness value of the optimal whale individual is outputted as a performance indicator.
[0016] In the present invention, when outputting the optimal parameter combination, the optimal individual whale fitness value is also output as a performance indicator, which provides a quantitative basis for model performance evaluation, facilitates comparison of different parameter combinations and model training effects, and helps to further optimize the model.
[0017] Furthermore, the whale algorithm update rule in step S5202 includes an update rule for simulating the shrinking and encircling of a whale group, which includes: introducing a random number p, when p < 0.5 and |A| < 1, according to the formula X(t+1) = X * (t)-A·D 1 Update the individual position of the whale; where D 1 =|C·X * (t)-X(t)|, t is the current iteration number, X * is the position vector of the current best solution, X * is the position vector of the individual whale, D 1 is the distance between the individual whale and its prey, || is the absolute value, . is the element-by-element multiplication, and A and C are coefficient vectors.
[0018] Furthermore, the whale algorithm update rule in step S5202 also includes an update rule for simulating the spiral decline of the whale group, which includes: when p≥0.5, according to the formula X(t+1)=D 2 ·e bl ·cos(2πl)+X* (t) Update the individual position of the whale; where D 2 =|X * (t)-X(t)|,D 2 is the distance from the individual whale to its prey, b is a constant, and l is a random number in [-1, 1].
[0019] Furthermore, the whale algorithm update rule in step S5202 also includes an update rule for simulating the global wandering and foraging of a whale group, which includes: when p < 0.5 and |A| ≥ 1, according to the formula X(t+1) = X rand -A.D rand Update the individual position of the whale; where D rand =|C·X rand -X(t)|,X rand represents the position vector of a whale randomly selected from the group, D rand represents the distance from a randomly selected individual whale to its prey.
[0020] In the present invention, when the conditions p < 0.5 and |A| < 1 are met, according to the formula X(t+1) = X * (t)-A·D 1 Update the position of individual whales, simulate the behavior of whales shrinking and surrounding prey, make individual whales approach the current best solution, explore better solution space, improve the local search ability of the algorithm, and optimize the support vector machine parameters; when the condition p≥0.5 is met, according to the formula X(t+1)=D 2 ·e bl ·cos(2πl)+X * (t) Update the individual position of the whale, simulate the spiral descent predation behavior of the whale, combine the logarithmic spiral shape and random numbers, explore new solutions near the current optimal solution, increase the diversity of solutions, and enhance the ability of the algorithm to jump out of the local optimum and find the global optimal solution; when p < 0.5 and |A| ≥ 1 are met, according to the formula X(t+1) = X rand -A.D rand Update the individual positions of whales, and realize global wandering and foraging by randomly selecting individual whales, so as to avoid the algorithm from falling into local optimality, expand the search range, enhance the global search ability of the algorithm, and find a better parameter combination.
[0021] Furthermore, the water quality parameters include permanganate index, ammonia nitrogen, total nitrogen, total phosphorus, turbidity and conductivity; the step of preprocessing the collected water quality parameters includes: after removing abnormal data, normalizing the data of each water quality parameter.
[0022] In the present invention, the types of water quality parameters are clarified to provide direction for data collection, while the preprocessing step ensures data reliability and consistency, enabling the model to better learn data features and improve model stability and prediction accuracy.
[0023] The present invention also discloses a system for realizing the method for constructing a water quality evaluation model based on the fruit fly-whale collaborative optimization algorithm disclosed in the present invention, comprising:
[0024] A data collection unit, which is configured to collect water quality data including a plurality of water quality parameters and pre-process the collected water quality data;
[0025] A key feature determination unit is configured to calculate the pre-processed water quality data through information gain and obtain information gain values of each water quality parameter, and determine key water quality parameter features based on the obtained water quality parameter information gain values;
[0026] A data set construction unit, which is constructed to construct a sample data set based on the determined key water quality parameter characteristics and divide it into a training sample set and a test sample set;
[0027] A support vector machine establishment unit, which is constructed to establish a support vector machine model and set the penalty coefficient and kernel function parameters of the support vector machine as a parameter combination to be optimized;
[0028] The parameter combination optimization unit is constructed to optimize the parameter combination based on the fruit fly-whale collaborative optimization algorithm, and includes:
[0029] A fruit fly algorithm optimization unit, which is constructed by using the fruit fly optimization algorithm to optimize the penalty coefficient and kernel function parameters of the support vector machine, and obtain the optimal solution of the fruit fly algorithm in a global range;
[0030] The whale algorithm optimization unit is constructed to use the optimal solution of the fruit fly algorithm obtained based on the fruit fly optimization algorithm as the initial solution of the whale algorithm, and then use the spatial position corresponding to the best whale individual obtained based on the output of the whale algorithm as the optimal solution of the parameter combination of the support vector machine;
[0031] A model building unit, which uses the optimized parameter combination to configure the support vector machine to construct an original water quality evaluation model based on the support vector machine;
[0032] The training and testing unit trains and tests the original water quality evaluation model based on the training sample set and the test sample set in the data set construction unit until the final water quality evaluation model is obtained.
[0033] In the present invention, the various units of the system divide the work and cooperate with each other. The data collection unit is responsible for data collection and preprocessing, the key feature determination unit screens key features, the data set construction unit constructs and divides the data set, the support vector machine establishment unit builds the model, the parameter combination optimization unit optimizes the parameters, the model construction unit configures the model, and the training and testing unit trains and tests the model, thereby realizing the automation and systematization of water quality evaluation model construction and improving development efficiency and model quality.
[0034] The present invention also discloses an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the water quality evaluation model construction method based on the fruit fly-whale collaborative optimization algorithm disclosed in the present invention.
[0035] Compared with the prior art, the present invention has the following beneficial effects:
[0036] 1) Traditional methods do not fully screen features, resulting in redundant information in the model, which affects accuracy. The present invention uses information gain to calculate the information gain value of each parameter for preprocessed water quality data, accurately determines the characteristics of key water quality parameters, and after removing redundant parameters, the model focuses on core factors, avoids interference from irrelevant information, and significantly improves the accuracy of water quality evaluation; in addition, existing machine learning methods have deficiencies in model parameter tuning. The present invention uses the fruit fly-whale collaborative optimization algorithm to optimize the support vector machine parameters. The fruit fly optimization algorithm relies on its fast convergence and global search capabilities to obtain a better parameter combination in a global range, providing a good initial solution for the whale algorithm; the whale algorithm is further optimized by simulating a variety of predation behaviors, and the optimal parameter combination found by the synergistic effect of the two enables the support vector machine to better fit the water quality data, greatly improving the accuracy of water quality classification and identification.
[0037] 2) Traditional water quality evaluation relies on laboratory analysis, which is time-consuming, costly and difficult to monitor in real time. The present invention uses machine learning algorithms to achieve automated evaluation, simplifies the model structure through information gain screening features, and reduces computational complexity; the processing speed of the optimized support vector machine model is significantly improved, and a large number of samples can be evaluated in a short time, meeting the needs of large-scale real-time monitoring and providing water quality information in a timely manner.
[0038] 3) The whale optimization algorithm has the problems of slow convergence and easy to fall into local optimality, while the fruit fly optimization algorithm has the advantages of fast convergence and global search. The present invention combines the two. The fruit fly optimization algorithm widely explores the solution space in the early stage, provides high-quality initial solutions for the whale optimization algorithm, avoids it from falling into local optimality too early, and accelerates the convergence speed. The two algorithms complement each other, enhance the adaptability of the model to different water quality conditions and complex data, improve the algorithm stability and reliability, and ensure that the model maintains high performance in complex water quality evaluation tasks; and, through the training sample set and the test sample set, the original water quality evaluation model is repeatedly trained and tested, and the model parameters are continuously adjusted. Compared with the existing model that has not been fully trained and tested, the model constructed by the present invention has a stronger generalization ability, can better adapt to water quality data in different scenarios, and has a more accurate prediction ability for newly collected data.
[0039] 4) The existing technology may have the problem of poor compatibility between the model and the monitoring platform. The water quality evaluation model constructed by the present invention can be seamlessly connected to the existing water quality monitoring platform, provide technical support for smart water affairs, realize the integration of water quality monitoring and evaluation, and promote the development of water resources management towards informatization and intelligence.
[0040] The method for constructing a water quality evaluation model based on the fruit fly-whale collaborative optimization algorithm of the present invention is disclosed in detail below in conjunction with the embodiments shown in the accompanying drawings and the accompanying figure numerals. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 The present invention is a flowchart of the steps of the method for constructing a water quality evaluation model based on the fruit fly-whale collaborative optimization algorithm.
[0042] Figure 2 It is a schematic diagram of the process of constructing the water quality evaluation model of the present invention.
[0043] Figure 3 This is a diagram of the whale predation contraction and encirclement mechanism of the present invention.
[0044] Figure 4 This is a diagram of the spiral renewal mechanism of whale predation in the present invention. DETAILED DESCRIPTION
[0045] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present invention. It should be noted that the embodiments in this application and the features in the embodiments can be combined with each other without conflict.
[0046] Figure 1 The following is a flow chart of the steps of the method for constructing a water quality evaluation model based on the fruit fly-whale collaborative optimization algorithm of the present invention. Figure 1 As shown, the present invention discloses a method for constructing a water quality evaluation model based on a fruit fly-whale collaborative optimization algorithm, comprising the following steps:
[0047] S1, collect water quality data containing multiple water quality parameters, and pre-process the collected water quality data; S2, calculate the pre-processed water quality data through information gain and obtain the information gain value of each water quality parameter, and determine the key water quality parameter characteristics based on the obtained water quality parameter information gain value; S3, construct a sample data set based on the determined key water quality parameter characteristics, and divide it into a training sample set and a test sample set; S4, establish a support vector machine model, and set the penalty coefficient and kernel function parameters of the support vector machine as the parameter combination to be optimized; S5, optimize the parameter combination based on the fruit fly-whale collaborative optimization algorithm, which includes: S51, collect The penalty coefficient and kernel function parameters of the support vector machine are optimized by the fruit fly optimization algorithm to obtain the optimal solution of the fruit fly algorithm globally; S52, the optimal solution of the fruit fly algorithm obtained based on the fruit fly optimization algorithm is used as the initial solution of the whale algorithm, and then the spatial position corresponding to the best whale individual obtained based on the output of the whale algorithm is used as the optimal solution of the parameter combination of the support vector machine; S6, the support vector machine is configured using the optimized parameter combination to construct an original water quality evaluation model based on the support vector machine; S7, the original water quality evaluation model is trained and tested based on the training sample set and the test sample set in step S3 until the final water quality evaluation model is obtained.
[0048] The present invention provides a complete water quality assessment model construction process based on the fruit fly-whale collaborative optimization algorithm. By collecting and preprocessing multiple water quality parameter data, using information gain to screen key features, combining the fruit fly-whale algorithm to optimize support vector machine parameters, and finally training and testing to obtain the final model, the accuracy and efficiency of water quality assessment can be effectively improved, and it is suitable for a variety of water quality assessment scenarios.
[0049] In a preferred embodiment, step S51 includes: S5101, setting the penalty coefficient and kernel function parameter value range of the support vector machine, and setting the fruit fly population size and initial flight radius; S5102, randomly generating the position of the fruit fly individual according to the set initial flight radius, and each fruit fly individual represents a set of parameter combinations; S5103, training the support vector machine for each fruit fly individual using the key water quality parameter characteristic sample data set of step S3, and calculating its fitness value; S5104, sorting all fruit fly individuals according to the fitness value, recording the parameter combination with the smallest fitness value, and taking it as the optimal solution of the fruit fly algorithm. In this embodiment, by reasonably setting the parameter value range, the fruit fly population size and the initial flight radius, randomly generating the position of the fruit fly individual and training and calculating the fitness value, and finally determining the optimal solution of the fruit fly algorithm, a good initial solution is provided for the subsequent whale algorithm, which helps to speed up the overall optimization process and improve the efficiency of model construction.
[0050] In a preferred embodiment, step S52 includes: S5201, setting the initialization whale population size and the maximum number of iterations; S5202, based on the optimal solution of the fruit fly algorithm determined in step S5104, updating and iterating the position of each whale individual according to the whale algorithm update rule; S5203, recalculating the new fitness value of each whale individual after each iteration update, and comparing the new fitness value with the previous old fitness value, updating the global optimal whale individual spatial position as the global optimal parameter combination; S5204, judging whether the iteration reaches the preset maximum number of iterations, when it is judged to be yes, then outputting the current global optimal parameter combination as the optimal solution of the parameter combination, and when it is judged to be no, then starting step S5202 again. In this embodiment, the appropriate whale population size and the maximum number of iterations are set, the whale individual position is continuously updated, the fitness value is calculated and the global optimal position is compared and updated, and finally the optimal solution of the parameter combination is determined, which enhances the adaptability and optimization ability of the model to different water quality data, and improves the stability and reliability of the model.
[0051] In a preferred embodiment, in step S5204, the fitness value of the best individual whale is output as a performance indicator. In this embodiment, the fitness value of the best individual whale is output as a performance indicator, which is convenient for intuitively evaluating the model optimization effect and performance, providing a reference for further improving the model, and helping to improve the model quality.
[0052] In a preferred embodiment, the whale algorithm update rule in step S5202 includes an update rule for simulating the shrinking and encircling of a whale group, which includes: introducing a random number p, when p < 0.5 and |A| < 1, according to the formula X(t+1) = X * (t)-A·D 1 Update the individual position of the whale; where D 1 =|C·X * (t)-X(t)|, t is the current iteration number, X * is the position vector of the current best solution, X * is the position vector of the individual whale, D 1 is the distance between the individual whale and the prey, || is the absolute value, · is the element-by-element multiplication, and A and C are coefficient vectors. In this embodiment, the update rule of shrinking and encircling the whale group is simulated, and the position of the individual whale is updated according to a specific formula under specific conditions, which helps the whale algorithm to perform accurate search in the local area, improves the convergence accuracy, enables the model to more accurately find the optimal parameter combination, and improves the accuracy of water quality evaluation.
[0053] In a preferred embodiment, the whale algorithm update rule in step S5202 also includes an update rule for simulating the spiral decline of the whale group, which includes: when p≥0.5, according to the formula X(t+1)=D2 ·e bl ·cos(2πl)+X * (t) Update the individual position of the whale; where D 2 =|X * (t)-X(t)|,D 2 is the distance from the individual whale to the prey, b is a constant, and l is a random number in the range of [-1, 1]. In this embodiment, the spiral descent update rule of the whale group is simulated, and the position is updated according to the corresponding formula, which further enriches the search strategy of the whale algorithm, enables it to explore more comprehensively in the solution space, and increases the probability of finding the global optimal solution, thereby improving the optimization effect of the model and the reliability of water quality evaluation.
[0054] In a preferred embodiment, the whale algorithm update rule in step S5202 also includes an update rule for simulating the global wandering and foraging of a whale group, which includes: when p < 0.5 and |A| ≥ 1, according to the formula X(t+1) = X rand -A.D rand Update the individual position of the whale; where D rand =|C·X rand -X(t)|,X rand represents the position vector of a whale randomly selected from the group, D rand Indicates the distance from a randomly selected individual whale to its prey. In this embodiment, the update rule of global wandering and foraging of a group of whales is simulated, and the position of individual whales is updated under specific conditions, which enhances the global search capability of the whale algorithm and avoids falling into the local optimum. Combined with other update rules, the robustness of the algorithm and its ability to handle complex water quality data are improved.
[0055] In a preferred embodiment, the water quality data is collected at different locations and depths of the target water body. In this embodiment, the water bodies at different locations and depths have different conditions such as light, temperature, dissolved oxygen, etc., which will lead to differences in biological activities and chemical reactions, thereby affecting the water quality parameters. By collecting data at multiple locations and depths, it is possible to cover various changes in the water body, present the overall water quality characteristics of the target water body more comprehensively and accurately, avoid misjudgment of water quality due to one-sided data, and enable the model to be exposed to water quality data patterns under different environmental conditions during the learning process, so as to better adapt to various actual scenarios, enhance the generalization performance of the model under different water conditions, and improve its reliability and practicality.
[0056] In a specific embodiment, the water quality parameters include permanganate index, ammonia nitrogen, total nitrogen, total phosphorus, turbidity and conductivity. In this embodiment, by clarifying common water quality parameters, the model construction is more targeted and applicable to common indicator analysis in actual water quality monitoring.
[0057] In a preferred embodiment, the step of preprocessing the collected water quality parameters includes: after removing abnormal data, normalizing the water quality parameter data. In this embodiment, removing abnormal data and normalizing the collected water quality parameters can effectively improve data quality, reduce the impact of abnormal data on the model, and improve the accuracy and stability of the model.
[0058] Specifically, the abnormal data that obviously deviates from the normal range is eliminated, such as the data with the permanganate index exceeding 10 times the normal upper limit of a specific water type. The water quality parameter data are normalized by using the min-max normalization method to map the data to the [0, 1] interval, and the formula is: Where X norm is the normalized value, X is the original value, and X min and X max They are the minimum and maximum values in the parameter data respectively.
[0059] The water quality evaluation model construction method based on the fruit fly-whale collaborative optimization algorithm provided by the present invention aims to improve the accuracy and efficiency of water quality assessment through a series of steps. Figure 2 The water quality assessment model flow chart shown covers the complete process from data collection and preprocessing, to feature selection, algorithm optimization, and then to model construction and evaluation. The specific steps are as follows:
[0060] 1. Initialize related parameters, initial population, and initial flight radius: Set the support vector machine parameter C (penalty coefficient) to [0.01, 100], and the g (kernel function parameter γ) to [0.001, 10]. Set the whale population size to 40 and the maximum number of iterations to T. max is 150. The fruit fly population size is determined to be 60 and the initial flight radius is 8.
[0061] 2. Data preprocessing: Collect water quality data from multiple drinking water sources, surface water monitoring points, and groundwater wells in a city. The collected water quality data are located at different locations and depths, including parameters such as permanganate index, ammonia nitrogen, total nitrogen, total phosphorus, turbidity, and conductivity. Abnormal data that deviates significantly from the normal range is eliminated. For example, data with a permanganate index that exceeds the normal upper limit of a specific water type by 10 times is considered abnormal and eliminated. Subsequently, the data of each water quality parameter is normalized using the formula Where X norm is the normalized value, X is the original value, and X min and X max They are the minimum and maximum values in the parameter data respectively.
[0062] 3. Calculate the information gain value of water quality indicators: Use the information gain algorithm to calculate the pre-processed water quality data. Divide the water quality into different levels as classification labels, and calculate the information gain value of each water quality parameter when distinguishing different water quality levels. Suppose that after calculation, it is found that the information gain values of ammonia nitrogen, total phosphorus and conductivity are relatively high.
[0063] 4. Select features with larger information gain values as input: According to the calculation results of the information gain value, the three parameters with larger information gain values, ammonia nitrogen, total phosphorus and conductivity, are selected as key features for subsequent model construction and training.
[0064] 5. Update the optimal solution according to the fruit fly algorithm: According to the set initial flight radius, the position of the fruit fly individual is randomly generated within the range of the support vector machine parameter value. Each fruit fly individual represents a set of [C, g] parameter combinations. For example, the parameter combination corresponding to fruit fly individual B is [2, 0.5]. Use the selected key features to train the support vector machine model, and use the inverse of the mean square error of the model on the cross-validation set as the fitness value calculation indicator. The smaller the mean square error, the greater the fitness value. Sort the fitness values of all fruit fly individuals, and record the parameter combination with the largest fitness value as the current optimal solution.
[0065] 6. Use the optimal solution of the fruit fly algorithm as the initial solution of the whale algorithm and start executing the whale algorithm: pass the optimal parameter combination obtained by the fruit fly algorithm to the whale algorithm as the initial solution. In the iterative process of the whale algorithm, set a random number p, and determine the update method of the whale individual according to the value of p and the correlation coefficient in each iteration.
[0066] 7. Fruit fly optimized whale algorithm optimizes the penalty coefficient C and kernel function parameter g: During the iteration of the whale algorithm, the individual positions of the whales are continuously updated in combination with the optimal solution of the fruit fly algorithm. When the individual positions of the whales are updated, the new parameter combination [C, g] must be ensured to be still within the set value range. Continue iterative optimization until the termination condition is met.
[0067] 8. Construct a water quality evaluation model: When the whale algorithm reaches the maximum number of iterations or meets other termination conditions (such as the fitness value change is less than 0.001 for 10 consecutive iterations), the spatial position corresponding to the best whale individual is output, that is, the optimal support vector machine parameters C and g. Use this set of optimal parameters to configure the support vector machine and construct a water quality evaluation model.
[0068] 9. Calculate individual fitness values, update optimal fitness values and optimal positions: During the algorithm iteration process, both fruit flies and whales need to calculate their fitness values after each position update. Compare the new fitness value with the previous optimal fitness value. If the new value is better, update the optimal fitness value and the corresponding optimal position.
[0069] 10. Output model evaluation results: Use the constructed water quality evaluation model to evaluate the test samples, and output the model's evaluation indicators, including classification indicators such as accuracy, precision, and recall, as well as regression indicators such as root mean square error and mean absolute error (if it is water quality grade prediction, use classification indicators; if it is water quality parameter prediction, use regression indicators). At the same time, evaluate the time efficiency of the model in processing data, record the time required for the model to evaluate a certain number of test samples, and complete the overall evaluation of the model application effect.
[0070] Figure 3 In the embodiment shown, during the iterative process of the whale algorithm, assuming that the current iteration number t=20, the position vector X of the current best solution * (20), assuming that the penalty coefficient C of the corresponding support vector machine is 3.5, the kernel function parameter g is 0.7, and the vector is represented by X * (20) = [3.5, 0.7]. The penalty coefficient C corresponding to the current position vector X(20) of a whale individual is 3.0, and the kernel function parameter g is 0.6, that is, X(20) = [3.0, 0.6]. The coefficient vector A is randomly set to [0.2, 0.3], and C is set to [1.2, 1.1]. The randomly generated p value is 0.4, which satisfies p < 0.5. The value of |A| is calculated as: Satisfies |A|<1. According to formula D 1 =|C·X * (t)-X(t)|Calculate the distance D between the individual whale and the prey (the current best solution) 1 , first calculate C·X * (t), C·X * (t) = [1.2, 1.1] · [3.5, 0.7] = [4.2, 0.77], then calculate D 1 , D 1 =|[4.2, 0.77]-[3.0, 0.6]|=[1.2, 0.17]. According to the formula X(t+1)=X * (t)-A·D 1 Update the individual whale positions, first calculate A·D 1 , A.D. 1 =[0.2, 0.3]·[1.2, 0.17]=[0.24, 0.051], then the updated whale individual position vector X(21), X(21)=X * (20)-A·D 1=[3.5, 0.7]-[0.24, 0.051]=[3.26, 0.649], and the support vector machine parameter combination corresponding to the updated position vector X(21) becomes (3.26, 0.649). In the subsequent iterations of the whale algorithm, the position will continue to be updated according to the corresponding rules based on the new position vector X(21) and the randomly generated p value and other conditions, and a better support vector machine parameter combination will be continuously explored to optimize the water quality evaluation model and improve the accuracy of water quality evaluation.
[0071] Figure 4 In the embodiment shown, during the iterative process of the whale algorithm, assuming that the current iteration number t=30, the position vector X of the current best solution * (30), assuming that the penalty coefficient C of the corresponding support vector machine is 2.8, the kernel function parameter g is 0.6, and the vector is represented by X * (30) = [2.8, 0.6]. The penalty coefficient C corresponding to the current position vector X(30) of a whale individual is 2.5, and the kernel function parameter g is 0.55, that is, X(30) = [2.5, 0.55]. The constant b is set to 1.2, and a random number generator is used to generate a random number l in the interval [-l, 1]. Assume that the generated l is -0.3. At the same time, the randomly generated p value is 0.6, which satisfies p ≥ 0.5. According to formula D 2 =|X * (t) - X(t) | Calculate the distance D from the individual whale to the prey (the current best solution) 2 , D 2 =[2.8, 0.6]-[2.5, 0.55]=[0.3, 0.05]. According to the formula X(t+1)=D 2 ·e bl ·cos(2πl)+X * (t) Update the individual whale positions. First calculate e bl Substituting b = 1.2 and 1 = -0.3 into the value, we get: e bl =e 1.2×(-0.3) ≈0.7047. Then calculate the value of cos(2πl), and substitute l=-0.3 to get: cos(2π×(-0.3))=-0.8090. Then calculate D 2 ·e bl ·cos(2πl), D 2 ·e bl Cos(2πl)=[0.3, 0.05]×0.7047×(-0.8090)≈[-0.170, -0.028], and finally calculate the updated whale individual position vector X(31), X(31)=D 2 ·e bl ·cos(2πl)+X *(t) = [-0.170, -0.028] + [2.8, 0.6] = [2.630, 0.572], and the support vector machine parameter combination corresponding to the updated position vector X (31) becomes (2.630, 0.572). In the subsequent iterations of the whale algorithm, the new position vector X (31) will be used as the basis, combined with the randomly generated p value, 1 value and other conditions, and the position will continue to be updated according to the corresponding rules, and a better support vector machine parameter combination will be continuously searched to optimize the water quality evaluation model and improve the accuracy of water quality evaluation.
[0072] The present invention also discloses a system for realizing the method for constructing a water quality evaluation model based on the fruit fly-whale collaborative optimization algorithm disclosed in the present invention, comprising:
[0073] A data collection unit, which is configured to collect water quality data including a plurality of water quality parameters and pre-process the collected water quality data;
[0074] A key feature determination unit is configured to calculate the pre-processed water quality data through information gain and obtain information gain values of each water quality parameter, and determine key water quality parameter features based on the obtained water quality parameter information gain values;
[0075] A data set construction unit, which is constructed to construct a sample data set based on the determined key water quality parameter characteristics and divide it into a training sample set and a test sample set;
[0076] A support vector machine establishment unit, which is constructed to establish a support vector machine model and set the penalty coefficient and kernel function parameters of the support vector machine as a parameter combination to be optimized;
[0077] The parameter combination optimization unit is constructed to optimize the parameter combination based on the fruit fly-whale collaborative optimization algorithm, and includes:
[0078] The fruit fly algorithm optimization unit is constructed by using the fruit fly optimization algorithm to optimize the penalty coefficient and kernel function of the support vector machine.
[0079] The parameters are optimized to obtain the optimal solution of the fruit fly algorithm globally;
[0080] The whale algorithm optimization unit is constructed to use the optimal solution of the fruit fly algorithm obtained based on the fruit fly optimization algorithm as the initial solution of the whale algorithm, and then use the spatial position corresponding to the best whale individual obtained based on the output of the whale algorithm as the optimal solution of the parameter combination of the support vector machine;
[0081] A model building unit, which uses the optimized parameter combination to configure the support vector machine to construct an original water quality evaluation model based on the support vector machine;
[0082] The training and testing unit trains and tests the original water quality evaluation model based on the training sample set and the test sample set in the data set construction unit until the final water quality evaluation model is obtained.
[0083] The water quality evaluation model construction system of the present invention exhibits significant advantages such as integration, high efficiency, precise optimization and strong adaptability: on the one hand, through modular design, key links such as data collection and preprocessing, key feature determination, data set construction, model parameter optimization, model construction, training and testing are integrated into a complete system, and each unit works together, which not only greatly improves the efficiency of model construction, avoids the tediousness and errors that may occur in manual operation during step conversion, but also can respond to needs quickly, and is suitable for large-scale real-time monitoring scenarios; on the other hand, the fruit fly-whale collaborative optimization algorithm is used in the parameter combination optimization unit to optimize the support vector machine parameters, and the fruit fly algorithm optimizes the single Yuan uses the fast convergence and global search capabilities of the fruit fly optimization algorithm to globally locate high-quality parameter combinations, providing a good initial solution for the whale algorithm optimization and avoiding falling into local optimality. On this basis, the whale algorithm optimization unit simulates predation behavior to fine-tune parameters. The combination of the two significantly improves the model's accuracy, stability and adaptability to different water quality conditions. In addition, the system has a clear architecture, and each unit is both relatively independent and closely connected, which makes it easy to improve and expand some units based on actual scenarios and new research results, such as introducing new screening methods in the key feature determination unit or trying new algorithm combinations in the parameter combination optimization unit, which can continuously meet the development needs of the water quality assessment field.
[0084] The present invention also discloses an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the water quality evaluation model construction method based on the fruit fly-whale collaborative optimization algorithm disclosed in the present invention.
[0085] The water quality evaluation model provided by the present invention has the following advantages:
[0086] 1) High accuracy: The accuracy of water quality evaluation is significantly improved by selecting features through information gain and optimizing support vector machine parameters in combination with FOA-WOA:
[0087] 2) Superior efficiency: Compared with traditional methods, this model can complete the evaluation task of a large number of samples in a short time and is suitable for large-scale real-time monitoring scenarios;
[0088] 3) Easy to integrate: It can be seamlessly integrated into the existing water quality monitoring platform, providing strong technical support for smart water services;
[0089] 4) Optimization and enhancement: The introduction of the fruit fly optimization algorithm enhances the convergence speed of the whale algorithm and its ability to avoid falling into local optimality, thereby further improving the stability and reliability of the model.
[0090] The present invention selects the fruit fly algorithm to optimize the whale algorithm for the following reasons:
[0091] 1) Complementary advantages:
[0092] Whale Optimization Algorithm (WOA): With its unique mechanism of simulating the predation behavior of humpback whales, it has the advantages of simple operation and few control parameters. However, the randomness of its initial solution may lead to the problem of local optimality, and there are also problems such as slow convergence speed and low convergence accuracy.
[0093] Fruit Fly Optimization Algorithm (FOA): It has fast convergence characteristics and good global search capabilities, and can quickly find the spatial region of high-quality solutions in the early stage. By introducing FOA, the problem of slow convergence of WOA can be improved, providing WOA with a better initial solution and reducing the risk of falling into local optimality.
[0094] 2) The advantages are as follows:
[0095] Enhanced global search capability: WOA relies on the current best solution for updating during the search process, while FOA can extensively explore the solution space in the early stage, helping WOA avoid focusing on the local optimal area too early. This combination enables the algorithm to cover the entire solution space more effectively and increase the probability of finding the global optimal solution.
[0096] Accelerate the convergence process: FOA's fast positioning capability can help WOA approach the high-quality solution faster, thereby shortening the overall optimization process. Using FOA's efficient search in the early stage and relying on WOA's precise adjustment in the later stage can achieve faster and more accurate parameter optimization.
[0097] Improve model stability: By combining two algorithms with different mechanisms, the model's adaptability to different types of problems is enhanced, and the algorithm's stability and reliability are improved. Even in the face of complex water quality assessment tasks, a high performance level can be maintained.
[0098] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution of the present invention, which should be included in the scope of the claims of the present invention.
Claims
1. A method for constructing a water quality evaluation model based on a fruit fly-whale collaborative optimization algorithm, characterized in that: The steps include: S1, collecting water quality data including multiple water quality parameters, and preprocessing the collected water quality data; S2, calculating the pre-processed water quality data through information gain and obtaining the information gain value of each water quality parameter, and determining the key water quality parameter characteristics based on the obtained information gain value of the water quality parameter; S3, constructing a sample data set based on the determined key water quality parameter characteristics and dividing it into a training sample set and a test sample set; S4, establishing a support vector machine model, and setting the penalty coefficient and kernel function parameters of the support vector machine as the parameter combination to be optimized; S5, optimizes the parameter combination based on the fruit fly-whale collaborative optimization algorithm, which includes: S51, using the fruit fly optimization algorithm to optimize the penalty coefficient and kernel function parameters of the support vector machine, and obtaining the optimal solution of the fruit fly algorithm in the global scope; S52, using the optimal solution of the fruit fly algorithm obtained based on the fruit fly optimization algorithm as the initial solution of the whale algorithm, and then using the spatial position corresponding to the best whale individual obtained based on the output of the whale algorithm as the optimal solution of the parameter combination of the support vector machine; S6, configuring the support vector machine using the optimized parameter combination to construct an original water quality evaluation model based on the support vector machine; S7, training and testing the original water quality evaluation model based on the training sample set and the test sample set in step S3 until a final water quality evaluation model is obtained.
2. The method for constructing a water quality evaluation model based on fruit fly-whale algorithm collaborative optimization according to claim 1, characterized in that: The step S51 comprises: S5101, setting the value range of the penalty coefficient and kernel function parameter of the support vector machine, and setting the fruit fly population size and initial flight radius; S5102, randomly generating positions of fruit fly individuals according to the set initial flight radius, each fruit fly individual representing a set of the parameter combinations; S5103, training a support vector machine for each fruit fly individual using the key water quality parameter characteristic sample data set in step S3, and calculating its fitness value; S5104, sort all fruit fly individuals according to their fitness values, record the parameter combination with the smallest fitness value, and use it as the optimal solution of the fruit fly algorithm.
3. The method for constructing a water quality evaluation model based on fruit fly-whale algorithm collaborative optimization according to claim 2, characterized in that: The step S52 comprises: S5201, set the initialization whale population size and maximum number of iterations; S5202, based on the optimal solution of the fruit fly algorithm determined in step S5104, the position of each individual whale is updated and iterated according to the whale algorithm update rule; S5203, recalculating the new fitness value of each whale individual after each iterative update, and comparing the new fitness value with the previous old fitness value, updating the global optimal whale individual spatial position as the global optimal parameter combination; S5204, determine whether the iteration reaches the preset maximum number of iterations. When it is determined to be yes, output the current global optimal parameter combination as the optimal solution of the parameter combination. When it is determined to be no, start step S5202 again.
4. The method for constructing a water quality evaluation model based on fruit fly-whale algorithm collaborative optimization according to claim 3, characterized in that: In step S5204, the fitness value of the optimal whale individual is output as a performance indicator.
5. The method for constructing a water quality evaluation model based on fruit fly-whale algorithm collaborative optimization according to claim 3, characterized in that: The whale algorithm update rule in step S5202 includes an update rule for simulating the shrinking and encircling of a whale group, which includes: introducing a random number p, when p<0.5 and |A|<1, according to the formula X(t+1)=X * (t)-A·D1 updates the individual position of the whale; where D1=|C·X * (t)-X(t)|, t is the current iteration number, X * is the position vector of the current best solution, X * is the position vector of the individual whale, D1 is the distance between the individual whale and the prey, || is the absolute value, · is the element-by-element multiplication, and A and C are coefficient vectors.
6. The method for constructing a water quality evaluation model based on fruit fly-whale algorithm collaborative optimization according to claim 5, characterized in that: The whale algorithm update rule in step S5202 also includes an update rule for simulating the spiral decline of the whale group, which includes: when p≥0.5, according to the formula X(t+1)=D2·e bl ·cos(2πl)+X * (t) Update the individual whale positions; where D2 = |X * (t)-X(t)|, D2 is the distance from the individual whale to its prey, b is a constant, and l is a random number in [-1,1].
7. The method for constructing a water quality evaluation model based on fruit fly-whale algorithm collaborative optimization according to claim 6, characterized in that: The whale algorithm update rule in step S5202 also includes an update rule for simulating the global wandering and foraging of a whale group, which includes: when p<0.5 and |A|≥1, according to the formula X(t+1)=X rand -A.D rand Update the individual position of the whale; where D rand =|C·X rand -X(t)|,X rand represents the position vector of a whale randomly selected from the group, D rand represents the distance from a randomly selected individual whale to its prey.
8. The method for constructing a water quality evaluation model based on the collaborative optimization of the fruit fly-whale algorithm according to any one of claims 1 to 7, characterized in that: The water quality parameters include permanganate index, ammonia nitrogen, total nitrogen, total phosphorus, turbidity and conductivity; The step of preprocessing the collected water quality parameters includes: after removing abnormal data, normalizing the water quality parameter data.
9. A system for implementing the method for constructing a water quality evaluation model based on a fruit fly-whale collaborative optimization algorithm according to any one of claims 1 to 8, characterized in that: include: A data collection unit, which is configured to collect water quality data including a plurality of water quality parameters and pre-process the collected water quality data; A key feature determination unit is configured to calculate the pre-processed water quality data through information gain and obtain information gain values of each water quality parameter, and determine key water quality parameter features based on the obtained water quality parameter information gain values; A data set construction unit, which is constructed to construct a sample data set based on the determined key water quality parameter characteristics and divide it into a training sample set and a test sample set; A support vector machine establishment unit, which is constructed to establish a support vector machine model and set the penalty coefficient and kernel function parameters of the support vector machine as a parameter combination to be optimized; The parameter combination optimization unit is constructed to optimize the parameter combination based on the fruit fly-whale collaborative optimization algorithm, and includes: A fruit fly algorithm optimization unit, which is constructed by using the fruit fly optimization algorithm to optimize the penalty coefficient and kernel function parameters of the support vector machine, and obtain the optimal solution of the fruit fly algorithm in a global range; The whale algorithm optimization unit is constructed to use the optimal solution of the fruit fly algorithm obtained based on the fruit fly optimization algorithm as the initial solution of the whale algorithm, and then use the spatial position corresponding to the best whale individual obtained based on the output of the whale algorithm as the optimal solution of the parameter combination of the support vector machine; A model building unit, which uses the optimized parameter combination to configure the support vector machine to construct an original water quality evaluation model based on the support vector machine; The training and testing unit trains and tests the original water quality evaluation model based on the training sample set and the test sample set in step S3 until a final water quality evaluation model is obtained.
10. An electronic device, characterized in that: It includes a memory and a processor, the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the water quality evaluation model construction method based on the fruit fly-whale collaborative optimization algorithm according to any one of claims 1 to 8.
Citation Information
Cited By
Denoising and adaptive feature extraction fused dissolved oxygen prediction method and device
CN120892823A
Water pollution risk early warning and tracing method based on multi-source data fusion
CN121119701A