# Data-Driven Forecasting of Acute and Chronic Hepatitis B in Ukraine with Recurrent Neural Networks
## 3 Materials and Methods  
The monthly incidence of laboratory-confirmed acute and chronic hepatitis B was obtained from the open reporting system of the Public Health Center of the Ministry of Health of Ukraine [27]. The time series spans January 2018-December 2023. Reports for January-December 2024 were withheld for strict out-of-sample assessment. Case definitions follow the Ministry of Health standard; acute infection denotes clinical onset within six months of exposure, whereas chronic infection requires the persistence of HBsAgAg for at least six months. Monthly notifications are entered into the Public Health Center electronic registry under a compulsory laboratory confirmation scheme. Each record passes a built-in range and type validation before release. A completeness audit showed 0 missing months for 2018-2023, while the linear rise in the cumulative series further indicates uninterrupted reporting. Consequently, the 72-month training set provides a coherent basis for sequence learning. Two parallel time series were created for each category: the original monthly counts and their cumulative sums. To stabilise gradients, the values in the estimation sample were transformed to the unit interval by min-max scaling. Given a training vector \(x=(x_{1},\ldots,x_{\text{T}})\) the min-max transform is  
\[x_{t}^{*}=\frac{x_{t}-min_{1\leq j\leq T}x_{j}}{max_{1\leq j\leq T}x_{j}-min_{1 \leq j\leq T}x_{j}},\ t=1,\ldots,T. \tag{1}\]  
The corresponding inverse mapping applied to any forecast \(\hat{x}_{t}^{*}\) that lies in \([0,1]\) is  
\[\hat{x}_{t}=\widehat{x_{t}}^{*}\left(max1\leq j\leq Tx_{j}-min1\leq j\leq Tx_{ j}\right)+min_{1\leq j\leq T}x_{j}. \tag{2}\]  
The same transformation was applied to the validation and test splits. Predictions were inverse-scaled before evaluation. No missing observations were present, so no imputation was required. A deep sequence-to-one recurrent network was developed. The architecture of the model is presented in Figure 1.  
The first LSTM captures short-range patterns and passes only its final hidden state. The second propagates long-range dependencies by returning the full hidden sequence. The dense layer compresses the representation before the linear output neuron produces a one-step-ahead forecast. The total number of trainable parameters is 171,251. Separate networks were fitted to the acute and chronic series. Weight updates employed back-propagation through time with an adaptively decaying learning rate. For the acute model, the optimisation converged after 170 epochs. The chronic model stabilised after 50 epochs. These epoch counts are dictated by the early-stopping rule embedded in the draft code and were not altered. The loss function for gradient descent was the mean absolute percentage error (MAPE). Mean squared error (MSE) was monitored as a secondary diagnostic but not minimised directly during training. Let L denote the fixed input-window length. At calendar time t, the model receives  
\[x_{t}=(x_{t-L+1},\ x_{t-L+2r}\ldots,x_{t}), \tag{3}\]  
and produces \(\hat{x}_{t}+1=f\theta(x_{t})\), where \(f\theta\) is the trained network with parameters \(\theta\). The window is then advanced by discarding \(x_{t-L+1}\) and appending \(\hat{x}_{t+1}\). The process iterates until the desired horizon is reached. This sliding window recursion enables multi-step forecasts without modifying the network weights. Forecast accuracy on the back-transformed scale was quantified with  
\[MSE=\frac{1}{n}{\sum_{i=1}^{n}}(y_{i}-\hat{y}_{i})^{2}, \tag{4}\]  
\[MAPE=\frac{100}{n}{\sum_{i=1}^{n}}\bigg{|}\frac{y_{i}-\hat{y}_{i}}{y_{i}}\bigg{|}, \tag{5}\]  
where \(y_{i}\) and \(\hat{y}_{i}\) denote the observed and predicted cases for month \(i\), and \(n\) is the number of test observations. Both metrics were calculated separately for each clinical category's monthly and cumulative series. The proposed pipeline constitutes a fully reproducible framework for short- and medium-term forecasting of hepatitis B incidence in Ukraine.