# Spectral Data-Driven Prediction of Soil Properties Using LSTM-CNN-Attention Model
## 2 Materials and Methods
### Model and Methodology  
#### 2.5.1 Long Short-Term Memory Neural Network (LSTM)  
The Long Short-Term Memory (LSTM) model is an enhanced version of Recurrent Neural Networks (RNNs), specifically designed to address the vanishing and exploding gradient problems that occur when training on long sequences [40]. These issues hinder the learning of long-term dependencies in traditional RNNs. LSTM introduces memory cells with gating mechanisms that selectively retain or discard information across time steps [41].  
The LSTM model's key components are three gates that regulate the flow of information as follows:  
* The forget gate determines which parts of the previous memory cell state should be discarded.
* The input gate controls the incorporation of new information into the cell state.
* The output gate determines which portion of the cell state is passed as the hidden state.  
These gates enable the model to maintain and update long-term memory, effectively addressing the limitations of standard RNNs.  
Figure 2: Initial absorbance spectra and preprocessed spectral curves for mineral soil samples from the LUCAS 2015 topsoil database: (**a**) shows the original spectra, and (**b**) displays the preprocessed spectra. Both figures present the 5 th, 16 th, 50 th, 84 th, and 95 th percentiles to illustrate the variability within the dataset.  
The operations of the LSTM model are governed by the following set of equations:  
\[f_{t} =\sigma(W_{f}\cdot[h_{t-1},x_{t}]+b_{f}) \tag{1}\] \[i_{t} =\sigma(W_{t}\cdot[h_{t-1},x_{t}]+b_{i})\] (2) \[\tilde{C}_{t} =\tanh(W_{\mathrm{C}}\cdot[h_{t-1},x_{t}]+b_{\mathrm{C}})\] (3) \[C_{t} =f_{t}\times C_{t-1}+i_{t}\times\tilde{C}_{t}\] (4) \[o_{t} =\sigma(W_{o}\cdot[h_{t-1},x_{t}]+b_{o})\] (5) \[h_{t} =o_{t}\times\tanh(C_{t}) \tag{6}\]  
In these equations, \(f_{t}\), \(i_{t}\), and \(o_{t}\) correspond to the forget gate, input gate, and output gate, respectively. \(\sigma\) and \(\tanh\) denote the sigmoid and hyperbolic tangent activation functions, respectively, while \(W\) and \(b\) represent the weight matrix and bias term, respectively. The intermediate cell state and the long-term cell state are denoted by \(\tilde{C}_{t}\) and \(C_{t}\), respectively. Finally, \(t-1\) and \(t\) refer to the previous and current time steps, respectively, and \(x_{t}\) and \(h_{t}\) denote the input and output at the current time step.  
As illustrated in Figure 3, the LSTM model consists of three gates, each regulating different aspects of information flow within the memory cell. The forget gate \(f_{t}\) and input gate \(i_{t}\) update the cell state \(C_{t}\), while the output gate \(o_{t}\) governs the generation of the hidden state \(h_{t}\). This gated mechanism enables the LSTM to effectively capture long-term dependencies by selectively filtering information at each time step.  
By employing this architecture, the LSTM model is highly effective for tasks involving sequential data modeling, as it retains important patterns across extended sequences. In this study, the time step refers to the spectral band interval, rather than the time interval used in traditional time series analysis. Each spectral band is treated as part of a sequence, enabling the model to capture global dependencies between the bands.