Disclosure of Invention
In order to overcome the defects of the prior art, the invention aims to provide a facility light environment regulation and control method fused with a random forest algorithm, so as to solve the problems of poor portability, low equipment reliability, slow system response, high energy consumption and the like of the conventional facility light environment regulation and control system.
In order to achieve the purpose, the invention adopts the technical scheme that:
a facility light environment regulation and control method fused with a random forest algorithm comprises the following steps:
the method comprises the following steps: according to the influence of the change of light, carbon dioxide and temperature on the plant photosynthetic rate in the plant growth process and the environmental factors of associated temperature, illumination and carbon dioxide concentration, a photosynthetic rate prediction model is established by using a BP algorithm, and then an improved fish swarm algorithm is adopted to optimize the photosynthetic rate model;
step two: finding light saturation points under different temperatures and carbon dioxide conditions by the optimization algorithm in the step one, establishing a light environment regulation and control model fused with a random forest algorithm, and gathering a large number of classification trees by selecting a random characteristic strategy to improve the prediction precision of the random forest model;
step three: the method comprises the steps that a raspberry group system frame and a platform system capable of achieving model transplantation are built, cross-platform transplantation of an intelligent regulation and control algorithm is achieved in the regulation and control process, the hardware structure of equipment mainly comprises a raspberry group main control node, a sensor monitoring node and an LED dimming node, information interaction is achieved among the nodes through a ZigBee wireless technology, and a modular design idea is adopted inside;
step four: after the model establishment and the cross-platform transplantation of the intelligent algorithm in the steps are completed, in the actual regulation process, the basic parameters of a controlled object are selected through a parameter selection interface, the environment condition is fed back by monitoring nodes in real time, the stored random forest model is directly called, the target value of the light environment regulation and control at the moment can be calculated by seeing the model in the interface, the photon flux density value actually required by the current environment is calculated by comparing with the input illumination intensity of the environment, the photon flux density value is converted into a pulse width modulation control signal, and the LED light supplementing node is controlled to complete dynamic and accurate regulation and control according to the actual light environment.
In the first step, the specific steps of constructing the photosynthetic rate prediction model and the optimization model are as follows:
step 1: according to the regulation model experiment scheme, a photosynthetic rate prediction model is established by using a BP algorithm, and a BP neural network model is established by taking temperature, carbon dioxide and illumination environment factor normalization processing as an input sample set of the model:
where n represents the number of input nodes, l represents the number of hidden layer nodes, m represents the number of output nodes, x represents the input quantity, w
ijRepresenting the connection weight, w, between the input layer and the hidden layer
jkRepresenting the connection weight between the hidden layer and the output layer, a
jIndicating initialization of hidden layer thresholds, b
kRepresenting the initialized output layer threshold, f () representing the hidden layer excitation function; establishing a BP photosynthetic rate prediction model: p
nNet (T, C, D) formula wherein P
nRepresenting photosynthetic rate, T temperature, C carbon dioxide concentration, D photon flux density, completing the model P from the input sample
nInstantiation of net (T, C, D) temperature, carbon dioxide and photon flux density, establishing prediction function P under different conditions of temperature, carbon dioxide and photon flux density
m=net(T
m,C
m,D
m);
Step 2: after the BP photosynthetic rate prediction model in the step one is established, optimizing the photosynthetic rate model by adopting an improved fish swarm algorithm, randomly generating an initial fish swarm, and expressing the state vector of the generated initial fish swarm individual as X ═ X (X)1,x2,…xn) Wherein x isnFor the corresponding light saturation points of the variables to be optimized under different temperature and dioxide concentration conditions, and utilizing the obtained optimization target value function F under specific temperature and carbon dioxide conditionsmThe positions of the artificial fishes are continuously updated through the processing of foraging behaviors, social behaviors and rear-end collisions in the fish swarm algorithm,therefore, the individual food concentration in the new fish school is continuously improved, the optimal photosynthetic rate of the crop in the current generation is gradually increased along with the increase of the evolution algebra, and when the artificial fish school algorithm generates a new individual approaching to the optimal solution, the individual food concentration is basically kept constant, so that the photosynthetic rate optimization is completed.
In the second step, the light regulation and control model fusing the random forest algorithm specifically comprises the following steps:
the method comprises the following steps: let X { (X)m,ym) M is 1,2, M is a light saturation point sample set which is obtained by optimizing an improved fish school algorithm under different temperature and dioxygen concentration conditions and is used as a group of training sets of a light environment optimization regulation model, wherein X ismIs the temperature and carbon dioxide concentration, y, corresponding to the mth light saturation pointmIs the mth light saturation point sample data; generating L decision trees f (X, theta) by randomly sampling the set of optimized samples Xk) Assembling and constructing a random forest, wherein k is 1,2kIs the random vector used by the kth decision tree to select sample points;
step two: randomly generating theta by Bootstrap sampling method
kRandomly drawing 2/3 training sample points to generate a kth decision tree, a random vector theta
kAre independent of each other and are distributed uniformly;
in the formula
Indicating that each decision tree produces a photon flux density value corresponding to a predicted light saturation point,
and the photon flux density value corresponding to the light saturation point representing the random forest prediction is obtained by averaging the predicted values of all decision trees.
After a light regulation and control model fused with a random forest algorithm is established, in order to modify the model and improve the prediction precision of the random forest, a random characteristic selection strategy is adopted: at each of each decision treeAt the node, randomly extracting N optical saturation point variables from the N total input optical saturation point variables, selecting an optimal optical saturation point variable from the N optical saturation point variables to segment the node, increasing or decreasing the value of N until the minimum test error is obtained, and outputting the final output photon flux density value at the moment
The method is an optimal regulation value, wherein N is less than or equal to N, so that the final regulation model has higher precision.
In the third step, the specific steps of the raspberry dispatching system framework and the intelligent algorithm transplantation are as follows:
step 1: the system controller adopts a raspberry group 3 generation B type, carries a Linux operating system, completes the development of an equipment interface on Qt, adopts a 7inch HDMI LCD touch display screen, is convenient for man-machine interaction, thereby building a raspberry group system frame and a platform system which can realize model transplantation, and realizing real-time accurate calculation and intelligent feedback control on a regulation target value of a fusion random forest light environment regulation model on an embedded platform;
step 2: after the random forest model is constructed, the random forest model is stored and output through a model variable, the variable is stored into a txt file or other file forms, the variable in the program is stored into a local file by using a pick.dump () function in a pick module of python, the storage work of the model is completed, the pick.load () function in the pick module of python is imported into the corresponding position of the program from the local file, the loading of the model is realized, the model can be exported only by loading the model on the corresponding path in the model transplanting process, and the cross-platform light control model transplanting is completed;
and step 3: the hardware structure of the equipment mainly comprises a raspberry group main control node, a sensor monitoring node and an LED dimming node, information interaction is realized among the nodes through a ZigBee wireless technology, and a modular design idea is adopted inside the equipment; each node adopts CC2530 as a core processing module, realizes Wireless Sensor Network (WSN) ad hoc network and management function based on the ZigBee protocol, the sensor monitoring node is used as a router in the ZigBee network to realize data forwarding among different greenhouse nodes, the raspberry group control node sends a main control program to the LED dimming node in a broadcasting mode through a coordinator, and the LED dimming node receives an LED control signal sent by the central control node by utilizing the CC 2530.
After the construction of a raspberry group system framework and the transplantation of an intelligent algorithm are completed, crop selection and light supplement stages are determined on an equipment parameter setting interface, a random forest model embedded into the system is loaded on a corresponding path of a raspberry group, environmental factors monitored by a sensor are used as input of the model, at the moment, the random forest algorithm gathers a large number of classification trees, photon flux density values corresponding to light saturation points of the model are obtained by averaging predicted values of all decision trees, and photosynthetically active radiation values are monitored according to sensor monitoring nodes in an actual environment to perform difference value calculation regulation.
And step four, in the actual regulation and control process, selecting basic parameters of a controlled object through a parameter selection interface, directly calling a stored random forest model, periodically monitoring the photosynthetically active radiation value by using a sensor monitoring node, calculating the current red and blue light quantum flux density by using the proportional relation between the solar altitude angle and the red and blue light in natural light, sending the current red and blue light quantum flux density to a raspberry dispatching main control node, calculating the difference value between the current red and blue light quantum flux density and the target quantity required by crops by using the main control node, converting the difference value into a pulse width modulation control signal, and controlling the LED dimming node to control the LED output brightness through the ZigBee control LED dimming node, so that the dynamic, accurate and wireless regulation and control of the output light quantity of the LED light supplementing lamp.
Compared with the prior art, the invention has the beneficial effects that:
1) the facility light environment regulation and control equipment is fused with a random forest algorithm to dynamically calculate the light regulation and control target value, compared with the traditional multiple linear regression model or the parameter regression model, the random forest algorithm does not need to set a function form in advance, and can overcome the complex interaction among covariates, has higher classification accuracy, improves the model prediction accuracy by gathering a large number of classification trees, has high tolerance on abnormal values and noise, is not easy to generate overfitting phenomenon, has longer exponential multiplication compared with the complexity of an SVM model based on an RBF kernel function along with the increase of the sample size, the time complexity thereof also becomes larger along with the increase of the training set sample base, and the random forest algorithm has the advantages of simple operation, short data processing time, high response speed and the like, therefore, the accuracy of the regulation and control system is effectively improved, and the requirement of the system on a hardware system is reduced.
2) In order to realize smooth transplantation of an intelligent control algorithm of a random forest light environment control model, the facility light environment control equipment designs a new raspberry dispatching system frame and a platform system, and compared with the traditional embedded light environment control system which cannot directly load the intelligent algorithm model, the system can store and output the intelligent algorithm model through model variables after the random forest model is constructed; in the model transplanting process, the model can be derived only by loading the model on a corresponding path, and the cross-platform light control model transplanting is completed, so that the regulation target value of the random forest light environment regulation and control model is fused on the embedded platform to carry out real-time accurate calculation and intelligent feedback control.
Detailed Description
The embodiments of the present invention will be described in detail below with reference to the drawings and examples.
The invention mainly comprises the following steps:
the method comprises the following steps: according to the influence of the changes of light, carbon dioxide and temperature on the plant photosynthetic rate in the plant growth process and the correlation of environmental factors of temperature, illumination and carbon dioxide concentration, a photosynthetic rate prediction model is established by using a BP algorithm, an improved fish swarm algorithm is adopted to optimize the photosynthetic rate model, light saturation points under different temperatures and carbon dioxide conditions are found, and a photosynthesis regulation and control model fused with a random forest algorithm is established.
Step two: a Wireless Sensor Network (WSN) with the advantages of ad hoc network, low energy consumption, easiness in management and the like is adopted to deploy whole facility light environment regulation and control equipment, a novel raspberry dispatching system frame and a platform system are designed, equipment hardware is composed of raspberry dispatching control nodes, sensor monitoring nodes and LED light dimming nodes, each node adopts CC2530 as a core processing module, and the Wireless Sensor Network (WSN) ad hoc network and information transmission are achieved based on a ZigBee protocol. The raspberry group control node has management functions of gathering real-time environment information, calculating light supplement amount, issuing a light supplement command, setting system parameters and the like, sends a main control program to the light supplement node in a broadcasting mode through a coordinator, and receives environment factor information sent by the sensor monitoring node; the sensor nodes finish the acquisition, processing and transmission of environmental factors, and are used as routers in the ZigBee network to realize data forwarding among different greenhouse nodes; the LED dimming node receives an LED control signal sent by the central control node by using the CC2530, converts the LED control signal into a corresponding PWM signal, and controls the LED output current through the LED driving chip to realize the purpose that the dimming lamp group outputs illuminance as required.
Step three: in the actual facility light environment regulation, a user enters a model import interface, selects a corresponding light supplement crop, loads a required model, and completes cross-platform transplantation of the model, wherein the model takes the temperature, carbon dioxide and illumination intensity of the environment as input, the model can be seen in the interface to calculate the target value of the light environment regulation at the moment, and the target value is compared with the input illumination intensity of the environment; and obtaining a value required in the environment of the model at the moment, and sending an instruction to the LED light supplement node through the raspberry sending main control node to complete dynamic light supplement for the tomatoes.
The following is a specific experimental protocol for the control model
The test for tomato seedlings was carried out in the laboratory incubator in the northern school district of agriculture and forestry technology university in northwest in 2017, 9 months to 2017, 10 months. The Li-6800 type portable photosynthetic apparatus produced by LI-COR company is adopted in the experiment, and the net photosynthetic rate can be measured while setting and regulating the small environment of a leaf chamber; adopt illumination, temperature, carbon dioxide coupling nested test mode to obtain the photosynthetic rate to the tomato seedling under different gradient temperature, illumination, carbon dioxide condition, carry out gross error analysis and filtering, secondly carry out the preliminary treatment to the data after the gross error of filtering to form the photosynthetic rate sample set that corresponds under the required different temperature of modeling, illumination, carbon dioxide combination condition, wherein control carbon dioxide concentration gradient is respectively: 400, 0,200, 400, 800, 1200 and 1600, and the control temperature is as follows: 14, 17, 20, 23, 16, 30 and 33, controlling the illumination intensity as follows: 1500,1300,1200,1100,900,700,500,300,200,100,50,20,0, ten gradients; and (3) carrying out 60 groups of experiments, randomly selecting 7 eggplant plants in each group of experiments, measuring each eggplant plant for 5 times, taking an average value, repeating the three groups to finally form a test sample set with the sample capacity of 350, and finally obtaining test samples with the sample number of 314 after data analysis and processing.
Based on the experimental scheme, the steps of establishing the photosynthetic rate prediction model by using the BP algorithm are as follows:
the method comprises the following steps: the data is preprocessed, the magnitude order difference of each variable in the facility environment is large, in order to enable the model calculation to be more effective, the original input variable is subjected to normalized processing and converted into a dimensionless variable, a normalized processing formula is shown as follows, and all the processed input variables are subjected to distribution with the mean value of 0 and the variance of 1.
Wherein the content of the first and second substances,
an input variable for the normalized jth temperature;
S
jthe mean value and the sample variance of the initial input variables of the jth original temperature are respectively, and the normalized vector X is equal to (X)
1,x
2,…x
n) Is the input of the photosynthetic rate model.
Step two: the BP neural network model established by using the processed data is as follows:
where n represents the number of input nodes, l represents the number of hidden layer nodes, m represents the number of output nodes, x represents the input quantity, wijRepresenting the connection weight, w, between the input layer and the hidden layerjkRepresenting the connection weight between the hidden layer and the output layer, ajIndicating initialization of hidden layer thresholds, bkRepresenting the initialized output layer threshold, f () representing the hidden layer excitation function.
The established BP photosynthetic rate prediction model formula is as follows:
Pn=net(T,C,D)
in the formula PnRepresents the photosynthetic rate in units of [ mu ] mol/(m)2S), net () representing the BP neural network model, T representing temperature, C representing carbon dioxide concentration, D representing photon flux density, model P being completed from the predicted samplesnInstantiation of net (T, C, D) temperature, carbon dioxide and photon flux density, establishing prediction function P under different conditions of temperature, carbon dioxide and photon flux densitym=net(Tm,Cm,Dm)。
Based on the BP algorithm photosynthetic rate prediction model, the temperature and carbon dioxide coupling photosynthetic rate model optimization steps of the improved fish swarm algorithm are as follows:
the method comprises the following steps: the flow chart of the improved fish swarm algorithm is shown in fig. 2, wherein an initial fish swarm is randomly generated, and the generated state vector of an initial fish swarm individual is represented as X ═ (X ═ X)1,x2,…xn) Wherein x isnThe corresponding light saturation points under different temperature and dioxygen concentration conditions of the variables to be optimized are obtainedUsing the obtained optimized target function F under specific temperature and carbon dioxide conditionsmAs the food concentration Y under specific temperature and carbon dioxide conditions, thereby utilizing Ym=FmAnd calculating the food concentration to finish evaluation, and when the fish school evaluation does not meet the stop condition, continuing optimizing operation through the improved fish school by using the dynamic adjustment formula of the core visual field and the step length of the improved fish school algorithm as follows.
Wherein v represents the field of view of the artificial fish in the present search, stThe step length v of the artificial fish movement is searchedi-1Indicating the field of view, s, of the artificial fish from the previous searcht,i-1Indicating the field of view of the artificial fish searched for the previous time, a indicating the adjustment factor, vminMinimum variation s of visual field rangetminIndicating the minimum amount of change in step size.
Step two: through the calculation of the third step, the foraging behavior is calculated as follows: recording the current state of the artificial fish as xiRandomly selecting a state x within the sensing rangejI.e. by
xj=xi+(2r-1)st
Wherein r is a random number, and the food concentration of the state of the artificial fish satisfies Yj>Yi,Yj、Yi,xi++Location update as
Step three: through the calculation of the third step, the calculation of the clustering behavior is as follows: the artificial fish moves toward the center of the partner, if the food concentration at the center of the artificial fish school is Y
cCurrent food concentration of Y
iNumber of buddies n in current view
fIf it is satisfied
Where σ is the degree of crowding,thereby limiting the scale of artificial fish herd aggregation, executing the clustering behavior, and the calculation formula is
Step four: through the calculation of the step three, the rear-end collision behavior is calculated as follows: the artificial fish moves towards the optimal position partner direction, and if the current optimal position food concentration Y of the artificial fish school is
bestWith the current food concentration Y
iSatisfy the requirement of
When the vehicle is running, the rear-end collision behavior is executed, and the calculation formula is
Step five: the positions of the artificial fishes are continuously updated by processing foraging behaviors, social behaviors and rear-end collision behaviors in the fish swarm algorithm, so that the individual food concentration in a new fish swarm is continuously improved, and the optimal photosynthetic rate of the tomato generation is gradually increased along with the increase of evolution algebra; and the artificial fish swarm algorithm is increased along with the evolution algebra, when a new individual approaches to an optimal solution, the individual food concentration is basically kept constant, and therefore the photosynthetic rate optimization is completed.
Optimizing a temperature and carbon dioxide coupled photosynthetic rate model based on the improved fish swarm algorithm, and establishing a regulation and control model fusing a random forest algorithm, wherein the steps of the regulation and control model are as follows:
the method comprises the following steps: let X { (X)
m,y
m) M is 1,2, M is a light saturation point sample set which is obtained by optimizing an improved fish school algorithm under different temperature and dioxygen concentration conditions and is used as a group of training sets of a light environment optimization regulation model, wherein X is
mIs the temperature and carbon dioxide concentration, y, corresponding to the mth light saturation point
mIs the mth light saturation point sample data; generating L decision trees f (X, theta) by randomly sampling the set of optimized samples X
k) And (6) collecting and constructing a random forest. Wherein k is 1,2
kIs a random vector used by the kth decision tree to select sample points, and randomly generates theta through a Bootstrap sampling method
kRandomly drawing 2/3 training sample points to generate a kth decision tree, a random vector theta
kAre independent of each other and are distributed uniformly;
in the formula
Indicating that each decision tree produces a PFD corresponding to a predicted light saturation point,
and the PFD value corresponding to the light saturation point representing the random forest prediction is obtained by averaging the predicted values of all decision trees.
Step two: FIG. 3 is a schematic diagram of a structural framework of a random forest learning algorithm model, in order to improve the prediction accuracy of a random forest, a random feature selection strategy is adopted, in which firstly, at each node of each decision tree, N (N is less than or equal to N) light saturation point variables are randomly extracted from N total input light saturation point variables, and an optimal light saturation point variable is selected from the N total input light saturation point variables to segment the node; then increase or decrease the value of n until the minimum test error is obtained, at which time the final output PFD value is output
Is the optimal regulation value.
Step three: FIG. 4 is a graph of the output of a control target value of a random forest model, and the verification model needs to pass through a proper evaluation index, wherein the goodness of fit R2The fitting degree of the regression model to the sample data can be checked, the value is between 0 and 1, and the higher the fitting goodness is, the higher the interpretable degree of the representative model is; the root mean square error RMSE can reflect the discrete degree of a sample, the value is an integer larger than 0, the lower the value is, the higher the precision is, but the size of the error is influenced by the size of a predicted value; the value of the precision P is between 0 and 1, and the higher the precision is, the higher the prediction accuracy is; FIG. 5 is the present inventionAnd (5) a model verification diagram of the bright random forest algorithm.
Based on the establishment of the regulation and control model, the hardware structure of the device is shown in fig. 6, and the structure of each part is as follows:
the hardware structure of the device mainly comprises a raspberry group main control node, a sensor monitoring node and an LED dimming node, wherein the raspberry group main control node controls the whole device, information interaction is realized among the nodes through a ZigBee wireless technology, and a modular design idea is adopted inside the device.
The raspberry master control node sends a master control program to the LED dimming node in a broadcasting mode through the coordinator, and receives environmental factor information sent by the sensor monitoring node; the receiving and sending program has management functions of gathering real-time environment information, calculating the light supplement amount, issuing a light supplement command, setting system parameters and the like, and the user interaction module adopts a 7inch HDMI LCD display screen with the ultra-clear resolution being 1024X600, supports touch operation and facilitates man-machine interaction.
The sensor monitoring node sends factors in a facility environment to the main control node in real time through the ZigBee by installing the temperature sensor, the illumination sensor and the carbon dioxide sensor, and the sensor monitoring node is regularly calibrated in order to guarantee the data validity of the sensor.
The LED dimming node adopts an array type light supplementing lamp group, blue light with the central wavelength of 450nm and red light with the central wavelength of 680nm are selected as dimming light sources, the red/blue ratio is set to be 3:2, a control signal sent by the intelligent regulation node is received by CC2530 and converted into a PWM control signal corresponding to the red and blue light, the PWM regulation mechanism is that a PT4115LED integrated driving chip is adopted, different PWM duty ratio signals are loaded at a control end, and the current of the output end of the driving chip is linearly changed, so that the current flowing through the LED is changed, and the quantitative control of the brightness of the LED is realized.
Based on the hardware design of the system equipment, the detailed steps of the specific embodiment of the invention are as follows:
the method comprises the following steps: training a model, namely training a random forest tool kit in a Python scimit-learn algorithm, training a random forest model by using a random forest tool kit class, and setting corresponding parameters according to the requirement of the random forest tool kit class on an expected model; preprocessing data to obtain attributes, labels and attribute names, storing the attributes, labels and attribute names into a list, converting the list into a numpy array form, constructing a training set and a test set by using train _ test _ split of sklern, displaying the performance change process of the integrated method when the number of decisions in the integrated method changes by using a performance curve, initializing a random forest tester object, calling a fit () method, using the training data set as an input parameter, calling a predict () method to predict, inputting the attribute of the test data set, comparing a predicted value with the label in the test data, calculating a predicted mean square error by using a mean _ squared _ error function of sklern. metrics, and finally storing the trained model.
Step two: outputting a model variable; because the trained model outputs a variable, the variable needs to be saved into a txt file or other files, because some programs later use the important file and store the important file locally, the local file is read and imported into a dictionary type when the program is called next time, the program can be accessed as long as the program is called, and the readability of the code is high; the variables in the program are stored to the local file using the pick.dump () function in the pick module of python.
Step three: model loading as shown in fig. 7, in order to improve the portability of the algorithm, a loading and transplanting interface of the model is provided in the device, and the function is realized by establishing a step two basis, saving the model variable output obtained in the step one, and then importing the model variable output into a corresponding position of a program from a local file by using a pick.
Step four: the system light control display interface of the device is shown in fig. 8, in actual facility light environment control, the sensor monitoring node displays the collected environment factors on the touch screen in real time, so that a user can look up the environment factors at the moment and the environment factors are used as input variables of a control model, the system loads the model through a corresponding path where the model is located at the moment and can derive the model, cross-platform light control model transplantation is completed, and photon flux density values required by the current environment are calculated through a constructed random forest model.
Step five: the sensor monitoring node monitors the photosynthetically active radiation value periodically, the current red and blue light quantum flux density is calculated by utilizing the proportional relation between the solar altitude angle and the red and blue light in natural light, the current red and blue light quantum flux density is transmitted to the raspberry sending main control node, the difference between the current red and blue light quantum flux density and the target quantity required by crops is calculated by utilizing the main control node and converted into a pulse width modulation control signal, then the LED dimming node is controlled by the ZigBee to control the LED output brightness, and the dynamic, accurate and wireless regulation and control of the output light quantity of the LED light supplementing lamp are realized.