{'fraction_non_alphanumeric': 0.02566144588974427, 'fraction_numerical': 0.015308379789399168, 'mean_word_length': 5.008506113769272, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Accelerating MCMC algorithms through Bayesian Deep Networks

Markov Chain Monte Carlo (MCMC) algorithms are commonly used for their versatility in sampling from complicated probability distributions. However, as the dimension of the distribution gets larger, the computational costs for a satisfactory exploration of the sampling space become challenging. Adaptive MCMC methods employing a choice of proposal distribution can address this issue speeding up the convergence. In this paper we show an alternative way of performing adaptive MCMC, by using the outcome of Bayesian Neural Networks as the initial proposal for the Markov Chain. This combined approach increases the acceptance rate in the Metropolis-Hasting algorithm and accelerate the convergence of the MCMC while reaching the same final accuracy. Finally, we demonstrate the main advantages of this approach by constraining the cosmological parameters directly from Cosmic Microwave Background maps.


Introduction
Cosmological observations have significantly increased in the last decade allowing us to obtain a better description of the Universe. This task has been also achieved thanks to Bayesian inference methods allowing to derive constraints on the parameters of cosmological models from those observations Verde [2007]. Bayesian inference offers a way to learn the prediction task from data through the posterior distribution p(θ|d) ∼ p(d|θ)p(θ); being θ a set of unknown parameters of interest, d the data associated with a measurement, p(θ) the prior distribution that quantifies what we know about θ before observing any data, and p(d|θ) is the likelihood function. Computing the true posterior is generally intractable, and approximation methods must be implemented in order to perform Bayesian inference in practice. Two main techniques for this purpose are Variational Inference and Markov Chain Monte Carlo (MCMC) Graves [2011], Metropolis et al. [1953], Regier et al. [2018], Jain et al. [2018]. The former method although computationally faster, requires the approximation of the true posterior, while the latter has become one of the most popular methods for cosmological parameter estimation due to its advantage of being non-parametric and asymptotically exact. Classical MCMC methods draw samples sequentially according to a probabilistic algorithm that allows to scale linearly with the dimension of the parameter space Verde [2007]. However if the complexity of the model increases from the presence of "slow" parameters, nuisance parameters, foregrounds or parameter correlations, the sampling will exhibit a high numerical cost Lewis [2013]. Additionally, it is generally difficult to determine a convenient initial state for the system and an accurate criterion to determine the convergence of the Markov Chain. These practical issues compel MCMC practitioners to resort convergence diagnostic tools which demand to run MCMC for a very long time to obtain good solutions Dunkley et al. [2005]. In this work we show a preliminary approach to accelerate the convergence of MCMC by including in the bottom of it, the approximate distribution outcome of the deep neural network as a proposal for the Markov Chain. We show the advantages of this approach in constraining the cosmological parameters directly from Cosmic Microwave Background (CMB) maps.

Dataset and Network
Following Hortua et al. [2019], we use 50.000 images related to the CMB maps projected in 20 × 20 deg 2 patches in the sky for training the Bayesian Neural Network. These images have a dimensions (256,256,3), where the last channel stands for the Temperature (channel=0) and Polarization (channel=1,2), and each image corresponds to a specific set value of the cosmological parameters: dark matter density ω cdm , spectrum amplitude A s , baryon density ω b , and the dark energy density parameter Ω Λ . The BNN was implemented in TensorFlow-Probability, and the same version of the VGG architecture along with the presence of Flipout as it was shown in Hortua et al.
[2019] was used in this paper. Finally, we used the calibration method introduced in Hortua et al. [2020] where α-divergence with α = 1 has been included at the top of the BNN. Results of the conditional distributions for the predicted parameters by our BNN vs standard MCMC methods are displayed in Fig. 1.

Method
MCMC algorithms are commonly used for sampling from complicated distributions. As the dimension of the distribution gets larger, the computational costs for a satisfactory exploration of the sampling space become challenging. Adaptive MCMC methods such as the choice of proposal distributions in the Metropolis-Hastings algorithms are designed to address this issue speeding up the convergence. However, a suitable class of distribution is almost never known in advance and the search for improved proposal distributions is often done manually, through trial and error, which can be difficult especially in high dimensions. The method shown in this paper can be seen as a novel way to perform adaptive MCMC in which the output distribution of the BNNs serves as a proposal distribution for the MCMC. As it was shown in the previous work of Hortua et al. [2019], multi-channel BNNs, are able to break degeneracies among parameters and provide reliable results close to the desired conditional posterior. This distribution can be used as potential proposals to significantly improve the performance during parameter inference. MCMC experiments were run in the cobaya software Torrado and Lewis [2020], with the likelihood given by Verde [2007] whereĈ l is the power spectrum of the CMB patches obtained with Lens-Tools Petri [2016], and C l the theoretical model. Cobaya accepts the cosmological parameters as input, compute C l via CLASS ? and when the Markov chains have enough points to provide reasonable samples from the posterior distributions, the simulation stops and it return the chains. We run two MCMC experiments taking into account the power spectrum of the CMB maps. In the first MCMC experiments we used the full sky map, while in the second one, we computed the power spectra for CMB patches and used them as an input in cobaya package.

Results
Results of the conditional distributions for the predicted parameters are displayed in Fig. 1 where we compared the MCMC results with the calibrated BNNs (on the CMB patches described in Section 2).  We observe that MCMC provides tighter and more accurate constraints. However, the trained Neural Network can generate 8000 samples in approximately ten seconds which it turns out to be 10000 times faster than MCMC for this dataset 1 . Runtime and metrics for convergence in MCMC are shown in Table 1. As expected, the polarization combined with temperature data shifts the values obtained from temperature alone and enhances the accuracy in all parameters (columns 1 and 3). Furthermore, a well-converged chain is also observed via the Gelman-Rubin R − 1 parameter and its standard deviation at 95% confidence level interval (R − 1) 95%CL (the smaller the better). The qualitative correlations among parameters as obtained from BNNs are mostly analogous to the MCMC ones (Fig. 1), showing that a multi-channel BNN is able to handle the complexities involved in this kind of analysis and additionally to use the polarization information to break cosmological degeneracies. Nonetheless, although 10000 times slower, the MCMC it is able to better quantify the uncertainty. This is especially true when using the power spectrum of the full map, and the intervals are an order of magnitude more accurate than those computed by VI (rightmost column of Table 1). On the other hand, we can also combine MCMC and VI leveraging the advantages of both methods. Such topic has attracted a lot of attention in the recent literature Salimans et al. [2015], Thin et al. [2020]. A straightforward approach to speed up MCMC algorithms consists in using the covariance matrix constructed from the chains of the trained Neural Network as proposal for the distribution of the MCMC. In fact, it is known that a good estimate of the covariance matrix for the parameters increases the acceptance rate leading to significantly faster convergence Lewis [2013]. In Table 1, we compare the runtime for the MCMC with and without a precomputed covariance obtained from BNN. As we can see from the table, proposal covariances from BNNs (covarBNN) speed up convergence in MCMC reducing the computational time for all datasets (Temperature, Polarization and full sky maps). In Fig. 2 we report MCMC convergence diagnostic quantities such as R − 1 and the acceptance rate per iteration. The stopping rule implemented in cobaya ensures that the Gelman-Rubin R − 1 value and its standard deviation at 95% confidence level interval (R − 1) 95%CL computed from different chains (four in our case), satisfy the convergence criterion R − 1 < 0.01 twice in a row, and (R − 1) 95%CL < 0.2 respectively to stop the run, Torrado and Lewis [2020]. For the Temperature signal alone, the Markov chains achieve a steady state in about 2000 steps working with the covarBNN proposal while it usually takes more than 5000 steps instead with the vanilla MCMC. This behavior can also be explained by observing the acceptance rate in Fig. 2 (bottom), the red curve (TTcovarBNN) quickly approaches a considerably high acceptance rate, eventually converging at around 0.23 (which is a standard value for which we expect to have a decent acceptance rate Roberts et al. [1997]). An analogous trend can be seen for the polarization case.

Discussion
In this paper we show that MCMC algorithms excel at quantifying uncertainty with respect to BNNs models, although the latter is about 10000 times faster at inference. Given these properties, we showed an approach in which the covariance matrix efficiently estimated from the BNNs samples, significantly enhance the acceptance rate in MCMC yielding faster convergence. A limitation of this method is the use of partial CMB maps that prevent the access to large scales correlations, leading to large uncertainties and possibly introducing a bias in the prediction of the cosmological parameters sensible to such scales. It would be interesting (and more of a fair comparison) to compare MCMC for a full sky with respect to spherical neural architectures Krachmalnicoff and Tomasi [2019], Perraudin et al. [2019], ? which can extract large scale signals correlations, thus determining if Deep Learning methods can achieve a similar level of precision as compared with MCMC. As a future work, we also expect to assess the performance of this method with respect to other MCMC modifications such as a Hamiltonian Monte Carlo.

Broader Impact
Combining the speed of Bayesian Neural Networks with the accuracy of MCMC algorithms results in potential Bayesian inference methods for upcoming cosmological observation. Additionally, the network built in this work allows to adaptively extract complicated correlations when performing inference without assuming a priori summary statistics such as power spectrum or higher order spectra (such as bispectrum, trispectrum or others). This work presents an example for how machine learning could be used in the physics community to improve classical inference methods.