# Simulation of Calibrated Complex Synthetic Population Data with XGBoost
## 3 Calibration of a Population
### Application of the SA Algorithm  
The SA algorithm including the improvements is fully implemented in the function calibPop() in the R package simPop. Some parameters have been added that reflect various hyperparameters described above (see Appendix B.4). For demonstration purposes, we post-calibrate the synthetic population from the previous section and use the data set eusilcP as the target population. We choose the following two post-calibration scenarios to highlight the improvements to the algorithm:  
* Post-calibrate the synthetic population on a single target margin using the number of individuals by region, gender and citizenship
* Post-calibrate the synthetic population on two target margins using the number of individuals by region, gender and citizenship and number of households by region and household size. In both scenarios, a value of \(\epsilon=0.1\) was set as default. The R code to apply the post-calibration scenarios to the synthetic data can be found in the Appendix C under Appendices C.4 and C.5. We performed this calculation on a server running Ubuntu 18.04 Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60 GHz with 8 cores and 125 GB memory. With the improved version of SA using only the single target margin, the algorithm converges in a few seconds instead of almost 50 min when using the older version implemented in simPop 1.2.1. When running the improved version with \(\epsilon=0.01\), it converges in almost 10 s.  
The results of the first scenario are shown in Figure 5, where the distribution of the variables used for post-calibration is displayed. The colors indicate the distribution before calibration, after calibration using the old implementation SA 1.2.1, the improved implementation SA 2.1.2 and the improved implementation using \(\epsilon=0.01\) SA eps = 0.01. The black lines represent the target distribution. Citizenship pb220a is shown in the horizontal panels and gender bb090 in the vertical panels. The distributions using the improved method seem to be more similar to the target margins, especially for large populations, e.g., the box on the left for people with the nationality \"AT\". Table 2 shows the mean absolute error (MAE), the mean absolute percentage error (MAPE), as well as the average Aitchison distance (see [32; 33]), compared to the target distribution. Using the improved implementation instead of the old, the MAE and MAPE are drastically reduced, especially for \(\epsilon=0.01\). For the average Aitchison distance, we observe similar values for the old and new improvements, but again a drastic improvement for \(\epsilon=0.01\). Figure 6 shows the results of the second scenario using two target distributions--one for the number of individuals and one for the number of households As a comparison the distribution before calibration and the distribution using only one set of target margins are displayed. The upper part of the Figure 6 shows that the margins for the number of people are reproduced slightly worse when multiple margins are used. The distribution on the number of households is, however, represented better when also considered during calibration, as can be seen in the bottom part of Figure 6.  
Table 3 shows the MAE, the MAPE and the average Aitchison distance compared to the target distribution for the second scenario. Using multiple margins yields slighter higher error measures for the person margins but much lower ones for the household margins. The household margins before the calibration yield a low average Aitchison distance because the relative distribution is already quite similar to the relative target distribution. \begin{table}
\begin{tabular}{l l l l l} \hline \hline  & **MAE** & **MAPE** & **Avg. Aitchison** \\ \hline Before calibration & 618.31 & 71.31 & 2.52 \\ SA 1.2.1 & 158.47 & 22.13 & 1.68 \\ SA 2.1.2 & 75.26 & 17.36 & 1.73 \\ SA \(\epsilon=0.01\) & 8.02 & 7.41 & 1.27 \\ \hline \hline \end{tabular}
\end{table}