## 2 Materials and Methods
### Methodology
#### 2.2.6 Phase 6: Data Improvement  
As the SPEs are prone to errors, it is crucial to enhance the estimations before they are ready for any hydrological applications. Therefore, in the present study, the IMERG satellite data are trained based on rain gauge data using the LSTM model. The standard LSTM architecture has memory blocks in the recurrent hidden layer that contain gates to control the information flow. The LSTM algorithm used in this research is the variant with \"peephole connections\" that let the gate layers consider the cell state, as shown in Figure 4. In the LSTM algorithm, there are three types of gates, which are the forgotten gate, input gate, and output gate. These gates are the memory cells that remember the state in the network. The flow of input and output activations will be controlled by the input gate and the output gate, respectively [77]. Firstly, the forget gate will reset the cell states from the beginning and scale the internal state of the cell before adding to the cell input. The sigmoid layer is used in the forget gate to make the decision. The next step contains the sigmoid layer which is the input gate layer that decides what values to update and the tanh layer that creates a vector of new candidate values. The new cell state was updated from the old cell state by considering what to forget and what new information to store with the time. The output will be based on the cell state by filtering with the sigmoid layer that decides which part of the cell state to output, put the cell state through tanh, and multiply it by the output of the sigmoid gate. Equations (8)-(13) were used to compute a mapping from the input sequence \(x=(x_{i},\ldots,x_{T})\) to the output sequence \(y=(y_{i},\ldots,y_{T})\) iteratively with time) \(t=1\) to T for the LSTM algorithm used. \[i_{t}=\sigma(W_{ic}c_{t-1}+W_{ih}h_{t-1}+W_{ix}x_{t}+b_{i}) \tag{8}\]  
\[f_{t}=\sigma(W_{fc}c_{t-1}+W_{fh}h_{t-1}+W_{fx}x_{t}+b_{f}) \tag{9}\]  
\[o_{t}=\sigma(W_{oc}c_{t}+W_{oh}h_{t-1}+W_{ox}x_{t}+b_{o}) \tag{10}\]  
\[c_{t}=f_{t}\odot c_{t-1}+i_{t}\odot\tanh(W_{ch}h_{t-1}+W_{cx}x_{t}+b_{c}) \tag{11}\]  
\[h_{t}=o_{t}\odot\tanh(c_{t}) \tag{12}\]  
\[y_{t}=W_{yh}h_{t}+b_{y} \tag{13}\]  
\(W\) is the matrix weight for the gates (\(i\) for input gate, \(f\) for forget gate, \(o\) for output gate). \(c\) and \(h\) are, respectively, the cell activation vector and cell output activation vector. \(\sigma\) is the sigmoid function, whereas \(\odot\) is the Hadamard product. The proposed LSTM model was developed in Python that utilizes Pytorch to train IMERG data based on observations of rain gauge data. For grids that contain complete satellite and rain gauge data (10 years), the data are merged as per IMERG grids and divided whereby 2/3 of the data were used for training and the remaining 1/3 were used for validation purposes. IMERG and rain gauge data are loaded into tensors which constitute the Numpy alike n-dimensional array. The tensors are commonly used in deep learning modeling. In the single layer model, a sliding window approach is employed, where a sequence length of four IMERG records is utilized to predict a single rainfall record. The prediction is made with reference to the available rain gauge data. The daily IMERG data were trained for each grid with an epoch of 20,000. The LSTM model built is trained  
Figure 4: Proposed LSTM algorithm. with \(MSE\) loss (Equation (14) shows the \(MSE\) function). It creates a criterion whereby it measures the squared error (squared L2 norm) between each element in the input \(x\) and target \(y\). \[MSE=\frac{\sum_{i=1}^{n}(x_{i}-y_{i})^{2}}{n} \tag{14}\]  
The uncertainty of parameters can be reduced with the use of robust optimization algorithms [78]. Optimization is critical in LSTM training as it involves finding the optimal set of parameters to minimize the loss function. One of the popular optimizers is the adaptive moment estimation (ADAM) optimizer which combines the benefits of the both momentum and adaptive learning rate methods.