def test_modules(self):
     chain = LikelihoodComputationChain()
     
     assert len(chain.getCoreModules())==0
     assert len(chain.getLikelihoodModules())==0
     
     coreModule = DummyModule()
     likeModule = DummyModule()
     chain.addCoreModule(coreModule)
     chain.addLikelihoodModule(likeModule)
     assert len(chain.getCoreModules())==1
     assert len(chain.getLikelihoodModules())==1
     
     chain.setup()
     assert coreModule.init
     assert likeModule.init
     
     like, data = chain([0])
     
     assert coreModule.called
     assert likeModule.compLike
     
     assert like == DummyModule.like
     assert len(data) == 1
     assert data["data"] == DummyModule.data
Ejemplo n.º 2
0
    def test_modules(self):
        chain = LikelihoodComputationChain()

        assert len(chain.getCoreModules()) == 0
        assert len(chain.getLikelihoodModules()) == 0

        coreModule = DummyModule()
        likeModule = DummyModule()
        chain.addCoreModule(coreModule)
        chain.addLikelihoodModule(likeModule)
        assert len(chain.getCoreModules()) == 1
        assert len(chain.getLikelihoodModules()) == 1

        chain.setup()
        assert coreModule.init
        assert likeModule.init

        like, data = chain([0])

        assert coreModule.called
        assert likeModule.compLike

        assert like == DummyModule.like
        assert len(data) == 1
        assert data["data"] == DummyModule.data
Ejemplo n.º 3
0
    szs = np.array(hf.get("szs_parms")).astype(int)

mins = params[:, 1]
maxs = params[:, 2]
nparam = len(mins)
#--------------------------------------------------------------------------------
#################################################################################################
####################################### LIKELIHOOD CHAIN ########################
#-------------------- Setup the Chain --------
# if mins, and maxs included, the code performs checkin
# and can calculate a null iteration of Generated Quantities in case of rejection
print 'Setting up chain'
chain = LikelihoodComputationChain()
coremodule = CoreModule(szs)
logPosterior = LogPosteriorModule(data, threads=k)
chain.addCoreModule(coremodule)
chain.addLikelihoodModule(logPosterior)
chain.setup()
#######################################################################################
############################### Particle Swarm Optimizer #############################
pso = MPSO(chain,
           low=mins,
           high=maxs,
           particleCount=partCount,
           req=req,
           threads=1,
           InPos=inpos)
smp = emcee.EnsembleSampler(
    partCount,
    nparam,
    chain,
Ejemplo n.º 4
0
        for tr_j in tracers[ntracers0:]:
            if tr_i.split('_')[0] != tr_j.split('_')[0]:
                # Generate the appropriate list of tracer combinations to plot
                trc_combs.append([tr_i, tr_j])
        i += 1
else:
    raise NotImplementedError('Only fit_comb = all, auto and cross supported. Aborting.')

logger.info('Fitting tracer combination = {}.'.format(trc_combs))

coremod_config = copy.deepcopy(config)
coremod_config['param_mapping'] = param_mapping
coremod_config['hmparams'] = hmparams
coremod_config['cosmo'] = cosmo
coremod_config['trc_combs'] = trc_combs
chain.addCoreModule(GSKYCore(saccfile_coadd, coremod_config))

chain.addLikelihoodModule(GSKYLike(saccfile_coadd, noise_saccfile_coadd))

chain.setup()

chaindir = os.path.join('chains', config['output_run_dir'])
if not os.path.isdir(get_output_fname(config, chaindir)):
    os.makedirs(get_output_fname(config, chaindir))

path2chain = os.path.join('chains', config['output_run_dir'] + '/' + ch_config_params['chainsPrefix'])

if ch_config_params['use_mpi'] == 0:
    if ch_config_params['rerun'] == 0:
        sampler = CosmoHammerSampler(
            params=params,
Ejemplo n.º 5
0
from cosmoHammer import LikelihoodComputationChain
from cosmoHammer.util import Params
from MCMC.Power_sampler.Power_like import PSlikeModule as slk
from MCMC.Power_sampler.Power_core import PScore

#======================================================================================================================#

params = Params(("n_ion", [250., 10.0, 510.0, 1.0]),
                ("R_mfp", [38.0, 5.0, 70.0, .5]),
                ("NoH", [750.0, 10.0, 1510.0, 1.0]))
#==========The parameter space is defined================================#
#======================================================================================================================#

chain = LikelihoodComputationChain(min=params[:, 1], max=params[:, 2])

chain.addCoreModule(
    PScore())  #=========setting up the modules===================#

chain.addLikelihoodModule(slk())

chain.setup()
#======================================================================================================================#

sampler = MpiCosmoHammerSampler(
    params=params,
    likelihoodComputationChain=
    chain,  #=============mpi sampler===============================#
    filePrefix="Powerspectrum_THANN_",
    walkersRatio=10,
    burninIterations=250,
    sampleIterations=250)
Ejemplo n.º 6
0
from wmap9Wrapper import WmapExtLikelihoodModule as wmap9
from cambWrapper import CambCoreModule

#parameter start center, min, max, start width
params = Params(
    ("hubble", [70, 65, 80, 3]), ("ombh2", [0.0226, 0.01, 0.03, 0.001]),
    ("omch2", [0.122, 0.09, 0.2, 0.01]),
    ("scalar_amp", [2.1e-9, 1.8e-9, 2.35e-9, 1e-10]),
    ("scalar_spectral_index", [0.96, 0.8, 1.2, 0.02]),
    ("re_optical_depth", [0.09, 0.01, 0.1, 0.03]), ("sz_amp", [1, 0, 2, 0.4]))

chain = LikelihoodComputationChain(min=params[:, 1], max=params[:, 2])

camb = CambCoreModule.CambCoreModule()

chain.addCoreModule(camb)

chain.addLikelihoodModule(wmap9.WmapExtLikelihoodModule())

chain.setup()

sampler = MpiCosmoHammerSampler(params=params,
                                likelihoodComputationChain=chain,
                                filePrefix="cosmoHammerWmap9_",
                                walkersRatio=20,
                                burninIterations=0,
                                sampleIterations=50)

print("start sampling")
sampler.startSampling()
print("done!")
Ejemplo n.º 7
0
#parameter start center, min, max, start width
params = Params(("hubble",                [70, 65, 80, 3]),
                ("ombh2",                 [0.0226, 0.01, 0.03, 0.001]),
                ("omch2",                 [0.122, 0.09, 0.2, 0.01]),
                ("scalar_amp",            [2.1e-9, 1.8e-9, 2.35e-9, 1e-10]),
                ("scalar_spectral_index", [0.96, 0.8, 1.2, 0.02]),
                ("re_optical_depth",      [0.09, 0.01, 0.1, 0.03]),
                ("sz_amp",                [1,0,2,0.4]))

chain = LikelihoodComputationChain(
                    min=params[:,1], 
                    max=params[:,2])

camb = CambCoreModule.CambCoreModule()

chain.addCoreModule(camb)

chain.addLikelihoodModule(wmap9.WmapExtLikelihoodModule())

chain.setup()


sampler = MpiCosmoHammerSampler(
                params= params, 
                likelihoodComputationChain=chain, 
                filePrefix="cosmoHammerWmap9_", 
                walkersRatio=20, 
                burninIterations=0, 
                sampleIterations=50)

print("start sampling")