# The Development of an Intelligent Monitoring System for Agricultural Inputs Basing on DBN-SOFTMAX

Authors: Ling Yang; V. Sarath Babu; Juan Zou; Xu Can Cai; Ting Wu; Li Lin
Journal: Journal of Sensors
 (2018)

---

## Abstract

To solve the problem of unreliability of traceability information in the traceability system, we developed an intelligent monitoring system to realize the real-time online acquisition of physicochemical parameters of the agricultural inputs and to predict the varieties of input products accurately. Firstly, self-developed monitoring equipment was used to realize real-time acquisition, format conversion and pretreatment of the physicochemical parameters of inputs, and real-time communication with the cloud platform server. In this process, LoRa technology was adopted to solve the wireless communication problems between long-distance, low-power, and multinode environments. Secondly, a deep belief network (DBN) model was used to learn unsupervised physicochemical parameters of input products and extract the input features. Finally, these input features were utilized on the softmax classifier to establish the classification model, which could accurately predict the varieties of agricultural inputs. The results showed that when six kinds of pesticides, chemical fertilizers, and other agricultural inputs were predicted through the system, the prediction accuracy could reach 98.5%. Therefore, the system can be used to monitor the varieties of agrarian inputs effectively and use in real-time to ensure the authenticity and accuracy of the traceability information.


---

## Body

## 1. Introduction

The traceability system of agricultural products is a powerful tool for solving the food safety issues [1]. The information on the farm inputs, such as pesticides and fertilizers used for cultivation, is one of the most concerned problems of the consumers. Currently, some companies have established their own traceability system of agricultural products [2]. However, it is reasonable that the consumers do not trust the appreciable information recorded by the producers themselves because of the lack of supervision. Therefore, the establishment of a traceability system, which can record the information timely, accurately, and ultimately is an urgent need.There have been many reports about the rapid techniques for detection of agricultural inputs. To name a few, Deng et al. established a liquid chromatography-tandem mass spectrometry (LC-MS) method for the simultaneous determination of benzoylurea pesticide residues in vegetables [3]. Zheng et al. found LC-MS method for the detection of pesticide residues in milk [4]. Selisker et al. used a competitive enzyme-linked immunosorbent assay (ELISA) to detect paraquat [5]. Alcocer et al. have developed a polyclonal antibody for detection of organophosphorus pesticides [6]. Kumaran and Tran-Minh used cholinesterase electrode to detect pesticides [7]. Chough et al. used a carbon electrode to identify the organophosphorus insecticide [8]. Seemingly, many of the rapid detection techniques for agricultural inputs have been established. However, most of the current monitoring of agricultural input information is still a kind of residue detection of the postproduction stage, and it is still difficult to monitor the data via real-time online. Furthermore, the current established traceability system records the traceability information, which is mainly entered manually; therefore, the information is not timely and accurate.It is desirable to seek an alternative method to overcome these drawbacks. In this report, based on sensors and DBN-SOFTMAX algorithm, we developed an intelligent monitoring system for the agricultural inputs. Different from chemical-based agrarian inputs detection methods described above. This paper proposed using the sensors arranged in the soil to realize the monitoring and prediction of farming inputs. In general, sensors were employed in agriculture to achieve environmental monitoring such as moisture and temperature [9, 10] or to attain precise agricultural control [11]. In this paper, the sensors placed in the soil were used to collect the physicochemical characteristics of the inputs such as pH and EC value, and then the artificial intelligence algorithm was used to analyze the above sensor data and finally realized the intelligent monitoring and prediction of agricultural inputs.


## 2. Monitoring System Design

### 2.1. Working Principles and Overall Architecture

The overall structure of the intelligence-monitoring platform for agricultural inputs is shown in Figure1.Figure 1
The overall system architecture.The monitoring equipment collects data every 15 seconds to obtain the physicochemical parameters of agricultural inputs, such as pH value, electronic conductivity (EC), and temperature, in real time. After data preprocessing, analog-to-digital conversion, and RS485 [12] format conversion, LoRa (long range) module transmits the data to the LoRa gateway [13] and converts them into the RJ45 format. Subsequently, the data will be received and stored in the cloud server, and data cleaning and reduction process are performed to obtain useful data for further modeling and classification. During the modeling process, the input data is continuously increased to the training samples, and the model is updated once a week to obtain more accurate prediction results.


### 2.2. Hardware Design

The monitoring system mainly consists of sensor module, low-power digital processor, multichannel AD/DA conversion module, RS485 serial communication module, LoRa wireless communication module, and solar power module. The sensor module includes a pH sensor, an EC sensor, and a temperature sensor. The RS485 serial port communication module provides multisensor data fusion service. It uses polling mode to collect different sensor data of the same monitoring point through the RS485 interface to complete multisensor data fusion. LoRa wireless communication module developed by LoRa spread spectrum chip SX1278; its transmission distance and penetration ability are more than one time higher than those of traditional FSK [14]. In LoRa wireless communication, the capability of error correction is stronger since the algorithm of cyclic interleaving error correction coding is expected to be adopted. The maximum continuous error correction is 64 bits, which can reduce the retransmission of a large number of erroneous data packets, to improve the anti-interference performance and transmission distance. The hardware structure of the monitoring system is shown in Figure 2.Figure 2
The hardware structure of monitor terminal.


### 2.3. Software Design

#### 2.3.1. The LoRa Node Software Design

There are three kinds of nodes in LoRA, namely, sensor, routing, and aggregation nodes. The routing node is responsible for forwarding data. The aggregation node does not collect data, but as a control center, it sends synchronization information to the monitoring network and the received data to the local monitoring and remote monitoring centers. The corresponding node software is designed to perform the functions of each node. In this paper, the sensor node was used as an example to introduce the software design method. The C language was used to develop software, and the flow chart of the program is shown in Figure3:Figure 3
The node program flow.The entire programming process uses the modular design, mainly including equipment initialization, data acquisition and processing, serial communication, and wireless communication. PC monitoring controls acquisition cycle and acquisition command and controlling center software. If the node software receives the acquisition command sent by the PC monitoring center program, it immediately responds and transmits the collected data to the corresponding sensor according to different Modbus protocol commands.


#### 2.3.2. The Monitoring Center Software Design

The software workflow diagram is shown in Figure4. The monitoring center software uses C# to develop and communicate with the LoRa gateway module through TCP/IP network programming and obtains monitoring data transmitted by the LoRa gateway to the Internet network. The monitoring software mainly includes parameters setting, real-time monitoring, data processing, and other functions. Parameter setting function is to set the acquisition cycle, acquisition Modbus command, and other parameter settings. The real-time monitoring function is to collect sensor data in real time. A data processing function included calling DBN-SOFTMAX prediction model code, analyzing the received data, matching the established model, and predicting the varieties of inputs.Figure 4
The software workflow.


## 2.1. Working Principles and Overall Architecture

The overall structure of the intelligence-monitoring platform for agricultural inputs is shown in Figure1.Figure 1
The overall system architecture.The monitoring equipment collects data every 15 seconds to obtain the physicochemical parameters of agricultural inputs, such as pH value, electronic conductivity (EC), and temperature, in real time. After data preprocessing, analog-to-digital conversion, and RS485 [12] format conversion, LoRa (long range) module transmits the data to the LoRa gateway [13] and converts them into the RJ45 format. Subsequently, the data will be received and stored in the cloud server, and data cleaning and reduction process are performed to obtain useful data for further modeling and classification. During the modeling process, the input data is continuously increased to the training samples, and the model is updated once a week to obtain more accurate prediction results.


## 2.2. Hardware Design

The monitoring system mainly consists of sensor module, low-power digital processor, multichannel AD/DA conversion module, RS485 serial communication module, LoRa wireless communication module, and solar power module. The sensor module includes a pH sensor, an EC sensor, and a temperature sensor. The RS485 serial port communication module provides multisensor data fusion service. It uses polling mode to collect different sensor data of the same monitoring point through the RS485 interface to complete multisensor data fusion. LoRa wireless communication module developed by LoRa spread spectrum chip SX1278; its transmission distance and penetration ability are more than one time higher than those of traditional FSK [14]. In LoRa wireless communication, the capability of error correction is stronger since the algorithm of cyclic interleaving error correction coding is expected to be adopted. The maximum continuous error correction is 64 bits, which can reduce the retransmission of a large number of erroneous data packets, to improve the anti-interference performance and transmission distance. The hardware structure of the monitoring system is shown in Figure 2.Figure 2
The hardware structure of monitor terminal.


## 2.3. Software Design

### 2.3.1. The LoRa Node Software Design

There are three kinds of nodes in LoRA, namely, sensor, routing, and aggregation nodes. The routing node is responsible for forwarding data. The aggregation node does not collect data, but as a control center, it sends synchronization information to the monitoring network and the received data to the local monitoring and remote monitoring centers. The corresponding node software is designed to perform the functions of each node. In this paper, the sensor node was used as an example to introduce the software design method. The C language was used to develop software, and the flow chart of the program is shown in Figure3:Figure 3
The node program flow.The entire programming process uses the modular design, mainly including equipment initialization, data acquisition and processing, serial communication, and wireless communication. PC monitoring controls acquisition cycle and acquisition command and controlling center software. If the node software receives the acquisition command sent by the PC monitoring center program, it immediately responds and transmits the collected data to the corresponding sensor according to different Modbus protocol commands.


### 2.3.2. The Monitoring Center Software Design

The software workflow diagram is shown in Figure4. The monitoring center software uses C# to develop and communicate with the LoRa gateway module through TCP/IP network programming and obtains monitoring data transmitted by the LoRa gateway to the Internet network. The monitoring software mainly includes parameters setting, real-time monitoring, data processing, and other functions. Parameter setting function is to set the acquisition cycle, acquisition Modbus command, and other parameter settings. The real-time monitoring function is to collect sensor data in real time. A data processing function included calling DBN-SOFTMAX prediction model code, analyzing the received data, matching the established model, and predicting the varieties of inputs.Figure 4
The software workflow.


## 2.3.1. The LoRa Node Software Design

There are three kinds of nodes in LoRA, namely, sensor, routing, and aggregation nodes. The routing node is responsible for forwarding data. The aggregation node does not collect data, but as a control center, it sends synchronization information to the monitoring network and the received data to the local monitoring and remote monitoring centers. The corresponding node software is designed to perform the functions of each node. In this paper, the sensor node was used as an example to introduce the software design method. The C language was used to develop software, and the flow chart of the program is shown in Figure3:Figure 3
The node program flow.The entire programming process uses the modular design, mainly including equipment initialization, data acquisition and processing, serial communication, and wireless communication. PC monitoring controls acquisition cycle and acquisition command and controlling center software. If the node software receives the acquisition command sent by the PC monitoring center program, it immediately responds and transmits the collected data to the corresponding sensor according to different Modbus protocol commands.


## 2.3.2. The Monitoring Center Software Design

The software workflow diagram is shown in Figure4. The monitoring center software uses C# to develop and communicate with the LoRa gateway module through TCP/IP network programming and obtains monitoring data transmitted by the LoRa gateway to the Internet network. The monitoring software mainly includes parameters setting, real-time monitoring, data processing, and other functions. Parameter setting function is to set the acquisition cycle, acquisition Modbus command, and other parameter settings. The real-time monitoring function is to collect sensor data in real time. A data processing function included calling DBN-SOFTMAX prediction model code, analyzing the received data, matching the established model, and predicting the varieties of inputs.Figure 4
The software workflow.


## 3. DBN-SOFTMAX Algorithm and Modeling

### 3.1. The DBN-Based Feature Extraction Method

Restricted Boltzmann Machine (RBM) [15], which was part of DBN [16, 17], could extract features that are more abstract and significantly improve the ability of neural network generalization [18]. Each RBM was a two-layer model that contained only one hidden layer, and each RBM training output was used as the input for the next RBM.


#### 3.1.1. Restricted Boltzmann Machine (RBM)

Ifθ=Wij,ai,bj, where Wijrepresented the connection weight between the visible unit i and the hidden element j. m,n was the number of hidden cells and visible cells, respectively. Both the visible and hidden units were binary variables. That is, ∀i,j,vi∈0,1,hj∈0,1, ai was the offset of the visible element i, bj was the offset of the visible element j, T was the number of samples, hwas a hidden layer unit, and vwas a visible layer unit.RBM was an undirected graph model [19, 20] which was used to solve the value of the parameter θ, to fit the given training data, and the extracted feature (Figure 5).Figure 5
The RBM model.RBM task was used to fit the input training data, figured out the optimal parameterθ, and completed the feature extraction. The parameter θ could be learned in the training set to maximize the logarithmic likelihood function. The formula was as follows:
(1)θ∗=argmaxLθ=argmax∑t=1TlogPVt∣θ,where
(2)Lθ=∑t=1TlogPVt∣θ=∑t=1Tlog∑hPVt,h∣θ=∑t=1Tlog∑hexp−EVt,h∣θ−log∑v∑hexp−Ev,h∣θ.The key to solving the optimal parameterθ∗ was to obtain the partial derivative of logPVt∣θ for Wij,ai,bj, and other parameters. Assuming that θ′was a parameter value of θ, the logarithmic likelihood function concerning θ′ was
(3)∂L∂θ′=∑t=1T∂∂θ′log∑hexp−EVt,h∣θ−log∑v∑hexp−Ev,h∣θ=∑t=1T∑hexp−EVt,h∣θ∑hexp−EVt,h∣θ×∂−EVt,h∣θ∂θ−∑v∑hexp−Ev,h∣θ∑v∑hexp−Ev,h∣θ×∂−Ev,h∣θ∂θ=∑t=1T∂−EVt,h∣θ∂θPh∣Vt,θ−∂−Ev,h∣θ∂θPv,h∣θ.Since the number of samplesT was known, the partial derivative of the logarithmic likelihood function for the connection weight Wij, the offset aiof the visible layer element, and the offset bj of the hidden layer unit could be expressed by Ph∣Vt,θ and Pv,h∣θ. Ph∣Vt,θ was a hidden probability distribution of training sample Vt; Pv,h∣θwas a joint probability function for a given state (v, h); the function was
(4)Pv,h∣θ=e−Ev,h∣θZθ,where Ev,h∣θ was the energy function of RBM and Zθ was the normalization factor.
(5)Ev,h∣θ=−∑i=1naivi−∑j=1mbjhj−∑i=1n∑j=1mviWijhj,Zθ=∑v,he−Ev,h∣θ.


#### 3.1.2. CD Algorithm

It has been shown that the normalization factorZθ was difficult to be solved [21]. Therefore, the joint probability function Pv,h∣θ was also difficult to calculate. To solve this problem, the fast learning algorithm based on contrast divergence was used to training data, and the steps were as follows:
(1)
Pv,h∣θ was given by the formula Pv,h∣θ=e−Ev,h∣θ/Zθ, Pv∣θ=1/Zθ∑he−Ev,h∣θ
(2)
The RBM network structure was connected between layers, no connection within the layer and the structure of symmetry, i.e., when the state of the visible cell was fixed, an activating probability of thejth hidden element was
(6)Phj=1∣v,θ=σbj+∑iviWij.When the state of the hidden cell was fixed, activating probability of theith hidden element was
(7)Pvi=1∣h,θ=σai+∑jhjWij.The binary state of all hidden layer units was calculated from equation (6). After the state of all hidden layer units was determined, the ith visible unit vivalue of 1 probability according to equation (7) was determined, and a reconstruction of the visible layer was created
(3)
The parameter updated formula in the data training process was as follows:
(8)∆Wij=ϵvihjdata−vihjrecon,∆ai=ϵvidata−virecon,∆bj=ϵhjdata−hjrecon,where ε was the learning rate, and ∙recon was the distribution that represented the reconstructed model definition.


### 3.2. The Softmax Classifier

In the above process, what is finally obtained was the feature values ofx(i). However, in the prediction of input varieties, it was necessary to categorize output and to add a softmax classifier [22] to the output layer to organize the learned feature values. The diagrammatic drawing of the softmax classifiers was presented in Figure 6. The marked training set x1,y1,x2,y2,…,xm,ym, among yj∈1,2,…,k representative training sample xi is k. The given test input xi, which is the classification model calculates the probability that it belongs to each category.Figure 6
The softmax classifier.Thus, to a sample set withk types, output k-dimensional vector to represent the probability vector. The jth element in the probability vector represents the probability of belonging to the jth category, and the sum of values of elements is 1. Specifically, our hypothesis function hθx is shown as
(9)hθxipyi=1∣xi;θpyi=2∣xi;θ⋮pyi=k∣xi;θ=1∑j=1keθjTxieθ1Txieθ2Txi⋮eθkTxi=p1p2⋮pk.Amongθ1,θ2,θ3,…,θk are network model parameters, as
(10)θ=−θ1T−−θ2T−⋮−θkT−,1∑j=1keθjTxi,this item mainly restricts the probability values from 0 to 1, which the sum of the probability values is 1.In equation (9), the probability of the sample xi output by the classifier belonging to class j is (1true=1,1false=0):
(11)pyi=j∣xi;θ=eθjTxi∑j=1keθjTxi=p1=∏j=1kpj1yi=j.The likelihood function corresponding to training samples is(12)Lθ=∏i=1mpyi=j∣xi;θ=∏i=1m∏j=1kpj1yi=j,lθ=logLθ=∑i=1m∑j=1k1yi=jlogpj=∑i=1m∑j=1k1yi=jlogeθjTxi∑l=1keθlTxi.The parameter θ that maximizes the likelihood function as the optimal parameter of the softmax classifier. The cost function of the softmax regression model is
(13)Jθ=−1m∑i=1m∑j=1k1yi=jlogeθjTxi∑l=1keθlTxi.The cost function is minimized by the gradient descent method; the gradient function is as follows:(14)∇θjJθ=−1m∑i=1mxi1yi=j−pyi=j∣xi;θ.The softmax classifier has an unusual feature: it has a “redundant” set of parameters [23]. To illustrate the feature, if the vector μ was subtracted from the parameter vector θj, each θj becomes θj−μj=1,2,…,k. The function is shown as
(15)pyi=j∣xi;θ=eθj−uTxi∑l=1keθl−uTxi=eθjTxie−μTxi∑l=1keθl−uTxie−μTxi=eθjTxi∑l=1keθlTxi.In equation (15), we can see that the parameters θj−μand θj can both gain the same result. In other words, when θj is the optimal parameter, θj−μcan also have the same effect. It is the disadvantage of having redundant parameters in the softmax classifier. The loss function of the softmax classifier is distinctly nonconvex. Although there is a minimum point, the minimum value is in “flat” space and not at a single point. That is, all points in the area can get a minimum value. To make the cost function a strictly convex function, we need to add a weight attenuation term, as follows:
(16)Jθ=Jθ+λ2∑i=1m∑j=1kθij2,∇θjJθ=∇θjJθ+λθj.


### 3.3. Modeling

In establishing the model, the collected data were first normalized, and then DBN was used for unsupervised training to extract features. However, these features were not directly applicable to classification [24–26], so the softmax classifier was added to the output to perform supervised classification training. The flow diagram is shown in Figure 7.Figure 7
The flow diagram of modeling.


## 3.1. The DBN-Based Feature Extraction Method

Restricted Boltzmann Machine (RBM) [15], which was part of DBN [16, 17], could extract features that are more abstract and significantly improve the ability of neural network generalization [18]. Each RBM was a two-layer model that contained only one hidden layer, and each RBM training output was used as the input for the next RBM.


### 3.1.1. Restricted Boltzmann Machine (RBM)

Ifθ=Wij,ai,bj, where Wijrepresented the connection weight between the visible unit i and the hidden element j. m,n was the number of hidden cells and visible cells, respectively. Both the visible and hidden units were binary variables. That is, ∀i,j,vi∈0,1,hj∈0,1, ai was the offset of the visible element i, bj was the offset of the visible element j, T was the number of samples, hwas a hidden layer unit, and vwas a visible layer unit.RBM was an undirected graph model [19, 20] which was used to solve the value of the parameter θ, to fit the given training data, and the extracted feature (Figure 5).Figure 5
The RBM model.RBM task was used to fit the input training data, figured out the optimal parameterθ, and completed the feature extraction. The parameter θ could be learned in the training set to maximize the logarithmic likelihood function. The formula was as follows:
(1)θ∗=argmaxLθ=argmax∑t=1TlogPVt∣θ,where
(2)Lθ=∑t=1TlogPVt∣θ=∑t=1Tlog∑hPVt,h∣θ=∑t=1Tlog∑hexp−EVt,h∣θ−log∑v∑hexp−Ev,h∣θ.The key to solving the optimal parameterθ∗ was to obtain the partial derivative of logPVt∣θ for Wij,ai,bj, and other parameters. Assuming that θ′was a parameter value of θ, the logarithmic likelihood function concerning θ′ was
(3)∂L∂θ′=∑t=1T∂∂θ′log∑hexp−EVt,h∣θ−log∑v∑hexp−Ev,h∣θ=∑t=1T∑hexp−EVt,h∣θ∑hexp−EVt,h∣θ×∂−EVt,h∣θ∂θ−∑v∑hexp−Ev,h∣θ∑v∑hexp−Ev,h∣θ×∂−Ev,h∣θ∂θ=∑t=1T∂−EVt,h∣θ∂θPh∣Vt,θ−∂−Ev,h∣θ∂θPv,h∣θ.Since the number of samplesT was known, the partial derivative of the logarithmic likelihood function for the connection weight Wij, the offset aiof the visible layer element, and the offset bj of the hidden layer unit could be expressed by Ph∣Vt,θ and Pv,h∣θ. Ph∣Vt,θ was a hidden probability distribution of training sample Vt; Pv,h∣θwas a joint probability function for a given state (v, h); the function was
(4)Pv,h∣θ=e−Ev,h∣θZθ,where Ev,h∣θ was the energy function of RBM and Zθ was the normalization factor.
(5)Ev,h∣θ=−∑i=1naivi−∑j=1mbjhj−∑i=1n∑j=1mviWijhj,Zθ=∑v,he−Ev,h∣θ.


### 3.1.2. CD Algorithm

It has been shown that the normalization factorZθ was difficult to be solved [21]. Therefore, the joint probability function Pv,h∣θ was also difficult to calculate. To solve this problem, the fast learning algorithm based on contrast divergence was used to training data, and the steps were as follows:
(1)
Pv,h∣θ was given by the formula Pv,h∣θ=e−Ev,h∣θ/Zθ, Pv∣θ=1/Zθ∑he−Ev,h∣θ
(2)
The RBM network structure was connected between layers, no connection within the layer and the structure of symmetry, i.e., when the state of the visible cell was fixed, an activating probability of thejth hidden element was
(6)Phj=1∣v,θ=σbj+∑iviWij.When the state of the hidden cell was fixed, activating probability of theith hidden element was
(7)Pvi=1∣h,θ=σai+∑jhjWij.The binary state of all hidden layer units was calculated from equation (6). After the state of all hidden layer units was determined, the ith visible unit vivalue of 1 probability according to equation (7) was determined, and a reconstruction of the visible layer was created
(3)
The parameter updated formula in the data training process was as follows:
(8)∆Wij=ϵvihjdata−vihjrecon,∆ai=ϵvidata−virecon,∆bj=ϵhjdata−hjrecon,where ε was the learning rate, and ∙recon was the distribution that represented the reconstructed model definition.


## 3.1.1. Restricted Boltzmann Machine (RBM)

Ifθ=Wij,ai,bj, where Wijrepresented the connection weight between the visible unit i and the hidden element j. m,n was the number of hidden cells and visible cells, respectively. Both the visible and hidden units were binary variables. That is, ∀i,j,vi∈0,1,hj∈0,1, ai was the offset of the visible element i, bj was the offset of the visible element j, T was the number of samples, hwas a hidden layer unit, and vwas a visible layer unit.RBM was an undirected graph model [19, 20] which was used to solve the value of the parameter θ, to fit the given training data, and the extracted feature (Figure 5).Figure 5
The RBM model.RBM task was used to fit the input training data, figured out the optimal parameterθ, and completed the feature extraction. The parameter θ could be learned in the training set to maximize the logarithmic likelihood function. The formula was as follows:
(1)θ∗=argmaxLθ=argmax∑t=1TlogPVt∣θ,where
(2)Lθ=∑t=1TlogPVt∣θ=∑t=1Tlog∑hPVt,h∣θ=∑t=1Tlog∑hexp−EVt,h∣θ−log∑v∑hexp−Ev,h∣θ.The key to solving the optimal parameterθ∗ was to obtain the partial derivative of logPVt∣θ for Wij,ai,bj, and other parameters. Assuming that θ′was a parameter value of θ, the logarithmic likelihood function concerning θ′ was
(3)∂L∂θ′=∑t=1T∂∂θ′log∑hexp−EVt,h∣θ−log∑v∑hexp−Ev,h∣θ=∑t=1T∑hexp−EVt,h∣θ∑hexp−EVt,h∣θ×∂−EVt,h∣θ∂θ−∑v∑hexp−Ev,h∣θ∑v∑hexp−Ev,h∣θ×∂−Ev,h∣θ∂θ=∑t=1T∂−EVt,h∣θ∂θPh∣Vt,θ−∂−Ev,h∣θ∂θPv,h∣θ.Since the number of samplesT was known, the partial derivative of the logarithmic likelihood function for the connection weight Wij, the offset aiof the visible layer element, and the offset bj of the hidden layer unit could be expressed by Ph∣Vt,θ and Pv,h∣θ. Ph∣Vt,θ was a hidden probability distribution of training sample Vt; Pv,h∣θwas a joint probability function for a given state (v, h); the function was
(4)Pv,h∣θ=e−Ev,h∣θZθ,where Ev,h∣θ was the energy function of RBM and Zθ was the normalization factor.
(5)Ev,h∣θ=−∑i=1naivi−∑j=1mbjhj−∑i=1n∑j=1mviWijhj,Zθ=∑v,he−Ev,h∣θ.


## 3.1.2. CD Algorithm

It has been shown that the normalization factorZθ was difficult to be solved [21]. Therefore, the joint probability function Pv,h∣θ was also difficult to calculate. To solve this problem, the fast learning algorithm based on contrast divergence was used to training data, and the steps were as follows:
(1)
Pv,h∣θ was given by the formula Pv,h∣θ=e−Ev,h∣θ/Zθ, Pv∣θ=1/Zθ∑he−Ev,h∣θ
(2)
The RBM network structure was connected between layers, no connection within the layer and the structure of symmetry, i.e., when the state of the visible cell was fixed, an activating probability of thejth hidden element was
(6)Phj=1∣v,θ=σbj+∑iviWij.When the state of the hidden cell was fixed, activating probability of theith hidden element was
(7)Pvi=1∣h,θ=σai+∑jhjWij.The binary state of all hidden layer units was calculated from equation (6). After the state of all hidden layer units was determined, the ith visible unit vivalue of 1 probability according to equation (7) was determined, and a reconstruction of the visible layer was created
(3)
The parameter updated formula in the data training process was as follows:
(8)∆Wij=ϵvihjdata−vihjrecon,∆ai=ϵvidata−virecon,∆bj=ϵhjdata−hjrecon,where ε was the learning rate, and ∙recon was the distribution that represented the reconstructed model definition.


## 3.2. The Softmax Classifier

In the above process, what is finally obtained was the feature values ofx(i). However, in the prediction of input varieties, it was necessary to categorize output and to add a softmax classifier [22] to the output layer to organize the learned feature values. The diagrammatic drawing of the softmax classifiers was presented in Figure 6. The marked training set x1,y1,x2,y2,…,xm,ym, among yj∈1,2,…,k representative training sample xi is k. The given test input xi, which is the classification model calculates the probability that it belongs to each category.Figure 6
The softmax classifier.Thus, to a sample set withk types, output k-dimensional vector to represent the probability vector. The jth element in the probability vector represents the probability of belonging to the jth category, and the sum of values of elements is 1. Specifically, our hypothesis function hθx is shown as
(9)hθxipyi=1∣xi;θpyi=2∣xi;θ⋮pyi=k∣xi;θ=1∑j=1keθjTxieθ1Txieθ2Txi⋮eθkTxi=p1p2⋮pk.Amongθ1,θ2,θ3,…,θk are network model parameters, as
(10)θ=−θ1T−−θ2T−⋮−θkT−,1∑j=1keθjTxi,this item mainly restricts the probability values from 0 to 1, which the sum of the probability values is 1.In equation (9), the probability of the sample xi output by the classifier belonging to class j is (1true=1,1false=0):
(11)pyi=j∣xi;θ=eθjTxi∑j=1keθjTxi=p1=∏j=1kpj1yi=j.The likelihood function corresponding to training samples is(12)Lθ=∏i=1mpyi=j∣xi;θ=∏i=1m∏j=1kpj1yi=j,lθ=logLθ=∑i=1m∑j=1k1yi=jlogpj=∑i=1m∑j=1k1yi=jlogeθjTxi∑l=1keθlTxi.The parameter θ that maximizes the likelihood function as the optimal parameter of the softmax classifier. The cost function of the softmax regression model is
(13)Jθ=−1m∑i=1m∑j=1k1yi=jlogeθjTxi∑l=1keθlTxi.The cost function is minimized by the gradient descent method; the gradient function is as follows:(14)∇θjJθ=−1m∑i=1mxi1yi=j−pyi=j∣xi;θ.The softmax classifier has an unusual feature: it has a “redundant” set of parameters [23]. To illustrate the feature, if the vector μ was subtracted from the parameter vector θj, each θj becomes θj−μj=1,2,…,k. The function is shown as
(15)pyi=j∣xi;θ=eθj−uTxi∑l=1keθl−uTxi=eθjTxie−μTxi∑l=1keθl−uTxie−μTxi=eθjTxi∑l=1keθlTxi.In equation (15), we can see that the parameters θj−μand θj can both gain the same result. In other words, when θj is the optimal parameter, θj−μcan also have the same effect. It is the disadvantage of having redundant parameters in the softmax classifier. The loss function of the softmax classifier is distinctly nonconvex. Although there is a minimum point, the minimum value is in “flat” space and not at a single point. That is, all points in the area can get a minimum value. To make the cost function a strictly convex function, we need to add a weight attenuation term, as follows:
(16)Jθ=Jθ+λ2∑i=1m∑j=1kθij2,∇θjJθ=∇θjJθ+λθj.


## 3.3. Modeling

In establishing the model, the collected data were first normalized, and then DBN was used for unsupervised training to extract features. However, these features were not directly applicable to classification [24–26], so the softmax classifier was added to the output to perform supervised classification training. The flow diagram is shown in Figure 7.Figure 7
The flow diagram of modeling.


## 4. Experiment Design

In this experiment, we used six agricultural inputs, including phosphate (P2O5, SinoChem, China), potassium (K2O, SinoChem, China), compound fertilizer (carbamide, nitrogen phosphorus potassium, SouthRanch, China), Podol pesticide (TaoChun, China), imidacloprid (Bayer, Germany), and oxamoxime (HeYi, China), purchased from local stores in Guangzhou, China. The first three of these inputs were chemical fertilizers, the latter three were pesticides, and their aqueous solutions were placed in dilution ratios (500 : 1) for use. Eighteen pots of soil-filled bottom drainable basins were prepared and set in an open-air environment. The EC sensors, pH sensors, and moisture sensors were inserted into the soil, and the power was turned on to enable to collect the sensor data in real time. During the period from October 2016 to March 2017, 200 ml of each inputs aqueous solution was sprayed into three pots of soil. Over 50 experiments, the soil parameter data before and after the input, including moisture proportion (before input), conductivity (before input), the pH value (before input), moisture ratio (after input), conductivity (after input), and the pH value (after input) were recorded. 150 data were collected for each type of input product, and the total number of data was 900.


## 5. Results and Discussion

### 5.1. Data of Sensors

The sensor data before input were not the same in each experiment; the collected sensor data after input minus before input could better explain the characteristics of the input. Six agricultural inputs were sprayed into the soil, respectively, and pH, conductivity, and moisture data were collected before and after the input. In this paper, 20 times of experimental data were randomly selected for observation.Observing the collected pH values, before input they were close to 7, which was neutral. After applying six agricultural inputs, the pH value decreased. As shown in Figure8, the changes of pH at different inputs were similar and overlapped with each other. It indicates that there was no significant difference in the power of hydrogen during several agricultural inputs applied.Figure 8
Changes in pH before and after input.Further observation of changes in electrical conductivity (EC), since the EC value was very sensitive to moisture content, there was a significant error in the shift in the EC value observed separately. The EC value divided the moisture content, and the obtained ratio was counted as shown in Figure9. Observation shows that in general, EC changes in pesticides, including podol pesticide, imidacloprid, and oxamoxime were smaller, while fertilizers were comparatively larger. Changes of potassium had the most considerable EC value, and its value was more significant than the three; however, the EC value changes of pesticide were less than 1.5.Figure 9
Changes in EC/moisture before and after input.


### 5.2. Modeling and Analysis

Sensors collected the trained and relevant experimental data of the agricultural inputs prediction models. The main content of each data sample is input product category, the moisture proportion (before input), conductivity (before input), the pH value (before input), moisture ratio (after input), conductivity (after input), and pH value (after input). In establishing the model, the leave-one-out method [27] was used for the cross-validation to test the model’s performance. Each of the 900 samples was taken separately, and then the remaining 899 samples were used to build the model. The model independently tested each sample, and the results were averaged to obtain the average performance of the method.When using DBN for feature extraction, a four-layer neural network was established, the number of neurons in each layer was 300, 100, 20, and 6, respectively. The activation function of the hidden layer was “logsig”, the training method was the L-BFGS algorithm [28], and the output layer function was a softmax function. In DBN feature extraction, RBM used an unsupervised learning method to train each layer of RBM networks separately, ensuring that the feature information was preserved as much as possible during the mapping process. After the training was completed, a classifier was set at the last level of the DBN; using supervised fine-tuning, the best training results were obtained. Since each layer of RBM network only adjusted the weights in its own layer, it did not guarantee that the feature vector mapping of the entire DBN was optimal. After supervised fine-tuning, the process of RBM network training could be regarded as the initialization process of weight parameters of a deep neural network, which enabled the DBN network to overcome the disadvantages of the traditional BP network due to random initialization weight parameters and easy to fall into local optimum and long training time.During the training, the number of iterations was 400, the learning rate was 0.1, and the training error target was set to 0.001. After the training, the extracted feature data were shown in Table1:Table 1
The characteristic data table.
ya
Feature data
1
0.261774
0.51821
0.363377
0.333239
0.40386
0.748109
1
0.249594
0.569245
0.360975
0.317917
0.442481
0.728785
1
0.25111
0.560419
0.361024
0.32006
0.437188
0.730672
2
0.811001
0.796877
0.348194
0.270687
0.189169
0.231068
2
0.839929
0.777112
0.698331
0.380023
0.302937
0.187739
2
0.822922
0.811853
0.321081
0.268463
0.183998
0.220862
3
0.397166
0.347973
0.591175
0.642555
0.696136
0.526804
3
0.441901
0.3287
0.630434
0.696979
0.742546
0.464949
3
0.417766
0.325697
0.646081
0.692987
0.75344
0.477638
4
0.716266
0.526859
0.587048
0.715965
0.590975
0.389491
4
0.764408
0.593614
0.599644
0.594801
0.447832
0.317517
4
0.735743
0.50656
0.56267
0.718762
0.570059
0.368529
5
0.221322
0.570325
0.261664
0.264869
0.386502
0.750886
5
0.226302
0.555085
0.258739
0.26812
0.375292
0.751574
5
0.23323
0.578087
0.251799
0.265587
0.376804
0.743913
6
0.760376
0.252841
0.753006
0.841325
0.298932
0.814017
6
0.752798
0.194803
0.781346
0.848471
0.26095
0.846151
6
0.760472
0.275192
0.74997
0.839426
0.310604
0.809583
ay is for the types of agricultural inputs. 1: potassium fertilizer; 2: compound fertilizer; 3: imidacloprid; 4: Podol liquid; 5: oxamoxime; 6: phosphate fertilizer.Through unsupervised training of DBN and nonlinear mappings, the features were obtained from the input data, such as pH, moisture, and conductivity. After extracting features, the cohesion of the same types of agricultural inputs and the variances of different farm inputs could be better demonstrated. After dimensional reduction by the principal component analysis (PCA) method [29], the three-dimensional distribution of feature values and the three-dimensional distribution of original values were shown in Figures 10 and 11. It could be observed that the feature values extracted by DBN can be separated, but the initial input values without feature extraction were scattered and there were some confusion. Therefore, it was evident that using the extracted feature values for classification could achieve better prediction results.Figure 10
Three-dimensional distribution of feature values.Figure 11
Three-dimensional distribution of original values.We used this model for predicting the agricultural inputs. First, by applying the RBM-based DBN model, unsupervised training on raw data was carried out to improve the robustness of the network. Second, the feature data were obtained, and the softmax classifier was added to the back of DBN, the feature data were taken as the input, and the categories of inputs were taken as the output. Thirdly, the feature data and the tagged samples were combined to fine-tune the softmax classifier, and finally, the model was established to predict the accuracy. The result was shown in Figure12. When 900 samples were predicted, thirteen samples were wrongly predicted with the model accuracy of 98.5%.Figure 12
The predicted results of DBN-SOFTMAX for test sets. In the ordinate, 1: potassium fertilizer; 2: compound fertilizer; 3: imidacloprid; 4: Podol liquid; 5: oxamoxime; and 6: phosphate fertilizer.To evaluate the performance of the DBN-softmax model, BP-neural network and DBN-BP model were also established and the prediction accuracy of the input products was compared.As shown in Table2, the DBN-BP accuracy was higher than that of the BP neural network, because DBN adopted the unsupervised layer-wise [16] mechanism training mode. The weights gained through DBN were obtained by learning the structure of input data, which were close to the optimal global values. However, BP neural network, whose initial values were randomly set, was prone to problems such as local optimal and gradient diffusion, so it required manual adjustment parameters [30]. When DBN-BP was compared with DBN-SOFTMAX, we used the same DBN structure to extract features with different classifiers, so the prediction accuracy was the same. It indicated that the prediction accuracy depended mainly on the quality of feature extraction, and the results obtained by different classifiers were not very different.Table 2
The forecast accuracy comparison table.
Training data
Model
Input layer (neuron)
Hidden layer (neuron)
Output layer (neurons)
Accuracy
Raw data
BP
6
10
6
84.7%
Raw data
DBN-BP
6
300-100-20-6
6
97.8%
Raw data
DBN-SOFTMAX
6
300-100-20-6
6
98.5%Further research on the determination coefficient (R-Square) and root mean square error (RMSE) when testing model performance. This paper compared conventional modeling methods such as BP-NN and support vector machine (SVM) [31]. When establishing the SVM model, the nu-SVM algorithm was selected, and the radial basis function (RBF) was selected as the kernel function. The error penalty coefficient γ and the kernel function parameter nu were 0.255 and 1, which were determined by grid searching technique [32]. In the process of modeling, the calibration sets were used to build the model, and the leave-one-out method was used for cross-validation to test the robustness and adaptability of the model further.As shown in Table3, when the BP-NN model was observed, the performance of the calibration sets was the same as SVM. However, the determination coefficient of cross-validation was smaller than SVM, and the root mean square error was more extensive than SVM, revealing that the model was not as accurate and stable as the SVM model. When the DBN model was observed, it could be seen that after feature extraction, the determination coefficients of calibration sets and cross-validation were the largest compared to BP-NN and SVM, reaching 0.99 and 0.99, respectively. Meanwhile, the RMSE of calibration sets and cross-validation in the DBN model were the smallest, which were 0.03 and 0.15, respectively. So in general, compared to SVM and BP-NN, DBN was still considered to be the optimal modeling method.Table 3
DBN model performance comparison with BP-NN and SVM.
Models
R2cal
RMSEC
R2CV
RMSECV
DBN
0.99
0.03
0.99
0.15
BP-NN
0.99
0.09
0.94
0.40
SVM
0.99
0.09
0.98
0.21


## 5.1. Data of Sensors

The sensor data before input were not the same in each experiment; the collected sensor data after input minus before input could better explain the characteristics of the input. Six agricultural inputs were sprayed into the soil, respectively, and pH, conductivity, and moisture data were collected before and after the input. In this paper, 20 times of experimental data were randomly selected for observation.Observing the collected pH values, before input they were close to 7, which was neutral. After applying six agricultural inputs, the pH value decreased. As shown in Figure8, the changes of pH at different inputs were similar and overlapped with each other. It indicates that there was no significant difference in the power of hydrogen during several agricultural inputs applied.Figure 8
Changes in pH before and after input.Further observation of changes in electrical conductivity (EC), since the EC value was very sensitive to moisture content, there was a significant error in the shift in the EC value observed separately. The EC value divided the moisture content, and the obtained ratio was counted as shown in Figure9. Observation shows that in general, EC changes in pesticides, including podol pesticide, imidacloprid, and oxamoxime were smaller, while fertilizers were comparatively larger. Changes of potassium had the most considerable EC value, and its value was more significant than the three; however, the EC value changes of pesticide were less than 1.5.Figure 9
Changes in EC/moisture before and after input.


## 5.2. Modeling and Analysis

Sensors collected the trained and relevant experimental data of the agricultural inputs prediction models. The main content of each data sample is input product category, the moisture proportion (before input), conductivity (before input), the pH value (before input), moisture ratio (after input), conductivity (after input), and pH value (after input). In establishing the model, the leave-one-out method [27] was used for the cross-validation to test the model’s performance. Each of the 900 samples was taken separately, and then the remaining 899 samples were used to build the model. The model independently tested each sample, and the results were averaged to obtain the average performance of the method.When using DBN for feature extraction, a four-layer neural network was established, the number of neurons in each layer was 300, 100, 20, and 6, respectively. The activation function of the hidden layer was “logsig”, the training method was the L-BFGS algorithm [28], and the output layer function was a softmax function. In DBN feature extraction, RBM used an unsupervised learning method to train each layer of RBM networks separately, ensuring that the feature information was preserved as much as possible during the mapping process. After the training was completed, a classifier was set at the last level of the DBN; using supervised fine-tuning, the best training results were obtained. Since each layer of RBM network only adjusted the weights in its own layer, it did not guarantee that the feature vector mapping of the entire DBN was optimal. After supervised fine-tuning, the process of RBM network training could be regarded as the initialization process of weight parameters of a deep neural network, which enabled the DBN network to overcome the disadvantages of the traditional BP network due to random initialization weight parameters and easy to fall into local optimum and long training time.During the training, the number of iterations was 400, the learning rate was 0.1, and the training error target was set to 0.001. After the training, the extracted feature data were shown in Table1:Table 1
The characteristic data table.
ya
Feature data
1
0.261774
0.51821
0.363377
0.333239
0.40386
0.748109
1
0.249594
0.569245
0.360975
0.317917
0.442481
0.728785
1
0.25111
0.560419
0.361024
0.32006
0.437188
0.730672
2
0.811001
0.796877
0.348194
0.270687
0.189169
0.231068
2
0.839929
0.777112
0.698331
0.380023
0.302937
0.187739
2
0.822922
0.811853
0.321081
0.268463
0.183998
0.220862
3
0.397166
0.347973
0.591175
0.642555
0.696136
0.526804
3
0.441901
0.3287
0.630434
0.696979
0.742546
0.464949
3
0.417766
0.325697
0.646081
0.692987
0.75344
0.477638
4
0.716266
0.526859
0.587048
0.715965
0.590975
0.389491
4
0.764408
0.593614
0.599644
0.594801
0.447832
0.317517
4
0.735743
0.50656
0.56267
0.718762
0.570059
0.368529
5
0.221322
0.570325
0.261664
0.264869
0.386502
0.750886
5
0.226302
0.555085
0.258739
0.26812
0.375292
0.751574
5
0.23323
0.578087
0.251799
0.265587
0.376804
0.743913
6
0.760376
0.252841
0.753006
0.841325
0.298932
0.814017
6
0.752798
0.194803
0.781346
0.848471
0.26095
0.846151
6
0.760472
0.275192
0.74997
0.839426
0.310604
0.809583
ay is for the types of agricultural inputs. 1: potassium fertilizer; 2: compound fertilizer; 3: imidacloprid; 4: Podol liquid; 5: oxamoxime; 6: phosphate fertilizer.Through unsupervised training of DBN and nonlinear mappings, the features were obtained from the input data, such as pH, moisture, and conductivity. After extracting features, the cohesion of the same types of agricultural inputs and the variances of different farm inputs could be better demonstrated. After dimensional reduction by the principal component analysis (PCA) method [29], the three-dimensional distribution of feature values and the three-dimensional distribution of original values were shown in Figures 10 and 11. It could be observed that the feature values extracted by DBN can be separated, but the initial input values without feature extraction were scattered and there were some confusion. Therefore, it was evident that using the extracted feature values for classification could achieve better prediction results.Figure 10
Three-dimensional distribution of feature values.Figure 11
Three-dimensional distribution of original values.We used this model for predicting the agricultural inputs. First, by applying the RBM-based DBN model, unsupervised training on raw data was carried out to improve the robustness of the network. Second, the feature data were obtained, and the softmax classifier was added to the back of DBN, the feature data were taken as the input, and the categories of inputs were taken as the output. Thirdly, the feature data and the tagged samples were combined to fine-tune the softmax classifier, and finally, the model was established to predict the accuracy. The result was shown in Figure12. When 900 samples were predicted, thirteen samples were wrongly predicted with the model accuracy of 98.5%.Figure 12
The predicted results of DBN-SOFTMAX for test sets. In the ordinate, 1: potassium fertilizer; 2: compound fertilizer; 3: imidacloprid; 4: Podol liquid; 5: oxamoxime; and 6: phosphate fertilizer.To evaluate the performance of the DBN-softmax model, BP-neural network and DBN-BP model were also established and the prediction accuracy of the input products was compared.As shown in Table2, the DBN-BP accuracy was higher than that of the BP neural network, because DBN adopted the unsupervised layer-wise [16] mechanism training mode. The weights gained through DBN were obtained by learning the structure of input data, which were close to the optimal global values. However, BP neural network, whose initial values were randomly set, was prone to problems such as local optimal and gradient diffusion, so it required manual adjustment parameters [30]. When DBN-BP was compared with DBN-SOFTMAX, we used the same DBN structure to extract features with different classifiers, so the prediction accuracy was the same. It indicated that the prediction accuracy depended mainly on the quality of feature extraction, and the results obtained by different classifiers were not very different.Table 2
The forecast accuracy comparison table.
Training data
Model
Input layer (neuron)
Hidden layer (neuron)
Output layer (neurons)
Accuracy
Raw data
BP
6
10
6
84.7%
Raw data
DBN-BP
6
300-100-20-6
6
97.8%
Raw data
DBN-SOFTMAX
6
300-100-20-6
6
98.5%Further research on the determination coefficient (R-Square) and root mean square error (RMSE) when testing model performance. This paper compared conventional modeling methods such as BP-NN and support vector machine (SVM) [31]. When establishing the SVM model, the nu-SVM algorithm was selected, and the radial basis function (RBF) was selected as the kernel function. The error penalty coefficient γ and the kernel function parameter nu were 0.255 and 1, which were determined by grid searching technique [32]. In the process of modeling, the calibration sets were used to build the model, and the leave-one-out method was used for cross-validation to test the robustness and adaptability of the model further.As shown in Table3, when the BP-NN model was observed, the performance of the calibration sets was the same as SVM. However, the determination coefficient of cross-validation was smaller than SVM, and the root mean square error was more extensive than SVM, revealing that the model was not as accurate and stable as the SVM model. When the DBN model was observed, it could be seen that after feature extraction, the determination coefficients of calibration sets and cross-validation were the largest compared to BP-NN and SVM, reaching 0.99 and 0.99, respectively. Meanwhile, the RMSE of calibration sets and cross-validation in the DBN model were the smallest, which were 0.03 and 0.15, respectively. So in general, compared to SVM and BP-NN, DBN was still considered to be the optimal modeling method.Table 3
DBN model performance comparison with BP-NN and SVM.
Models
R2cal
RMSEC
R2CV
RMSECV
DBN
0.99
0.03
0.99
0.15
BP-NN
0.99
0.09
0.94
0.40
SVM
0.99
0.09
0.98
0.21


## 6. Conclusions

Based on the self-developed monitoring equipment and DBN-SOFTMAX model, we have developed a platform for intelligent monitoring of agricultural inputs; perform online and real-time monitoring on farms. When the agricultural inputs were applied in farms, we could compare the types of inputs and application time with the data entered by the administrators in the traceability system. Once the producers do not record the traceability information or input the wrong information, our system can capture related data timely and accurately, then automatically provides safety warning to the producers, to ensure that the traceability information is true and accurate. The intelligent monitoring platform will pave a new way for the development of traceability systems.



---

*Source: 6025381-2018-10-28.xml*