## 2 Materials and Methods
### Methodology
If there are five consecutive records, respectively, at 21:00, 21:15, 21:30, 21:45, and 22:00, the pairs (21:00 -> 21:15), (21:15 -> 21:30), and (21:30 -> 21:45) are used to generate the hourly transition matrix for the 21 st hour. Similarly, the generation of the hour-change transition matrix between the 21 st and the 22 nd hours is based on the pair (21:45 -> 22:00). **Step 3. Model testing**  
The next step is to test the generated matrices to see whether they can be used to generate synthetic data with an acceptable accuracy. This step includes two phases:  
**Phase 3.1. Test data generation**--a random generator is used to create synthetic data for a certain month of the year. This procedure includes the following:  
* The initial hour and state for the data (for example, 0 h) are chosen--the chosen state must have non-zero probability in the corresponding hourly transition matrix;
* The next state of the synthetic data is generated randomly, according to the probability distribution for the current state in the transmission matrix, which could be achieved as shown in Algorithm 1. Figure 4: Generation of the transition matrices for each hour of the day and for each hour-change. ```
Let \(\text{X}_{t}\) be the last state \(\text{NumberOfTransitions}=\text{Count}(\text{M}_{\text{h},\text{h}},\text{X}_{t})//\text{Get}\) the total number of possible transitions (according to the original dataset) from the current state \(\text{X}_{t}\) \(\text{RandomNumber}=\text{rand}(1\dots\text{NumberOfTransitions})//\text{get}\) a random number between 1 and NumberOfTransitions \(\text{NextState}=0//\text{initialize}\) \(\text{while}\text{RandomNumber}>0\) {  if \(\text{RandomNumber}<=\text{M}_{\text{h},\text{h}}(\text{X}_{t},\text{NextState})// \text{M}_{\text{h},\text{h}}(\text{X}_{t},\text{NextState})\) are the number of possible transitions from \(\text{X}_{t}\) to NextState \(\text{X}_{t+1}=\text{NextState}\);//the next state has been randomly generated  break;  RandomNumber = \(\text{RandomNumber}-\text{M}_{\text{h},\text{h}}(\text{X}_{t},\text{NextState})\);  NextState = NextState + 1 }
```  
**Algorithm 1**Generating the next state according to the transition matrix probabilities. Once the new state \(S_{t+1}\) is generated, the value of the next sample is estimated according to  
\[P_{t+1}=StateWidth\times(S_{t+1}-1)+random(0\dots StateWidth), \tag{2}\]  
where \(random(0\dots StateWidth)\) returns a random value between 0 and \(StateWidth\). When the current and the next generated records belong to the same hour of the day, the corresponding hourly transition matrix is used; if they belong to different hours, the corresponding hour-change transition matrix is used. When testing data are generated, the record count should be large enough, and often it might be larger than the training dataset. This is required to make sure the long-term trend of the Markov chain has reached its final probability distribution vector. There is one situation that requires special handling: the final state of the previous hour \(\text{X}_{t}\) may exist in the hour-change transition matrix \(\text{M}_{\text{h},\text{h}+1}\) with zero probability. This can happen because of the limited volume of the training dataset, though it is also possible in very large training datasets. This situation is handled according to Algorithm 2. Initially, the algorithm tries to generate a new final state \(\text{X}_{t}\) from the previous state \(\text{X}_{t-1}\), which has a non-zero probability in the hour-change transition matrix \(\text{M}_{\text{h},\text{h}+1}\). If it does not succeed \(N\) number of times, then the new state \(\text{X}_{t+1}\) is chosen randomly from the hour-change transition matrix based on its probability distribution. **Phase 3.2. Accuracy assessment**This phase aims to compare the synthetic and training data in terms of distribution and probabilities to assess how closely the synthetic data represent the original one.