# Tuning ANN Hyperparameters for Forecasting Drinking Water Demand
## 2 Methods and Materials
### Methods  
#### 2.2.1 Methodology Structures  
This section presents a description of the methodology used for the proposed investigation. It is worth noting that the training of a neural network model is an optimisation procedure aiming to build up the more performing model to accomplish a defined task. Due to the nature of this optimisation, the model resulting from the training procedure is slightly different even adopting the same set of parameters. This is due to the fact that ANN algorithms use randomness during learning to help finding the best model and avoiding the local optima. For this reason, it is proposed to perform an iterative investigation to address this stochastic component. Figure 3 summarises the proposed investigation methodology. Figure 3 shows the proposed iterative grid search procedure, whose aim is to assess the hyperparameters tuning in the context of water demand forecasting. The procedure, which is repeated \(N\) times, consists of the problem definition, the Neural Network selection, the combination of variables testing and finally the evaluation of each model. The grid search has carried out for each problem, which is defined for a selected dataset with forecasting horizon ranges among 1, 6, 24, 168 h. For the sake of clarity, the horizon means the number of next hourly demand values that the model has to predict. Hereafter, the ANN architecture to analyse can be chosen from FFNN, LSTM, GRU and SRNN. Several combinations of variables have been tested including nodes and layers, which constitute  
Figure 1: Full length of the time series of water consumption adopted in this study. (**a**) depicts the synthetic time series (\(ts1\)), whereas (**b**) represents a real consumption of a WDS in Trentino (\(ts2\)). Figure 2: A weekly view of the two time series. (**a**) and (**b**) show the intra-daily behaviour of \(ts1\) and \(ts2\), respectively. ANN structure and also the set of inputs. These latter comprise both 2 different set of past observation but also a set of other indicators that are simple variables that give useful information about the time of the prediction. These are the day type, which indicates whether it is a working day or not, the actual month, whose aim is to give information about the seasonality and the actual hour which is a number indicating the hour target of the prediction and suggests to the model the daily behaviour of the water demands. A summary of the selected parameters is proposed in Table 1.  
Then, the 24 combinations of layers and nodes selected for this investigation are iteratively tested to evaluate their performances. The nodes and layers combinations are reported in Table 2.  
The iteration is performed \(N\) times for each of the 8 problems consisting of 4 prediction horizons for the 2 case studies. The number of iteration has been selected after a stochastic analysis of the process, which has been reported in Section 3.1. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Horizon** & **Batch** & **Set of Inputs 1** & **Set of Inputs 2** & **Other Indicators** \\ \hline
1 h & 24 & \(q_{t-1}\), \(q_{t-2}\), \(q_{t-3}\), \(q_{t-23}\) & \(q_{t-144}\), \(q_{t-167}\), \(q_{t-168}\) & Actual hour, Actual month, Day type \\
6 h & 4 & \(q_{t-1}\),..., \(q_{t-6}\), \(q_{t-18}\),..., \(q_{t-23}\), & \(q_{t-1}\),..., \(q_{t-12}\), \(q_{t-18}\),..., \(q_{t-24}\), \(q_{t-43}\), & Actual hour, Actual month, Day type \\  & & \(q_{t-43}\), \(q_{t-44}\), \(q_{t-45}\) &..., \(q_{t-48}\), \(q_{t-163}\),..., \(q_{t-168}\) & Actual hour, Actual month, Day type \\
24 h & 1 & \(q_{t-1}\),..., \(q_{t-24}\), \(q_{t-143}\),..., & \(q_{t-1}\),..., \(q_{t-24}\), \(q_{t-142}\),..., \(q_{t-168}\) & Actual hour, Actual month, Day type \\  & & \(q_{t-148}\) & & \\
168 h & 1 & \(q_{t-1}\),..., \(q_{t-24}\), \(q_{t-142}\),..., & \(q_{t-1}\),..., \(q_{t-168}\) & Actual hour, Actual month, Day type \\  & & \(q_{t-168}\) & & \\ \hline \hline \end{tabular}
\end{table}