# Reconstruction of Ultra-High Vacuum Mass Spectra Using Genetic Algorithms
## 2 Materials and Methods
### Reconstruction of Mass Spectra Using GAs and Gas Selection  
When observing the results obtained by GAs in the reconstruction of the MS by estimating the partial pressures of 80 gases (considering all species present in our data set), we find 2 main problems to be addressed. On the one hand, optimizing 80 genes in each chromosome in the population makes the search for an optimal result very costly and time consuming. On the other hand, when all 80 gases are considered as candidates, a small value of partial pressure is found for each of them, contributing an error when calculating the weighted sum of Equation (1). Knowing that only a small number of gases are present in a typical UHV environment (usually less than 10), this could be avoided by finding an optimal initial subset of gases to be considered by the GA. Both results indicate that a pre-selection of gases is needed in order to obtain the best performance from the GAs. As discussed in the Introduction, the considered ML model, based on classifying the presence of each gas from a probability score, is able to determine which gases are present with an accuracy >89% [2] using a probability threshold of 0.5. Thus, using this model to search for the gases to be considered in the partial pressures reconstruction seems to be a good starting point. After applying the model, the number of genes on each chromosome is significantly reduced as we restrict the search space from the initial 80 gases from the \begin{table}
\begin{tabular}{c c c} \hline \hline
**Parameter** & **Description** & **Value** \\ \hline \(N\) & Population size & 100 \\ \(b\) & Number of mating parents & 25 \\ \(m_{p}\) & Probability of mutation & 0.03 \\ \(N_{gen}\) & Number of generations & 10 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Hyperparameters of the GA.  
NIST 2017 database, which includes some of the most common contaminants in UHV environments [2; 6], to only those detected by the ML model. Even when a threshold of 0.5 provides the best accuracy for the ML classification performed on the 80 gases, if we lower this threshold (making it less restrictive), more false positives are accepted in the pre-selected pool of candidate species. However, our hypothesis is that this will not affect the GAs negatively. Actually, it may help increase the search space by increasing the variety of parents to be crossed by the GAs, and hence increase the probability of finding a better solution, at the expense of extra computational cost. Another aspect to be analyzed is the performance of GAs depending on the number of present gases in the vacuum system. Obviously, this has an impact on the complexity of the problem to solve and, consequently, on the convergence speeds and on the ultimate reachable reconstruction error. It is interesting to compare the results obtained in the reconstruction of the spectrum containing a variable number of gases. In our study, we analyzed the reconstruction of the MS with 2, 5 and 10 different gases, as UHV systems typically contain less than 10 contaminant species and therefore the classifier used for pre-selection was trained to simultaneously identify up to 10 distinct species [2]. We randomly generated 100 gas combinations with their respective partial pressures and corresponding MS for each one of the scenarios of study, i.e., 100 different cases for each number of gases (2, 5 and 10) and each threshold (0.5, 0.4 and 0.3) making up a total of 9 different combinations. For each one of these cases, we calculated the distribution of the integral error (IE) and its associated median. We follow the IE definition as in [8] to measure the total reconstruction error with respect to the target MS. The expression that defines the IE is the following:  
\[IE^{norm}=\sqrt{\sum_{m}(I_{calc}^{norm}-I_{gen}^{norm})^{2}} \tag{4}\]  
where \(I_{calc}^{norm}\) is the calculated MS and \(I_{gen}^{norm}\) is the generated MS, and both of them are transformed into the normalized logarithmic scale.