## Cobaya: adding a derived parameter to likelihood class

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Agne Semenaite
Posts: 6
Joined: June 08 2020
Affiliation: Max Planck Institute for Extraterrestrial Physics

### Cobaya: adding a derived parameter to likelihood class

Hi, I am trying to add a derived parameter sigma12 to the DES likelihood.

I modified the cobaya base DES likelihood class and made use of the provider function sigma_R in order to get a theory calculation of sigma12, however, I am not sure how to actually add it as a derived parameter. It seems like only likelihood functions have the option of adding a dictionary of derived parameters and having it returned in a tuple together with the logp value. However, I cannot find what the equivalent is when dealing with a likelihood class (such as DES) when the calculation of the derived parameter is non-trivial and requires theory products.

Thank you for any help!

Antony Lewis
Posts: 1686
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

### Re: Cobaya: adding a derived parameter to likelihood class

If the logp method of class I think you can set the "_derived" element of params_values_dict to the dictionary of your output derived parameters.

Agne Semenaite
Posts: 6
Joined: June 08 2020
Affiliation: Max Planck Institute for Extraterrestrial Physics

### Re: Cobaya: adding a derived parameter to likelihood class

Thank you, this is very helpful! However, I think I am still missing something. I have set the "_derived" element in logp function, as you suggested:

Code: Select all


derived = {"sigma_12": sigma_12}
params_values["_derived"] = derived
return -0.5 * self.chi_squared(theory, return_theory_vector=False)

and if I check the items in params dictionary everything seems to be set appropriately, however, I still get this error:

Code: Select all

[exception handler] ---------------------------------------

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/bin/cobaya-run", line 8, in <module>
sys.exit(run_script())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/run.py", line 193, in run_script
run(info)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/run.py", line 101, in run
sampler.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/sampler.py", line 270, in run
self._run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/samplers/evaluate/evaluate.py", line 64, in _run
self.logposterior = self.model.logposterior(reference_point)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/model.py", line 413, in logposterior
make_finite=make_finite, cached=cached, _no_check=True)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/model.py", line 318, in loglikes
cached=cached, make_finite=make_finite)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/model.py", line 279, in logps
derived_list = [derived_dict[p] for p in self.output_params]
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cobaya/model.py", line 279, in <listcomp>
derived_list = [derived_dict[p] for p in self.output_params]
KeyError: 'sigma_12'
-------------------------------------------------------------

If I check the derived_dict in model.py, it looks like sigma_12 is not on the derived dictionary anymore, as it only contains the usual CAMB parameters...

Antony Lewis
Posts: 1686
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

### Re: Cobaya: adding a derived parameter to likelihood class

Try not making a new dictionary object, e.g.

Code: Select all

        params_values["_derived"]["sigma_12"] = sigma_12

Agne Semenaite
Posts: 6
Joined: June 08 2020
Affiliation: Max Planck Institute for Extraterrestrial Physics

### Re: Cobaya: adding a derived parameter to likelihood class

That worked, thanks so much!