# Spatiotemporal Assessment and Correction of Gridded Precipitation Products in North Western Morocco
## 2 Materials and Methods
### Methodology
#### 2.3.5 Correction of Precipitation Estimates  
The spatial variability of precipitation in the Bouregreg watershed has been the subject of few analyses [71]. However, the sparse and uneven distribution of rain gauges raises concerns about the reliability of spatial interpolation methods such as inverse distance weighting and ordinary kriging [72]. Bias correction is a vital step in improving the accuracy and reliability of satellite precipitation estimates. The latter is indeed prone to systematic errors or biases that can impact the quality of the estimates. Bias correction techniques then aim to minimize these biases and bring the satellite-derived estimates in closer agreement with ground-based observations. In this regard, an advanced bias correction method will be applied to the most suitable model using artificial neural networks (ANN) for regression. ANN is a parallel distributed information processing system that exhibits characteristics similar to the biological neural networks in the human brain [73; 74]. The concept of artificial neurons was initially proposed by [PERSON] and [PERSON] in 1943 [75], and ANN does not rely on assumptions about variables, making it suitable for complex and unstructured problems. It is also robust to specification errors and serves as a parsimonious universal approximator [76; 77; 78].  
The constructed model is a linear stack of layers. Specifically, a sequential model of Keras. The first layer is a fully connected dense layer that has 64 neurons with a readback activation function and a predefined input shape. The next layers have 128, 256, and 128 neurons, respectively, with a relu activation function and which are hidden layers that nonlinearly transform input into output. The final layer is also a dense layer, but with a single neuron and no activation function specified, making it an output layer for a regression. The model uses a backpropagation learning approach to minimize a loss function that quantifies the difference between the predicted values and the actual values of the dependent variable. More precisely, for observation i, the prediction \(\hat{y}_{i}\) is obtained using the formula below. The mean squared error (MSE) is used as the loss function, which calculates the mean of the squares of the differences between the predictions and the actual values. The loss function is minimized by the Adam optimization algorithm, which adjusts weights and biases during training using error backpropagation. In summary, the model combines matrix multiplication, addition, nonlinear activation, and optimization techniques to learn a function that predicts the dependent variable given the independent variable.  
The tuning or training parameters include the number of epochs, which represents the total number of iterations performed by the model on the entire training data. Each epoch allows traversing the entire data once. In our model, we used 100 epochs, meaning that the model will be trained for 100 complete iterations. The batch_size parameter corresponds to the number of training samples used in a single iteration during the optimization of the model's weights. The training data are divided into batches, and each batch is used to update the model's weights. In this model, we have set batch_size = 32, indicating that each iteration will use a batch of 32 samples.  
\[\hat{Y}_{i}=f(w^{T}x_{i}+b)\hskip 42.679134 ptMSE=\frac{1}{N}\sum_{i=1}^{N}(Y_{i }-\hat{Y}_{i})^{2}\]  
where: \(x_{i}\) is the input vector; \(w\) is a weight vector; b is the bias (a constant) learned by the model during training; \(f\) is the activation function of each layer; \(N\) is the total number of observations in the training dataset; \(Y_{i}\) is the actual value of the dependent variable for observation \(i\); and \(\hat{y}_{i}\) is the model prediction for observation i.