## 2 Materials and Methods
### Simulated Annealing Wavelength Selection  
Instead of sensing the full-resolution visible absorbance spectrum at 450-800 nm, the proposed method uses just a small number of narrow wavelength bands (referred to simply as \"wavelengths\" in this paper) that are specifically chosen from the vicinity of the hemoglobin peaks (520-600 nm) to yield accurate SO\({}_{2}\) estimates using the EMLB. Wavelength selection is accomplished via simulated annealing, a heuristic optimization method modeled after the metallurgical annealing process in which the metal undergoes controlled cooling to remove defects and toughen it. The simulated annealing algorithm consists of a discrete-time inhomogeneous Markov chain with current state \(s(i)\) and a cooling schedule defined by a starting temperature, \(T_{max}\), a final temperature, \(T_{min}<T_{max}\), and a total number of steps, \(n\)[44]. The goal of the algorithm is to determine the minimum of a user-defined energy function, \(E(i)\). At each iteration \(i\in 1,\cdots,n\), a new trial state is determined by randomly selecting a \"neighbor\" of the previous state and calculating its energy. If the resulting energy is lower than the energy from the previous iteration, the trial state becomes the new state of the system. If the resulting energy exceeds the energy of the previous iteration, the algorithm adopts the trial state, with the probability given by:  
\[P(E(i),\ E(i-1))=e^{-\frac{[E(i)-E(i-1)]}{T(i)}} \tag{7}\]  
where \(T(i)\) is the temperature at iteration \(i\). Note that this equation allows the algorithm to occasionally accept states that result in an increase in energy. This can benefit the optimization by preventing it from becoming stuck in local minima. The probability of accepting such states is high at the beginning of the process when the temperature is high, but gradually decreases with decreasing temperature. The output of the algorithm is the state with the lowest energy encountered throughout the annealing schedule. Figure 3 provides a summary of this algorithm. Figure 3: Flowchart for the simulated annealing algorithm used to select the best \(k\) wavelengths for SO\({}_{2}\) estimation. For this wavelength selection problem, the state is defined as an array of binary elements indicating the presence or absence of each wavelength in the full-resolution spectrum. A limit, \(k\), is set on the number of wavelengths selected, such that:  
\[\sum_{j=m+1}^{N-m-1}I(j)=k \tag{8}\]  
Under this restriction, the state for each iteration is updated by generating a \"neighbor\" of the current system state. This is done by randomly deselecting one wavelength index from the current state and selecting a new one. The energy of the trial state is then calculated as the average absolute prediction error over the Monte Carlo dataset. The MATLAB function _simannealbrd_ served as the basis for the implementation of the proposed simulated annealing algorithm. The initial temperature was set to \(T_{max}=5000\) and the maximum number of iterations was set to \(n=1000\). The number of steps was chosen to balance the desire for rapid processing with the need for algorithm convergence. The temperature function was modified to allow for a slower cooling rate than the default, and is given by:  
\[T=T_{0_{iter}}.0.985^{(iter-offset)} \tag{9}\]  
where _iter_ is the current number of iterations. With these settings, the probability of acceptance for a 1% increase in the RMSE remained above 66% for the first half of the total iterations, allowing for a less restricted random walk through the solution space. In the latter half of the iterations, the acceptance probability was allowed to drop well below 1%, enabling a more targeted search near the optimal point. After 750 iterations, \(T_{0}\) was increased to 5 and an _offset_ was applied to the number of iterations in the exponent of Equation (3) to reset the cooling rate from that point. The acceptance function was modified to implement the exponential function in Equation (1).