cosmoHammer package

Submodules

cosmoHammer.ChainContext module

class cosmoHammer.ChainContext.ChainContext(parent, params)[source]

Bases: object

Context holding a dict to store data and information durring the computation of the likelihood

add(key, value)[source]

Adds the value to the context using the key

Parameters:
  • key – string key to use
  • value – object the value to store
contains(key)[source]

Checks if the key is in the context

Parameters:key – string key to check
Returns:True if the key is in the context
get(key, default=None)[source]

Returns the value stored in the context at the key or the default value in the context doesn’t contain the key

Parameters:
  • key – string key to use
  • default – string the default value to use if the key is not available
getData()[source]

Returns the data

Returns:The data of this context
getParams()[source]

Returns the currently processed parameters

Returns:The param of this context
getParent()[source]

Returns the parent

Returns:The parent chain of this context
remove(key)[source]

Removes the value from the context

Parameters:key – string key to remove from the context

cosmoHammer.ConcurrentMpiCosmoHammerSampler module

class cosmoHammer.ConcurrentMpiCosmoHammerSampler.ConcurrentMpiCosmoHammerSampler(threads=1, **kwargs)[source]

Bases: cosmoHammer.MpiCosmoHammerSampler.MpiCosmoHammerSampler

A sampler implementation extending the mpi sampler in order to allow to distribute the computation with MPI and using multiprocessing on a single node.

Parameters:
  • threads – (optional) The number of threads to use for parallelization. If threads == 1, then the multiprocessing module is not used but if threads > 1, then a Pool object is created
  • kwargs – key word arguments passed to the CosmoHammerSampler

cosmoHammer.Constants module

Some constants used by the samplers

cosmoHammer.CosmoHammerSampler module

class cosmoHammer.CosmoHammerSampler.CosmoHammerSampler(params, likelihoodComputationChain, filePrefix, walkersRatio, burninIterations, sampleIterations, stopCriteriaStrategy=None, initPositionGenerator=None, storageUtil=None, threadCount=1, reuseBurnin=False, logLevel=20, pool=None)[source]

Bases: object

A complete sampler implementation taking care of correct setup, chain burn in and sampling.

Parameters:
  • params – the parameter of the priors
  • likelihoodComputationChain – the callable computation chain
  • filePrefix – the prefix for the log and output files
  • walkersRatio – the ratio of walkers and the count of sampled parameters
  • burninIterations – number of iteration for burn in
  • sampleIterations – number of iteration to sample
  • stopCriteriaStrategy – the strategy to stop the sampling. Default is None an then IterationStopCriteriaStrategy is used
  • initPositionGenerator – the generator for the init walker position. Default is None an then SampleBallPositionGenerator is used
  • storageUtil – util used to store the results
  • threadCount – The count of threads to be used for the computation. Default is 1
  • reuseBurnin – Flag if the burn in should be reused. If true the values will be read from the file System. Default is False
createEmceeSampler(callable, **kwargs)[source]

Factory method to create the emcee sampler

createInitPos()[source]

Factory method to create initial positions

createInitPositionGenerator()[source]

Returns a new instance of a Init Position Generator

createSampleFileUtil()[source]

Returns a new instance of a File Util

createStopCriteriaStrategy()[source]

Returns a new instance of a stop criteria stategy

getChain()[source]

Returns the sample chain

isMaster()[source]

Returns True. Can be overridden for multitasking i.e. with MPI

loadBurnin()[source]

loads the burn in form the file system

log(message, level=20)[source]

Logs a message to the logfile

paramValues
paramWidths
resetSampler()[source]

Resets the emcee sampler in the master node

sample(burninPos, burninProb=None, burninRstate=None, datas=None)[source]

Starts the sampling process

sampleBurnin(p0)[source]

Run the emcee sampler for the burnin to create walker which are independent form their starting position

startSampleBurnin()[source]

Runs the sampler for the burn in

startSampling()[source]

Launches the sampling

cosmoHammer.LikelihoodComputationChain module

class cosmoHammer.LikelihoodComputationChain.LikelihoodComputationChain(min=None, max=None)[source]

Bases: object

Implementation of a likelihood computation chain.

addCoreModule(module)[source]

adds a module to the likelihood module list

Parameters:module – callable the callable module to add for the computation of the data
addLikelihoodModule(module)[source]

adds a module to the likelihood module list

Parameters:module – callable the callable module to add for the likelihood computation
computeLikelihoods(ctx)[source]

Computes the likelihoods by iterating thru all the modules. Sums up the log likelihoods.

createChainContext(p)[source]

Returns a new instance of a chain context

getCoreModules()[source]

pointer to the likelihood module list

getLikelihoodModules()[source]

pointer to the core module list

invokeCoreModule(coreModule, ctx)[source]

Invokes the given module with the given ChainContext

invokeCoreModules(ctx)[source]

Iterates thru the core modules and invokes them

invokeLikelihoodModule(likelihoodModule, ctx)[source]

Invokes the given module with the given ChainContext

isValid(p)[source]

checks if the given parameters are valid

setup()[source]

sets up the chain and its modules

cosmoHammer.MpiCosmoHammerSampler module

class cosmoHammer.MpiCosmoHammerSampler.MpiCosmoHammerSampler(**kwargs)[source]

Bases: cosmoHammer.CosmoHammerSampler.CosmoHammerSampler

A sampler implementation extending the regular sampler in order to allow for distributing the computation with MPI.

Parameters:kwargs – key word arguments passed to the CosmoHammerSampler
createInitPos()[source]

Factory method to create initial positions

createSampleFileUtil()[source]

Returns a new instance of a File Util

isMaster()[source]

Returns true if the rank is 0

loadBurnin()[source]

loads the burn in form the file system

sample(burninPos, burninProb, burninRstate, datas)[source]

Starts the sampling process. The master node (mpi rank = 0) persists the result to the disk

sampleBurnin(p0)[source]

Starts the sampling process. The master node (mpi rank = 0) persists the result to the disk

cosmoHammer.exceptions module

exception cosmoHammer.exceptions.InvalidLikelihoodException(params=None)[source]

Bases: cosmoHammer.exceptions.LikelihoodComputationException

Exception for invalid likelihoods e.g. -loglike >= 0.0

exception cosmoHammer.exceptions.LikelihoodComputationException[source]

Bases: exceptions.Exception

Exception for likelihood computation

Module contents

cosmoHammer.getLogger()[source]