Real-time Prediction Model of Amount of Manure in Winter Pig Pen Based on Backpropagation Neural Network
2022-02-06HuZhennanSunHongminLiXiaomingDaiBaishengGaoYueandWangYuhan
Hu Zhen-nan ,Sun Hong-min* ,Li Xiao-ming ,Dai Bai-sheng, ,Gao Yue ,and Wang Yu-han
1 College of Electrical and Information,Northeast Agricultural University,Harbin 150030,China
2 Ministry of Agriculture and Rural Affairs,Key Laboratory of Pig Breeding Facilities Engineering,Harbin 150030,China
Abstract:The automatic control of cleaning need to be based on the total amount of manure in the house.Therefore,this article established a prediction model for the total amount of manure in a pig house and took the number of pigs in the house,age,feed intake,feeding time,the time when the ammonia concentration increased the fastest and the daily fixed cleaning time as variable factors for modelling,so that the model could obtain the current manure output according to the real-time input of time.A Backpropagation(BP) neural network was used for training.The cross-validation method was used to select the best hyperparameters,and the genetic algorithm (GA),particle swarm optimization (PSO) algorithm and mind evolutionary algorithm (MEA) were selected to optimize the initial network weights.The results showed that the model could predict the amount of manure in real-time according to the model input.After the cross-validation method determined the hyperparameters,the GA,PSO and MEA were used to optimize the manure prediction model.The GA had the best average performance.
Key words:manure amount,BP neural network,weight optimization algorithm,cross-validation
Introduction
In recent years,with the continuous modernization of the pig industry,the intelligent control integration of pig house including the pig house environmental control system and the manure removal system has been developed by leaps and bounds.The cleanup of pig house manure is an important part of pig breeding(Zonget al.,2015),and the accumulation of manure in a pig house for a long time seriously affects the air quality in the house (Roxanaet al.,2013).Northern China is located between 42° and 53°N latitude and is one of the coldest natural areas.In winter,fully enclosed mechanical ventilation is used to reduce heat loss and heating costs in pig house (Songet al.,2013);compared with that in summer,the concentration of harmful gases in pig house increases significantly in winter (Manuelet al.,2020).Therefore,it is necessary to increase the frequency of manure removal in a timely mannerviaregular manure removal.The prerequisite for automatic manure removal is to know the total amount of manure in the house.
There are relatively few domestic and foreign studies on the prediction of manure in pig house,and most of them focus on the problems of manure treatment and environmental control in pig house.Ruanet al.(2019) studied the influence of different manure removal methods on the ammonia concentration in pig house and showed that a reasonable choice of manure removal method can improve the pig house environment,especially in terms of reducing the ammonia concentration.Sunet al.(2008) found that the ammonia concentration in pig house is mainly affected by the time of the day,season,floor type,ventilation speed,animal growth cycle,indoor manure storage and weather conditions.Kimet al.(2005)conducted a study on the distribution of pollutants in a pig house under closed conditions in winter and showed that there are different distribution patterns at different times throughout the day.Xieet al.(2017) proposed using an adaptive neuro-fuzzy control inference system model to predict changes in the ammonia concentration throughout the day in a pig house.Sunet al.(2008) established a pig house air quality prediction model through a BP neural network and a generalized regression neural network to predict the level of harmful gases in a pig house.The above studies have shown that ammonia concentration changes in pig house are related to environmental factors and the behavioural characteristics of pigs,so ammonia levels can be predicted by modelling.Nevertheless,the above mentioned researches still provide many references for manure prediction research.In a faecal volume prediction study conducted by Rigolotet al.(2010),they established a mathematical model to simulate NH3,N2O and CH4emissions from pig manure production.The factors considered in the model are mainly related to animal performance (feed efficiency,yield,weight gain,etc.),water and nutrient intake and feeding conditions (ambient temperature).This model has good accuracy and robustness when predicting manure volume,N,P and a small amount of dry matter content in each growth stage of pigs.However,none of the above related studies can predict the real-time manure volume in pig house.
A real-time prediction model for the amount of manure in pig house in winter was proposed in this article.The number of pigs in a pig house,age in days,feed intake,feeding time,daily fixed manure removal time,ammonia concentration increase time were selected as the input variables of the model.A BP neural network was used for training to obtain an accurate real-time manure forecast model.To improve model performance,a cross-validation method was used to select the best model hyperparameters.Then,the method was combined with the genetic algorithm(GA),particle swarm optimization (PSO) algorithm and mind evolutionary algorithm (MEA) weight optimization algorithm to optimize and compare the models.The goal was to obtain the best performance prediction model and to provide a reliable basis for manure removal control.
Materials and Methods
Experimental environment
The experimental site is located at the Acheng Pig Farm in Harbin City,Heilongjiang Province,China.The fattening pig house in the pig farm was selected for the experiment.The length of the finishing barn was 25 m,the width was 9 m,and the total area was 225 m2.There was a middle aisle in the house with six pig pens connected side by side on each side,and each pig pen was 3.5 m×3.5 m.The pig pens were close to the side wall,the ground was a slatted floor (1.5 m),and there was a ditch (1.5 m) below the slatted floor.The manure was cleanedviamechanical dry manure removal.The urination ditch in the manure ditch flowed into the urine storage tank,and the faeces were left in the manure ditch.When cleaning the manure,the manure scraper was also scraped into the manure storage tank in the house and was manually transferred to the outdoor manure storage area.The pig house used machinery for ventilation,and the two fans were installed on each side of the wall.The test period was from November 2,2019 to January 25,2020;it was winter in northern China.The pig house adopted winter management measures,with doors and windows closed,and regular limited mechanical ventilation.The pigs in the experimental pig house were the same ages.The starting day was 81,and the experiment ending day was 165.The number of fattening pigs in each pigpen was 15,totalling 180 pigs.
Analysis of factors affecting amount of manure
The pig house was closed in winter,and the accumulation of manure in the house would increase the concentration of NH3(Liuet al.,2019;Aarninket al.,1996).The release rate of NH3was positively related to the amount of accumulated manure in the house(Zhuet al.,2006).Based on the detection of NH3emission rate,the amount of manure was determined at the time of the maximum NH3growth rate.The currentVNH3was calculated by formula (1),whereXwas the time interval,ΔCwas NH3concentration increment,andVNH3was the emission rate in the current period.
The total amount of manure in the pig house was positively correlated with the age and number of pigs.The pig feed intake (E) was also a direct factor affecting the total amount of manure (Liu and Powers,2014;Zhu and Dong,2006).Due to the digestion cycle of pigs (Hu and Liu,1986),the factors that affected pigs' daily excretion also included the evening feed intake (E1) of the previous day and the morning feed intake (E2) of that day.Manure removal was conducted whenVNH3was at its maximum.The amount of manure was related to the interval between the time of manure removal (Yang,2002) and the time of feeding.The larger the interval was,the more manure that accumulated.Moreover,the greater the interval from the last cleaning time was,the greater the accumulation was.In addition,due to the physiological characteristics of pigs,pigs excreted within a short time after eating.This meant that the time between the removal of manure and eating in the evening of the same day was also used as a parameter that affected the amount of accumulated manure.Therefore,the evening feeding time of the previous day was recorded ast1,the morning feeding time of the day was recorded ast2,the morning manure removal time of the same day was recorded ast3,the evening feeding time of the same day was recorded ast4,and manure removal was performed when the maximumVNH3occurred.In addition,the recording time wasT,and the weight of collected manure wasW.LetT1=T–t1,T2=T–t2,T3=T–t3,andT4=T–t4.
They were used along with the pig age,number of pigs,feed intake the night before (E1),feed intake in the morning (E2) and manure (weight) as sampling data,as shown in Fig.1.
Fig.1 Variable factors
Data collection and processing
During the experiment,feeding occurred in the pig house twice a day at 8: 00 a.m.and 5: 00 p.m.The feed was weighed and recorded.The remaining feed in the trough was weighed before feeding.After feeding,the faeces were cleared at 9: 30 a.m.The experimental manure removal equipment was a mechanical dry and wet separation scraper,and the moisture content of the manure after dry and wet separation was approximately 40%-46% (Ruanet al.,2019).The pig house was ventilated when cleaning manure.The manure was ventilated simultaneously.Then,VNH3was monitored in real-time according to NH3concentration monitoring instrument,and the data acquisition interval of NH3concentration was 3 min.WhenVNH3concentration was at its maximum value,more manure might accumulate.At this time,the manure was cleaned into the manure storage tank in the house,workers weigh the manure in buckets,with the corresponding time recorded.
Cleaning manure would increase the release of NH3in the manur (Wanget al.,2018).However,the short-term increase in NH3concentration due to cleaning faeces could not be attributed to the accumulation of faeces.Therefore,it was stipulated that no reprocessing of manure would be repeated within 1 h of excretion.In this way,allday manure removal data were recorded,as shown in Table 1.
Table 1 Pig manure volume and related factors data
The data were collected according to the needs of the experiment;after collection,the missing or abnormal data values that could reduce the impact on the model accuracy were removed (Wang and Wang,2018);and then,the data were normalized to make the data distributed in [0,1] and improve the convergence performance of the model to achieve better training effects.The normalization formula was as follows:
Methods
Manure forecast model
The BP neural network was a multilayer feed-forward neural network that backward propagated the errors(Jianget al.,2019).It consisted of an input layer,a hidden layer and an output layer.It had a good generalization ability and nonlinear mapping ability(Wanget al.,2019).This article selected the number of pigs in the pig house (number of pigs),pig growth days (pig age),feed intake parametersE(E1andE2) and time parametersT(T1,T2,T3andT4) as the network inputs.Then,the corresponding amount of manure was selected as the network output.Next,the corresponding experimental data were collected.A three-layer BP neural network was used to establish and train a prediction model for the total amount of manure in a pig house.The basic structure is shown in Fig.2.
Fig.2 Neural network topology diagram
The number of input nodes wasM,the number of hidden layer nodes wasN,and the number of output layer nodes wasK.In this article,K=1,andIirepresented theith neuron in the input layer.Wijwas the weight between the input layer and the hidden layer,b1iwas the bias,θjwas the threshold of hidden layer neurons,andHjrepresented thejth neuron that connected the hidden layer to the output layer.Wjkwas the weight between the input layer and the hidden layer,b2jwas the bias,andθkwas the threshold of output layer neurons.
The calculation process of the BP neural network was divided into the forward propagation of information and the back propagation of errors (Zhanget al.,2018).First,the model input information into the network through the input layer,calculated the output value of the neurons corresponding to the hidden layer through the hidden layer transfer functionf(x),and continued to spread the error backwards until the prediction results from the output layer were obtained.Supposed the output of thejth neuron in the hidden layer wasHj:
The model compared the predicted results with the actual results to determine whether the error was within expectations.Otherwise,the error would be propagated back along the network.The model defined the mean square error as the loss function of the network (Huanget al.,2019).Then,the model adjusted the network weight threshold according to the loss function:
Where,pwas the number of samples,was the value of the sample,andrepresented the network prediction output.The above steps were repeated until the network training conditions were met.
Model initial weight optimization
The real-time prediction model of the amount of manure was established using a BP neural network;However,it had problems such as the randomness of weight threshold initialization (Zhanget al.,2019),insufficient global search ability and ease of falling into local optima (Lei and Yuan,2020).In this article,a genetic algorithm (GA),particle swarm optimization(PSO) algorithm and mind evolutionary algorithm(MEA) were used to optimize and compare models(Zhaoet al.,2016).The optimization process of the initial weight threshold of the algorithm was divided into three main parts:
1) Mapping coding
The algorithm mapped the solution space to the coding space according to the BP neural network structure.The encoding lengths=M×N+M+N+N×K+K+K;M×Nwas the number of weights from the input layer to the hidden layer,the bias of the input layer wasM,the number of weights from the hidden layer to the output layer wasN×K,the bias of the hidden layer wasK,the number of hidden layer thresholds wasN,and the number of output layers thresholds wasK.
2) Calculating optimal individual
Different optimization algorithms had different optimization methods.In this study,the genetic algorithm used the inverse of the SSE (sum of squared errors) to score individuals (Zhuet al.,2019),where the highest score was chosen as the winner.The particle swarm algorithm used the MSE (mean squared error) as the evaluation index of the solution and continuously updated the individual extreme value and the group extreme value to obtain the global optimal solution (Liuet al.,2019).The mind evolutionary algorithm calculated the individual score using the inverse of the MSE,regardless of the update of the winning subpopulation and temporary subpopulation scores.The best individual in the optimal population was finally obtained (Chenet al.,2019).
3) Decoded the optimal individual and obtained the initial value corresponding to the model weight threshold.The optimization process is shown in Fig.3.
Fig.3 Schematic diagram of weight optimization algorithm
Determining model hyperparameters
In the machine learning model,the parameters that needed to be manually selected were called hyperparameters.In the model,the number of network layers,the number of neurons in the hidden layer,the learning rate and the weight optimization algorithm were all the factors that could affect the performance of the model.Improper selection would lead to underfitting or over-fitting problems.This article used the grid search cross-validation method to determine the model hyperparameters,within the specified parameter range,to adjust the parameters in turn to train the model,to find the most accurate parameter on the test set from all the parameters,and to minimize the error of the training model test set.Relatively few data were collected in this article.In order to avoid the problem of over-fitting,a three-layer neural network was selected,one of the weight optimization algorithms was selected to optimize the model,and then cross-validated the model with different learning rates and the number of neurons,and evaluated and compared all the trained models.Selected the learning rate and the number of hidden layer neurons that got the best performance of the model,and retrained with all the training set data as the best model optimized by this kind of weight algorithm.Repeated the above process,each weight algorithm (GA,PSO and MEA)would get the corresponding best model,which was established as the real-time prediction model of manure amount.The principle of cross-validation is shown in Fig.4.
Fig.4 Cross-validation flowchart
Results
Evaluation indexes
This article used commonly used statistical indicators in the BP neural network,including the coefficient of determination (R2),root mean square error (RMSE)and mean absolute error (MAE),to evaluate model performance.The statistical indicators were defined as follows:
Where,Xirepresented the target value of samplei,Yirepresented thetth predicted value of samplei,andrepresented the corresponding averages,andnwas the number of samples.
Cross-validation method to determine hyperparameters
The real-time prediction model of the amount of manure used the GA,PSO and MEA algorithms to conduct optimization separately.On this basis,each optimization algorithm used a different learning rate and number of hidden layer neurons for crossvalidation.The learning rate (Lr) was 0.001,0.01 and 0.1.The number of hidden layer neurons wasm,where(zwas the number of input variables,and l was the number of output variables).Therefore,each learning rate in this article corresponded to training 10 models with different numbers of hidden layer neurons.A total of 30 models were obtained for each optimization algorithm.This article selected the model hyperparameter with the smallest MSE as the optimal model hyperparameter for the weight optimization algorithm.The results are shown in Fig.5.
Fig.5 Cross-validation selection hyperparameter result
The hyperparameters of the real-time prediction model of manure volume established by BP,GA_BP,PSO_BP and MEA_BP after cross-validation are shown in Table 2.
Table 2 Model optimal hyperparameter
Model optimization process and results
This article used BP,GA_BP,PSO_BP and MEA_BP to train the real-time prediction model of manure volume.In the cross-validation process,the model was trained under different hyperparameter conditions,and Fig.6 showed the training process of the BP network.In the multiple cross-validation processes,it was found that some model results did not reach the target accuracy and easily converged to the local optimum.
Fig.6 BP neural network training process
This article used the weight optimization algorithm to optimize the initial weight of the model.
Fig.7 showed that the individuals in the genetic algorithm obtained the most adaptable individuals through continuous evolution,and the 70 generations of evolution basically obtained the best results.The particle swarm optimization algorithm minimized the MSE by continuously updating individual extreme values and group extreme values and iterated 60 generations to obtain the optimal solution.
Fig.7 GA and PSO optimization process
Fig.8 showed that the mind evolutionary algorithm obtained the superior subgroups and the temporary subgroupsviainitialization.Through convergence competition within populations,the five subpopulations in (a) and (b) matured and stabilized through seven iterations.The scores of temporary subgroup 1 and temporary subgroup 3 in Fig.7b were higher than those of superior subgroup 4 and superior subgroup 5.
Fig.8 MEA optimization process
Through alienation competition among subgroups,subgroup 2 became the superior subgroup in (c).Furthermore,temporary subgroups continued to iterate in (d),no temporary subgroups with a higher score than the superior subgroups appeared,and the algorithm ended.This article took the best individual in superior subgroup 1 to conduct decoding.
The manure volume prediction model used crossvalidation to determine the model hyperparameters corresponding to different weight optimization algorithms.On the basis of this approach,all the training sets were used to retrain four models using different optimization algorithms,and a test set was used to evaluate and compare models.It was found that within the specified learning rate and the number of hidden layer neurons,the real-time prediction model of manure volume optimized by the genetic algorithm had the highest coefficient of determination,which was 0.975.Fig.9 showed the accuracy comparison of these four models.Fig.10 showed the regression line corresponding to the model.
Fig.9 Model training results
Fig.10 Model training regression line
To verify the reliability of the combination of the cross-validation method and the weight optimization algorithm,a model that randomly selected hyperparameters within a given range was established for training.Lr=(0.001,0.01,0.1),andNeuron=(4-13).This randomly selected hyperparameter model trained a total of 1000 models.Combined with the crossvalidation model,first determined the hyperparameters through cross-validation and then trained 1 000 models for each optimization model,attaining a total of 5 000 models.TheR2variation range,averageR2,RMSE and MAE of the model obtained by each method were recorded.The results are shown in Table 3 and Fig.11.
Fig.11 R2 distribution
Table 3 Average performance
Compared with that of the real-time prediction model of manure volume with randomly selected hyperparameters,the averageR2of the model obtained by CV_BP training increased by 1.18%,the lower limit of the fluctuation range ofR2increased by 3.1%,and the RMSE and MAE decreased by 1.81 and 1.68,respectively.On the premise of determining the hyperparameters,the three optimization algorithms all increase the lower limit of the fluctuation range of the modelR2values.Compared with that of the model obtained by CV_BP,the averageR2of the models obtained by CV_GA_BP,CV_PSO_BP and CV_MEA_BP increased by 2.26%,2.0% and 1.92%,respectively,and the RMSE and MAE decreased correspondingly.
Validation of real-time prediction model for amount of manure
The comprehensive evaluation of all the models obtained by different training methods showed that for the model optimized using the weight optimization algorithm after model hyperparameter selection within the model hyperparameter range specified in this article,theR2distribution was more concentrated,and GA was the most obvious.This result showed that training the model with this method had a high probability of obtaining the optimal prediction model.Therefore,the cross-validation method combined with the genetic algorithm was selected as the final training method for the real-time prediction model of the amount of manure.Using all the training set data for training and verifying the generalization ability of the real-time prediction model of the amount of manure through the reserved test set data,theR2of the final model was 97.95%.The final result is shown in Fig.12.
Fig.12 Model verification
Discussion
There were many combinations of model hyperparameters,and it was impossible to train models for all the situations.The cross-validation parameters in this article were selected from three learning rates and a limited number of hidden layer neurons.Different optimization algorithms performed differently under different model hyperparameters.This article chose the genetic algorithm as the final weight optimization method.The results of this article could not indicate that the upper limit of the ability of the other two weight optimization algorithms was lower than the upper limit of the genetic algorithm and could only indicate that the genetic algorithm performed the best in the model established within the given hyperparameter range.
The dynamic prediction model established by the BP neural network achieved high accuracy in forecasting the amount of manure.However,there were still limitations and shortcomings of the application conditions.The experimental environment of this study was a closed pig house environment in winter in the north.In summer,pig house usually adopted mechanical ventilation combined with natural ventilation.The ammonia concentration in pig house was low,and it was impossible to detect the influence of manure accumulation on the ammonia concentration.Therefore,this study was affected by the geographical environment.Restricted by seasonal factors,it was only suitable for closed pig house in winter in the north.In the experimental design,the feeding time of the pig house was strictly controlled and the manure removal time was in the morning so that the time parameter in the model only depended on the time point when the maximumVNH3concentration appeared.However,by obtaining a parameter of the current time,the time difference with other activities could be obtained,and then,the input of nontemporal parameters such as the age and feed intake could be integrated to form the input of the model to obtain the predicted output of manure.However,in actual breeding management,the pig feeding time and manure removal time were difficult to accurately control due to human and other factors.Therefore,how to construct a prediction model of the amount of manure without a fixed feeding time and manure removal time would be the focus of the next step of this research.
Conclusions
In this article,the real-time amount of manure in a fattening pig house in winter was studied.This article selected the number of pigs in the shed,the age of the pigs,the feed intake of the day before in the pig house,the feed intake on the day,and the time of the maximumVNH3concentration in the pig house as the sample data.This article selected the amount of faeces as the target value.The dynamic prediction model of pig house dung pollution was realized by using a BP neural network.In addition,the GA,PSO algorithm and MEA with cross-validation were separately used to optimize the model.Further analyses allowed us to make the following conclusions:
1) The amount of manure model established by the BP neural network method provided the conditions for application in actual production.The current amount of manure in a pig house could be obtained in real-timeviathe dynamic input of time parameters,which had high reliability and could be used for predict pig house manure.This method could provide a reliable basis for the control of dung clean-up in pig house.
2) Compared with the particle swarm algorithm and the evolutionary thinking algorithm,the genetic algorithm performed better in the manure volume prediction model,with higher accuracy and stronger stability.The averageR2could reach 97.64%,when verifying the generalization ability of the final model using the test set,theR2was 97.95%.This results showed that the model was more applicable in realtime prediction of the amount of manure.
杂志排行
Journal of Northeast Agricultural University(English Edition)的其它文章
- Synergistic Effect of Adjuvants on Clomazone
- Effects of Biochar,Arbuscular Mycorrhizal Fungi and Nitrogen Application on Crop (Cichorium intybus L.) Growth and Soil Properties in Cadmium Contaminated Soil
- Effects of Tillage Practices and Straw Management on Physical Properties of Mollisols,Root Architecture and Maize Yield in Northeast China
- Isolation and Characterization of A High-efficiency Atrazinedegrading Strain Paenarthrobacter ureafaciens ZF1
- Regulation of Migration,Phagocytosis and Apoptosis of Human Neutrophils by Recombinant Human Intestinal Alkaline Phosphatase
- Investigation and Analysis of Grassland Plant Germplasm in Zhalantun City of Eastern Inner Mongolia