Installation
Using CAMEL
Tutorials

MCMCIntroductionMonte Carlo Markov Chains are popular in cosmology. Although it may look as an evolved technique it is in fact mathematically a very simple one (the MetropolisHastings algorithm, father of all, takes about 10 lines to code, you should try). But anyone who practiced them in real life conditions (ie data) knows that a lot of cooking (on CPU, proposal matrix, convergence, priors) is generally forgotten/hidden. So let see in practice how it works.
The MCMC is therefore only a method to shoot samples from some (complicated) multidimensional function. It is not especially "Bayesian" (it can be used to compute integrals) and is quite inefficient. However with some practice you can manage to sample about everything. Here is how MetroplisHastings (MH) works in practice to sample a function F:
Run this for "some" time, then read the file and do histograms. Isn't that simple? But what does this has to do with cosmological parameter estimation? For parameters inference the sampled function F is the data likelihood. According to Bayes theorem
(there is a denominator, but it's however unimportant for parameter estimation)
So that if you sample your likelihood+prior you get the posterior distribution (ie. a pdf) of the parameters you are trying to estimate Unfortunately most people forget about the priors and more or less implicitly put them to 1 arguing this is the most uninformative one (that's wrong see Jeffreys priors). So that finally in most cases, one uses elaborate statistical terms to justify laziness to pretend that the posterior distribution is equal to the likelihood (which is again wrong, think if something "likely" is the same than something "probable"). A serious Bayesian approach is to figure out how your result varies depending on your priors choice. An even simpler one is to compare the output of this method to the frequentist profilelikelihood one which does not have any buildin notion of prior. This is the main motivation for CAMEL If you are new to MCMC techniques you should definitely code once in your life the MettroplisHastings algorithm (on a very simple case) to understand how all this works (local python work) Main.Metropolis Although the method is sometimes presented as magic, it is not and involves actually a lot of cooking and care (in particular with multiple parameters and complicated likelihoods) Indeed
These 2 points are very intricate: if you have a "good" proposal you can run the chain for a shorter time. In fact theory says the best proposal is to input the "real" covariance of your parameters: you can determine it from the samples themselves but only if your samples have a good proposal! In MH, people try to make some "guess" for this covariance matrix, make some (very long) run, estimate empirically the covariances using these samples, input this matrix as a new proposal, and redo some run(s). In cosmology, this can take more than one week. In CAMEL we did implement some adaptive strategy to reconstruct a covariance matrix on the fly. It is not completely trivial and one should care not destroying the Markovian nature of the chain: samples do not depend only on the previous one but here also on the previous proposal (in practice the "adaptation" of the proposal is gradually decreased until it gets "frozen". We will learn how to use that in this standard level module but on fake data (docker or mardec) If you already know about CAMEL you might be more interested by revisiting the sigma8 measurement on real data : (mardec) : Main.sigma8 