# Prediction of Almond Nut Yield and Its Greenhouse Gases Emission Using Different Methodologies
## 2 Material and Methods
### Development of ANFIS  
A typical rule set for the common first order Takagi-Sugeno fuzzy model with two fuzzy _if-then_ rules is presented as follows [22]:  
Rule 1: If (_x_ is \(A\)1) and (_y_ is \(B\)1), then: \(Z\)1 = \(p\)1 _x + q_1 _y + r_1  
Rule 2: If (_x_ is \(A\)2) and (_y_ is \(B\)2), then: \(Z\)2 = \(p\)2 _x + q_2 _y + r_2  
where, \(p\)1, \(p\)2, \(q\)1, \(q\)2, \(r\)1, and \(r\)2 are linear, and \(A\)1, \(A\)2, \(B\)1, and \(B\)2 are non-linear parameters.  
A summarized architecture with two inputs and one output for the corresponding equivalent ANFIS is presented in Figure 2. Circle and square in the figure indicate fixed and adaptive nodes, respectively.  
In the first layer, each node creates the membership grades for their proper fuzzy sets. The outputs are given as follows [18]:  
\[\left\{\begin{array}{ll}Q_{i}^{1}=\mu_{A_{i}}(x).&i=1.2\\ Q_{i}^{1}=\mu_{B_{i-2}}(y).&i=3.4\end{array}\right. \tag{4}\]  
Figure 2: A schematic of an ANFIS structure.  
In Equation (4), \(\mu_{A_{i}}\) and \(\mu_{B_{i-2}}\) are the degrees of membership functions. By using the bell-shape membership function, \(\mu_{A_{i}}(x)\) is given as follows by Equation (5) [33]:  
\[\mu_{A_{i}}(x)=\frac{1}{1+\left[\left((x-c_{i})/a_{i}\right)^{2}\right]^{b_{i}}} \tag{5}\]  
where, \(a_{i}\), \(b_{i}\) and \(c_{i}\) are known as adjustable parameters.  
The fixed nodes of the second layer make a simple multiplication process. The outputs of the layer (firing strengths of the rules) could be calculated as follows (Equation (6)) [29]:  
\[Q_{i}^{2}=w_{i}=\mu_{A_{i}}(x)\mu_{B_{i}}(y).\qquad i=1.2 \tag{6}\]  
In the third layer, the ratio of one firing strength to the total rules' firing strengths is calculated. The outputs of normalized layer can be represented in the following form:  
\[Q_{i}^{3}=w_{i}^{\prime}=\frac{w_{i}}{w_{1}+w_{2}}.\qquad i=1.2 \tag{7}\]  
The fourth is the defuzzification layer. The outputs of this layer are displayed as follow:  
\[Q_{i}^{4}=w_{i}^{\prime}Z_{i}=w_{i}^{\prime}\left(p_{i}\ x+q_{i}\ y+r_{i} \right).\qquad i=1.2 \tag{8}\]  
In Equation (8), the three modifiable parameters \(\{p_{i},\ q_{i},\ r_{i}\}\) relate to the first-order polynomial.  
In the fifth layer, the single fixed-node described with \(S\) performs the total incoming signals as follows [36]:  
\[Q_{i}^{5}=overall\ output=\sum_{i}w_{i}^{\prime}Z_{i}=\frac{\sum_{i}w_{i}Z_{i} }{w_{1}+w_{2}}.\qquad i=1.2 \tag{9}\]  
Since the number of inputs in the present study was eight (\(x_{1},x_{2},x_{3},x_{4},x_{5},x_{6},x_{7}\), and \(x_{8}\)), two main schemes were developed by employing MATLAB software version 7.14.0.739 (R2012a), and the results were compared to obtain the best ANFIS algorithm. In the first scheme, the input variables were divided into four groups and each group was taken as an input variable for each ANFIS network (Figure 3). Therefore, the outputs of ANFIS 1 and ANFIS 2 were chosen as inputs for ANFIS 5. Similarly, the outputs of ANFIS 3 and ANFIS 4 were fed as inputs to ANFIS 6. Finally, the outputs of ANFIS 5 and ANFIS 6 made ANFIS 7 and the output almond nut yield was forecasted.  
In the second ANFIS scheme, the inputs were split up into three groups and each group was chosen as an input for ANFIS networks 1 to 3 (Figure 4). Eventually, The ANFIS 4 was made of the output values from ANFIS 1-3 to predict the almond nut yield.  
Figure 3: The first scheme of the ANFIS network developed to predict the almond nut yield.