## 4 Discussion  
In this study, conditional generative adversarial networks were proposed to learn the joint multidimensional probability density distribution of the properties of photons (location in space, energy, and momentum) included in the phase spaces of medical linear accelerator simulators. Because the networks are conditioned with respect to the parameters of the primary electron beam (unique to individual medical linear accelerators), the trained models are generic and can be used to generate phase spaces for arbitrary parameters of the primary electron beam within the limits over which the training data were collected. Histograms shown in Figure 2 demonstrate that differences between the PRIMO-generated and GAN-generated phase spaces are much smaller than the densities themselves, with a few exceptions related to areas with large gradients of probability density. Notably, the high variability of density between phase spaces exhibited by the Z component of momentum is well reflected by the RoCGAN model. Doses delivered to a water phantom calculated based on the RoCGAN-generated phase spaces closely match the doses from PRIMO-generated phase spaces. As seen in Figure 4, differences in delivered dose, even in the worst case, are not much larger than their statistical uncertainty in the case of lateral profiles and within statistical uncertainty for depth profiles. As indicated by the \(p\)-values of the Wilcoxon signed-rank test in Table 3, the CGAN and RoCGAN models have similar levels of error for depth profiles. For the lateral dose profiles, the RoCGAN model delivers a significantly lower level of error with respect to MC-based profiles. Importantly, any loss of accuracy due to the application of machine learning models does not significantly affect the predicted dose distributions in test plans P1, P2, HN1, and HN2, as demonstrated by the high gamma passing rates and low dose differences in Table 2. For the P1 plan, the CGAN and RoCGAN models work equally well, as judged from the \(p\)-values in Table 2, but for the remaining three plans, the RoCGAN model delivers a significantly lower level of error. The results of simulating dose delivery to water phantoms, to test phantoms, and to patients indicate that the MC-based and GAN-based phase spaces can, in most cases, be used interchangeably. Because the generation of particles with GANs is 1000-times faster than that with MC, GANs can be used on the fly to increase the amount of particles in the phase space, thus improving the precision of dose calculation in phantoms or in patients. \begin{table}
\begin{tabular}{l c c c c c c c c} \hline \hline  & \multicolumn{2}{c}{**30 cm \(\times\) 30 cm**} & \multicolumn{2}{c}{**10 cm \(\times\) 10 cm**} & \multicolumn{2}{c}{**3 cm \(\times\) 3 cm**} & \multicolumn{2}{c}{**Depth**} \\ \hline  & **CGAN** & **RoCGAN** & **CGAN** & **RoCGAN** & **CGAN** & **RoCGAN** & **CGAN** & **RoCGAN** \\ \hline \(P_{0}\) & 3.134 & 1.282 & 1.568 & 0.685 & 0.691 & 0.568 & 0.008 & 0.008 \\ \(P_{1}\) & 2.846 & 1.247 & 1.900 & 0.667 & 1.596 & 0.492 & 0.009 & 0.007 \\ \(P_{2}\) & 2.459 & 1.471 & 1.108 & 0.748 & 0.525 & 0.418 & 0.008 & 0.008 \\ \(P_{3}\) & 5.323 & 1.506 & 3.181 & 1.055 & 1.768 & 0.335 & 0.009 & 0.008 \\ \(P_{4}\) & 4.359 & 1.093 & 1.534 & 0.887 & 0.520 & 0.508 & 0.008 & 0.010 \\ \(P_{5}\) & 2.498 & 1.185 & 1.629 & 0.920 & 1.234 & 0.541 & 0.008 & 0.007 \\ \(P_{6}\) & 2.899 & 1.915 & 1.035 & 1.106 & 0.486 & 0.476 & 0.008 & 0.007 \\ \(P_{7}\) & 3.885 & 1.802 & 2.290 & 1.009 & 1.264 & 0.533 & 0.007 & 0.008 \\ \(P_{8}\) & 1.477 & 1.043 & 1.109 & 0.671 & 0.459 & 0.291 & 0.007 & 0.008 \\ \(P_{9}\) & 2.241 & 1.068 & 1.358 & 0.667 & 0.589 & 0.430 & 0.007 & 0.008 \\ \hline mean & 3.112 & 1.361 & 1.671 & 0.841 & 0.913 & 0.459 & 0.008 & 0.008 \\ std & 1.067 & 0.290 & 0.623 & 0.166 & 0.477 & 0.086 & 0.001 & 0.001 \\ \hline \hline \(p\)-value & \multicolumn{2}{c}{0.0020} & \multicolumn{2}{c}{0.0039} & \multicolumn{2}{c}{0.0020} & \multicolumn{2}{c}{0.9219} \\ \hline \hline \end{tabular}
\end{table}