Demo 4: Finding the best-fit parameters for Planck 2013
Note that both the data and sampler used in this example are a little out of date. If you are new to CosmoSIS you should still read it to get an idea of how things work, but you can see how to fit Planck 2015 data with the more robust Minuit sampler in Demo 16
In this example we will find the maximum likelihood cosmological parameters for Planck 2013. For simplicity we keep the Planck nuisance parameters and the optical depth tau fixed, so we have five varying parameters. Run like this:
This will take a little while, since we have to do several hundred different cosmologies. Once done it will create two files, output/demo4.txt and output/demo4_output.ini.
The first txt file output/demo4.txt is in the same form as the grid output from before - as column text. But this time there is only one entry, the best-fit sample:
#cosmological_parameters--omega_m cosmological_parameters--h0 cosmological_parameters--omega_b cosmological_parameters--a_s cosmological_parameters--n_s LIKE ... 0.323118340227 0.663067835995 0.0481099681605 2.15244682388e-09 0.958526048347 -4033.15502856
(your numbers may be different from this - for speed we set the accuracy settings in the demo quite weakly - if you want a more accurate answer then see the note below).
The second output file output/demo4_output.ini is more interesting:
[cosmological_parameters] ommh2 = 0.12 0.14161103899324978 0.19 ombh2 = 0.005 0.02225223756479768 0.03 h0 = 0.6 0.6800918515177078 0.8 n_s = 0.92 0.9651390758410499 1.0 a_s = 2e-09 2.2027452026774598e-09 2.3e-09 ...
This is a new version of our ini file with the starting positions of all the varied parameters set to their best-fit values. This can be used as a starting point for MCMC samplers to avoid the burn-in period at the start of their run.
This example introduces a third "sampler", which uses the Nelder-Mead simplex algorithm to find the maximum likelihood. (Notice that this algorithm does not draw samples from a probability distribution - but we refer to it as a sampler for code naming consistency.) There are a few parameters we set for this sampler:
[runtime] sampler = maxlike [maxlike] maxiter = 100 tolerance = 0.1 output_ini = output/demo4_output.ini [output] filename = output/demo4.txt format = text verbosity= debug
The tolerance and maxiter parameters are paraemters of the algorithm; reducing tolerance will improve the fit at the cost of time. 0.1 is really too low for this kind of parameter space - 0.01 will give you much better answers at the cost of more time (though still not too long).
We got the second ini output file because we set output_ini. Setting the verbosity to debug meant we got lots of output during the optimization.
The parameters that we just gave a single value for in the values4.ini file were left fixed during the optimization, and the ones for which we gave a range were varied:
[cosmological_parameters] omega_m = 0.2 0.3 0.4 h0 = 0.6 0.7 0.8 omega_b = 0.02 0.04 0.06 A_s = 2.0e-9 2.1e-9 2.3e-9 n_s = 0.92 0.96 1.0 ; We will leave these parameters constant ; for speed tau = 0.08 omega_k = 0.0 w = -1.0 ...