Sampler module¶
This module defines one key function, run()
, that distributes the work to
the desired actual sampler (Metropolis Hastings, or Nested Sampling so far).
It also defines a serie of helper functions, that aim to be generically used by all different sampler methods:
-
sampler.
accept_step
(data)[source]¶ Transfer the ‘current’ point in the varying parameters to the last accepted one.
-
sampler.
check_flat_bound_priors
(parameters, names)[source]¶ Ensure that all varying parameters are bound and flat
It is a necessary condition to use the code with Nested Sampling or the Cosmo Hammer.
-
sampler.
compute_lkl
(cosmo, data)[source]¶ Compute the likelihood, given the current point in parameter space.
This function now performs a test before calling the cosmological model (new in version 1.2). If any cosmological parameter changed, the flag
data.need_cosmo_update
will be set toTrue
, from the routinecheck_for_slow_step
.Returns: loglike (float) – The log of the likelihood (\(\frac{-\chi^2}2\)) computed from the sum of the likelihoods of the experiments specified in the input parameter file. This function returns
data.boundary_loglkie
, defined in the moduledata
if i) the current point in the parameter space has hit a prior edge, or ii) the cosmological module failed to compute the model. This value is chosen to be extremly small (large negative value), so that the step will always be rejected.
-
sampler.
get_covariance_matrix
(cosmo, data, command_line)[source]¶ Compute the covariance matrix, from an input file or from an existing matrix.
Reordering of the names and scaling take place here, in a serie of potentially hard to read methods. For the sake of clarity, and to avoid confusions, the code will, by default, print out a succession of 4 covariance matrices at the beginning of the run, if starting from an existing one. This way, you can control that the paramters are set properly.
Note
The set of parameters from the run need not to be the exact same set of parameters from the existing covariance matrix (not even the ordering). Missing parameter from the existing covariance matrix will use the sigma given as an input.
-
sampler.
read_args_from_bestfit
(data, bestfit)[source]¶ Deduce the starting point either from the input file, or from a best fit file.
Parameters: bestfit (str) – Name of the bestfit file from the command line.
-
sampler.
read_args_from_chain
(data, chain)[source]¶ Pick up the last accepted values from an input chain as a starting point
Function used only when the restart flag is set. It will simply read the last line of an input chain, using the tail command from the extended
io_mp.File
class.Warning
That method was not tested since the adding of derived parameters. The method
read_args_from_bestfit()
is the prefered one.Warning
This method works because of the particular presentation of the chain, and the use of tabbings (not spaces). Please keep this in mind if you are having difficulties
Parameters: chain (str) – Name of the input chain provided with the command line.
-
sampler.
run
(cosmo, data, command_line)[source]¶ Depending on the choice of sampler, dispatch the appropriate information
The
mcmc
module is used as previously, except the call tomcmc.chain()
, ornested_sampling.run()
is now within this function, instead of from withinMontePython
.In the long term, this function should contain any potential hybrid scheme.