Installation
Using CAMEL
Tutorials

Likelihoodbased statisticsOn this page... (hide) 1. Model+parametersWe will learn how to write a parameter file ("parFile") which is the main input to CAMEL. The very first questions one must ask are
Here we will use the popular (flat) LambdaCDM one. How many free parameters does it contain? In the following for the data we will use a (fake) matter power spectrum measurement (embedded in a likelihood) and work with 3 parameters only (for CPU reasons) ie. we assume the other parameters are known and fixed. In linear theory, the matter powerspectrum shape is most sensitive to the Hubble constant, and matter densities where one should distinguish between the standard "baryonic" one and the "cold dark matter" contribution.
In the following we will call your choice of parameters "par1,par2,par3" and the first values as "guess1,guess2,guess3" Instructions
Edit there with your preferred editor a new file called for instance and complete it with your choices: fix par1 cosmo guess1 fix par2 cosmo guess2 fix par3 cosmo guess3 class sBBN\ file bbn/sBBN.dat
The starting keyword "class" can be used to transmit parameters to CLASS (similar to explanatory.ini but without the = sign).
Validation:the
$EXECDIR/writeSpectraPk lcdm.par 2000 output.fits 0.5 The third argument is lmax (here 2000) for Cl(CMB), the next is the name for the fits output file, and the last one (here 0.5) is the redshif (z) at which the matter spectrum is computed. You may now have a look at the Pk spectrum which is in the 3d header of the output.fits file.
Here is how to read a FITS file in python ( from astropy.io import fits h= fits.open("output.fits") pkdata=h[3].data k=pkdata['k'] pk=pkdata['pklin'] loglog(k,pk) 2. LikelihoodA likelihood is a real function of a set of parameters "pars" (a vector, here (par1,par2,par3)) that returns a high value when the model matches the data and low values otherwise. If correctly written (a big job in real life) it contains all the information concerning observables. We will equally use the term "chi2" which by definition is chi2(pars)=2 ln[L(pars)] so that a "high likelihood" means a "low chi2". An essential piece of information is the value of pars for which L(pars) is maximal or chi2(pars) minimal. This is the Maximum Likelihood Estimator (MLE) and is most often the best one can do to infer which set of pars describes best the data. We work with a some very basic likelihood, which assumes we did measure a set of "Pk" measuremnts at redshifts of z=0.5,1,1.5 over some k range and we know exactly the associated Gaussian errors (this is a very oversimplified example but it will really happen soon with the EUCLID/LSST missions, with a much higher precision than what we are playing with today). We also add another likelihood related to the BAO peak position. The "Pk" likelihoods value (or chi2, a single number) of a set of cosmological parameters pars=(par1,par2,par3) is in fact computed in two steps:
InstructionsTo use these likelihoods add the following lines to lcdm.par: fakePk1=fakepk/pk_0.5.lik fakePk2=fakepk/pk_1.lik fakePk3=fakepk/pk_1.5.lik fakeBAO=fake/BAO_scale.lik
Then we add to lcdm.par some CLASS directives to compute the spectrum only at the right redshifts (the default being z=0). For optimization with this likelihood we also don't need CLASS to compute spectra above some k_max value right? Then complete X,Y,Z (which is a commaseparated list) and W in the following CLASSspecific parameters: class z_pk X,Y,Z class P_k_max_1/Mpc W To check that the parFile is correctly configured we then run the $EXECDIR/writeChi2 lcdm.par The (galactic) bias is a nuisance parameter, that comes from the fact that one does not measure directly the full matter power spectrum but the power spectrum inferred from some population of galaxies. It is not well known (and actually varies with the galaxy selection and redshift, here for simplicity we assume it is the same in all the likelihoods) There are generally much more nuisance parameters qualifying for instance possible systematics in the measurement: they impact directly the likelihood (not the cosmological model) and can have some external constraints depending on independent measurements/apriori knowledge. So finally what is called "parameters" is a set of (cosmos,nuisances) ones. The likelihood actually depends on them through :
'''Complete the parFile adding the nuisance parameter (in this case instead of "cosmo", use the keyword "nui"). For the moment we will fix its value to 1.07, so add fix bias nui 1.07 Rerun 3. The Maximum Likelihood Estimator, a.k.a. "bestfit"Given some measurement(s), we are looking for the set of parameters (within a model) that is the most likely to produce those data (note the "likely" semantic, it is not the same than "probable"). Technically this is performed by looking for the parameters that minimize the chi2(pars) function (or maximizes the likelihood). "pars" is a vector that includes both cosmological and all the nuisance parameters. Here it has low dimensionality but it is frequent to go up to 10, 30 or 100 parameters. So we are dealing with the minimization of a multidimensional function. There are several algorithms to do that but there is no magical one (unless your likelihood is linear which is rarely the case). Furthermore we don't have access here to the analytical gradients of the function which complicates the work. We use in CAMEL the MINUIT package which has been widely used in High Energy Physics. However remember: no magic, you always have to experiment with such tools to ensure your really captured the minimum chi2 solution. This means trying different starting points and check that the solution is not blocked at some boundary for example. So far our parameters were fixed. Let us release one.
Modify one of your parameter adding a (rough) estimate of its error and some bounds within which it should be varied
with guesses for the "error" and "bounds" (use spaces or tabs to separate the fields) Also to see what is happening during the minimization add to your parFile verbose=true and run with $EXECDIR/Minimize lcdm.par bf.txt hess.txt (the two output arguments are the bestfit/hessian outputs written) What is shown is then the values that are being tried by MINUIT: the last 2 columns are of interest also: they gives respectively the chi2 value for this set of parameters and the CLASS time computation of the model (in s). Don't be worried at the end by this kind of message: WARNING: FunctionMinimum is invalid. which is hard to avoid because of the numerical noise . The minimum can be actually valid (but maybe not the estimate of its error, see the Hessian part). Modify slightly the input value and rerun. Do you obtain the same minimum? Which one is better? 4. PrecisionRecall that CLASS is solving numerically some complicated equations. One can control the level of accuracy of many steps in the code. What is nice in CLASS is that all the precision parameters (cutoffs,steps etc.) can be specified in a single place. CLASS has some reasonable values but you may need to adapt them if your need some really high precision. Of course this will take more time so it is always a compromise between speed and precision. When we try to minimize a multidimensional function the algorithms assume that the function is smooth wrt the parameters. It is not the case here since within CLASS the "error" and "bounds" in finite precision of the computations brings up numerical noise because chi2(pars)=chi2(Pk(pars)) where the Pk operation is performed by CLASS. This complexify the minimizer's task of precisely finding the minimum. CAMEL provides some higherprecision parameters to CLASS, still within reasonable computation time. InstructionsAdd the following line to your parFile precisionFile=class_pre/hpjul2.pre (you may look at what is in this file, recall relative paths are wrt to the /lik directory) Rerun with the one parameterfree and see if there is some difference. Now release all the parameters but the bias one (ie. modify the "fix" lines by "par" ones) and look for the global bestfit. You may try to figure out the MINUIT strategy by looking at the output. Try changing a bit the starting values and see if you get the same result: which one is better? When you have a reasonable first guess try releasing also the "bias" parameter (but do not spend too much time if it hardly converges). 5. ProfilelikelihoodsThe MLE (which is classical statistics) gives you a solution in a multidimensional space which is not very convenient to visualize. We would like to make statements about each variable separately What can we say about individual parameters? But then you have to choose your religion and decide what a probability means! It's time to ask yourself '''are you a Bayesian or a frequentist?
Certainly the most sane way for a scientist is to be agnostic and compare both approaches (which, when the problem is well constrained give in practice similar results). Profilelikleihoods are the frequentist solution (MCMC will give a Bayesian answer) to estimating intervals for variables. Rather than writing a lot of theory, let see in practice how it works. We choose one variable, here H0 and we will profile it:
Think about it: where is the minimum located wrt to the globalbest fit (ie. the MLE, when all the parameters free)? Sometimes starting from a slightly different point leads to a slighty better chi2 and you should use this one. Here it may be a bit cumbersome because you are doing it by hand. In real life, there are some tools to send several minmizations (with differemt starting point values) to a cluster and take the best chi2, but it is outside the scope of this school. You may look at a more reallife case here (see Fig.4). Finally write your statement about H0 , using the "+" notation. If you have some time left you may
6. The Hessian matrixYou notice as you run that MINUIT finally gives you some "Values" and "Errors" for the released parameters. InstructionsRelease again all parameters (ie. we come back to the MLE case), start with the best values you obatined with the profile likelihood, and add the following line to lcdm.par: doHesse=true (which will compute a slightly more precise Hessian matrix) Then run again a minimization. $EXECDIR/Minimize lcdm.par bf hess.txt Are the printed errors realistic? For H0 do you have something similar to what you obtained with the profile likelihood? While the Values of the Chi2 are quite precise the "Errors" quoted by MINUIT are much more uncertain. They (should) represent the curvature of the function at the minimum (the so called "Hessian"). However
However we will see in the 2d session, that the Hessian, although uncertain can still be interesting. Let's read the Hessian matrix
Because of the different range of all the variables, this matrix is by eye not very intresting: transform it into a correlation matrix and look at it. 