Likelihood class module¶

Contains the definition of the base likelihood class Likelihood, with basic functions, as well as more specific likelihood classes that may be reused to implement new ones.

class likelihood_class.Likelihood(path, data, command_line)[source]

Bases: object

General class that all likelihoods will inherit from.

It copies the content of self.path from the initialization routine of the Data class, and defines a handful of useful methods, that every likelihood might need.

If the nuisance parameters required to compute this likelihood are not defined (either fixed or varying), the code will stop.

Parameters: data (class) – Initialized instance of Data command_line (NameSpace) – NameSpace containing the command line arguments
add_contamination_spectra(cl, data)[source]
add_nuisance_prior(lkl, data)[source]
computeLikelihood(ctx)[source]

Interface with CosmoHammer

Parameters: ctx (Context) – Contains several dictionaries storing data and cosmological information
get_cl(cosmo, l_max=-1)[source]

Return the $$C_{\ell}$$ from the cosmological code in $$\mu {\rm K}^2$$

loglkl(cosmo, data)[source]

Placeholder to remind that this function needs to be defined for a new likelihood.

Raises: NotImplementedError
need_cosmo_arguments(data, dictionary)[source]

Ensure that the arguments of dictionary are defined to the correct value in the cosmological code

Warning

So far there is no way to enforce a parameter where smaller is better. A bigger value will always overried any smaller one (cl_max, etc...)

Parameters: data (dict) – Initialized instance of data dictionary (dict) – Desired precision for some cosmological parameters
read_contamination_spectra(data)[source]
read_from_file(path, data, command_line)[source]

Extract the information from the log.param concerning this likelihood.

If the log.param is used, check that at least one item for each likelihood is recovered. Otherwise, it means the log.param does not contain information on the likelihood. This happens when the first run fails early, before calling the likelihoods, and the program did not log the information. This check might not be completely secure, but it is better than nothing.

Warning

This checks relies on the fact that a likelihood should always have at least one line of code written in the likelihood.data file. This should be always true, but in case a run fails with the error message described below, think about it.

Warning

As of version 2.0.2, you can specify likelihood options in the parameter file. They have complete priority over the ones specified in the likelihood.data file, and it will be reflected in the log.param file.

class likelihood_class.Likelihood_clik(path, data, command_line)[source]
loglkl(cosmo, data)[source]
class likelihood_class.Likelihood_clocks(path, data, command_line)[source]

Base implementation of H(z) measurements

loglkl(cosmo, data)[source]
class likelihood_class.Likelihood_mock_cmb(path, data, command_line)[source]
compute_lkl(cl, cosmo, data)[source]
loglkl(cosmo, data)[source]
class likelihood_class.Likelihood_mpk(path, data, command_line, common=False, common_dict={})[source]
add_common_knowledge(common_dictionary)[source]

Add to a class the content of a shared dictionary of attributes

The purpose of this method is to set some attributes globally for a Pk likelihood, that are shared amongst all the redshift bins (in WiggleZ.data for instance, a few flags and numbers are defined that will be transfered to wigglez_a, b, c and d

loglkl(cosmo, data)[source]
class likelihood_class.Likelihood_newdat(path, data, command_line)[source]
compute_lkl(cl, cosmo, data)[source]
loglkl(cosmo, data)[source]
class likelihood_class.Likelihood_prior(path, data, command_line)[source]

It copies the content of self.path from the initialization routine of the Data class, and defines a handful of useful methods, that every likelihood might need.

If the nuisance parameters required to compute this likelihood are not defined (either fixed or varying), the code will stop.

Parameters: data (class) – Initialized instance of Data command_line (NameSpace) – NameSpace containing the command line arguments
loglkl()[source]
class likelihood_class.Likelihood_sn(path, data, command_line)[source]
read_configuration_file()[source]

Extract Python variables from the configuration file

This routine performs the equivalent to the program “inih” used in the original c++ library.

read_light_curve_parameters()[source]

Read the file jla_lcparams.txt containing the SN data

Note

the length of the resulting array should be equal to the length of the covariance matrices stored in C00, etc...

read_matrix(path)[source]

extract the matrix from the path

This routine uses the blazing fast pandas library (0.10 seconds to load a 740x740 matrix). If not installed, it uses a custom routine that is twice as slow (but still 4 times faster than the straightforward numpy.loadtxt method)

Note

the length of the matrix is stored on the first line... then it has to be unwrapped. The pandas routine read_table understands this immediatly, though.