Page 1 of 2

Adding new parameters to CosmoMC, March-13

Posted: March 28 2013
by alireza hojjati
Hi Antony,

I am trying to add new parameters to CosmoMC. Since the structure has changed in this version and there is no definition of "num_hard" in the settings.f90 anymore, I tried to change it in cmbtypes.f90 as

num_hard = slow_num + 6

And add the new parameters right before the derived parameters (After #21: Aphiphi and #22:omegal). I get errors such as :

params_CMB.f90(188): error #6410: This name has not been declared as an array or a function. [PARAMS]
Params(22) = CMB%mag1
----- ^

Any suggestion?

Thanks,

Alireza

Re: Adding new parameters to CosmoMC, March-13

Posted: March 28 2013
by Antony Lewis
To add new theory parameters

* add the definition of the physical parameter to CMBParams in cmbtypes.f90

* Change params_CMB.f90 to add a new parameterization or modify an existing one (with a corresponding .paramnames file with the new parameter names in). In particular the _Init routine does

Code: Select all

call SetTheoryParameterNumbers(num_slow_params,num_semi_slow_params)
which sets the number of hard and semi-hard parameters (the latter being things like initial power spectrum parameters) and then

Code: Select all

  call this%Init(Ini,Names, 'params_CMB.paramnames')
to set the parameter names file.

* Modify CMB_Cls_Simple.f90 to pass your new CMBParams parameters to CAMB to actually change the result

* Edit your .ini files to to add range and width settings for the new parameter names


If instead your parameter is a likelihood parameter (nuisance parameter), the new parameter can be handled entirely inside your likelihood function code (see supernovae_SNLS.f90 for a simple example that has two nuisance parameters): you just set the .paramnames file (which determimes the number of new parameters), and then use them when passed in to your likelihood function.

Adding new parameters to CosmoMC, March-13

Posted: March 30 2013
by alireza hojjati
Thanks, it worked !

Adding new parameters to CosmoMC, March-13

Posted: July 30 2013
by Tijmen de Haan
My likelihood code includes likelihood/nuisance parameters, which I've successfully added as suggested.

My code is faster than the Planck likelihood, but slower than CAMB. Is it possible to assign these nuisance parameters their own fast/slow subspace?

Re: Adding new parameters to CosmoMC, March-13

Posted: July 30 2013
by Antony Lewis
Each likelihood object has a speed parameter, just set the appropriate number for the relative speed (CamSpec is set to have speed 5, higher number is faster).

Adding new parameters to CosmoMC, March-13

Posted: August 01 2013
by Tijmen de Haan
Thanks. I noticed some code in paramdef.F90, and the clik_speed_* parameters in the clik-related ini files. How do I set the analogous speed parameter for my likelihood (which I added simply as an .ini file in batch1, a .paramnames file in data, a .f90 file in source, and an entry in DataLikelihoods.f90)?

Re: Adding new parameters to CosmoMC, March-13

Posted: August 01 2013
by Antony Lewis
In your f90 file defining your descendant of CosmologyLikelihood set the speed parateter. E.g.

Code: Select all

  module MyLlike
    use likelihood

    type, extends(CosmologyLikelihood) :: MyLikelihood
    ..
    contains
    ..
    end type MyLikelihood

..
    contains
 ..
    subroutine MyLike_Add(LikeList,Ini)
    class(LikelihoodList) :: LikeList
    Type(TIniFile) :: ini
    type(MyLikelihood), pointer :: like

     allocate(like)
     like%speed =  2
 ..

    call LikeList%Add(like)

...


end module

Adding new parameters to CosmoMC, March-13

Posted: August 01 2013
by Tijmen de Haan
Awesome, thanks Antony!

Adding new parameters to CosmoMC, March-13

Posted: March 21 2014
by Andrei Lazanu
Hi Antony,

Is the same true for the March 2014 version? I have modifeid the March 2013 according to your suggestions and it worked fine, but in the case of the March 2014 one the program compiles but does not seem to correctly read the parameter in the .ini file.

Best,
Andrei

Re: Adding new parameters to CosmoMC, March-13

Posted: March 22 2014
by Antony Lewis
A few things have been renamed. The template is now

Code: Select all

  module MyLlike
    use Likelihood_Cosmology

    type, extends(TCosmologyLikelihood) :: TMyLikelihood
    ..
    contains
    ..
    end type TMyLikelihood

..
    contains
 ..
    subroutine MyLike_Add(LikeList,Ini)
    class(TLikelihoodList) :: LikeList
    class(TSettingIni) :: ini
    type(TMyLikelihood), pointer :: like

     allocate(like)
     like%speed =  2
 ..

    call LikeList%Add(like)

...


end module
You can look at the various provided likelihoods for other examples.

Adding new parameters to CosmoMC, March-13

Posted: March 24 2014
by Andrei Lazanu
Thanks Antony for the reply. In my case the parameter is a physical one so my question is if there is anything different compared to the previous versions apart from the obvious program name renamings, or if there is any other new place where I would have to add the parameter.
To add new theory parameters

* add the definition of the physical parameter to CMBParams in cmbtypes.f90

* Change params_CMB.f90 to add a new parameterization or modify an existing one (with a corresponding .paramnames file with the new parameter names in). In particular the _Init routine does
Code:
call SetTheoryParameterNumbers(num_slow_params,num_semi_slow_params)

which sets the number of hard and semi-hard parameters (the latter being things like initial power spectrum parameters) and then
Code:
call this%Init(Ini,Names, 'params_CMB.paramnames')

to set the parameter names file.

* Modify CMB_Cls_Simple.f90 to pass your new CMBParams parameters to CAMB to actually change the result

* Edit your .ini files to to add range and width settings for the new parameter names

Re: Adding new parameters to CosmoMC, March-13

Posted: March 24 2014
by Antony Lewis
The readme was out of date, I've now updated that section - thanks.

Re: Adding parameters to CosmoMC, March-13

Posted: February 13 2020
by Saisandri Saini
Hii
I am trying to add "mnu" as a parameter to the chains and then use it in my Plots.How can I do it? I am using CosmoMC july 2019. Thanks

Re: Adding new parameters to CosmoMC, March-13

Posted: February 16 2020
by Cristhian GQ
Hello,

in the file batch3/params_CMB_defaults.ini, you need to change

param[mnu] = 0.06

for a fix value, to a a parameter by adding its center value, min value, max value, start width, and propose width. For example, replace the above by

param[mnu] = 0.06 0 0.9 0.005 0.005

or whatever values you want. Then CosmoMC will vary that parameter also.

Best regards,
Cristhian Garcia.

Re: Adding new parameters to CosmoMC, March-13

Posted: February 17 2020
by Antony Lewis
Or, better, set param[mnu] in the ini file for your run rather than changing the default one. Generally you shouldn't need to edit files in batch3, parameters can be overridden in the .ini file actually used.