def createFakeChains(config, nclusters, zcluster, r_mpc_edges, beta_s, galdensity, shapenoise, nsamples=1000, mass=10**15.2): mtrues = mass * np.ones(nclusters) r_mpcs, shearprofiles, shearerrs = createClusterSet( config, mtrues, zcluster, r_mpc_edges, beta_s, galdensity, shapenoise) fitter = nfwfit.buildFitter(config) chains = [] for i in range(nclusters): mcmc_model = None for j in range(10): try: mcmc_model = fitter.model.makeMCMCModel( r_mpcs[i], shearprofiles[i], shearerrs[i], beta_s, beta_s**2, zcluster) break except pymc.ZeroProbability: pass if mcmc_model is None: raise pymc.ZeroProbability manager = varcontainer.VarContainer() options = varcontainer.VarContainer() manager.options = options options.singlecore = True options.adapt_every = 100 options.adapt_after = 100 options.nsamples = nsamples manager.model = mcmc_model runner = pma.MyMCMemRunner() runner.run(manager) runner.finalize(manager) chains.append(manager.chain['m200'][200:]) return mtrues, chains
def memsample(parts, samples, adaptevery = 100, adaptafter = 100): options = varcontainer.VarContainer() options.singlecore = True options.nsamples = samples options.adapt_every = adaptevery options.adapt_after = adaptafter manager = varcontainer.VarContainer() manager.options = options manager.model = pymc.Model(parts) runner = pma.MyMCMemRunner() runner.run(manager) runner.finalize(manager) return manager.chain
def __call__(self, profile): chains = {} for delta in self.deltas: mcmc_model = None for i in range(20): try: mcmc_model = self.model.makeMCMCModel(profile, delta = delta) break except pymc.ZeroProbability: pass if mcmc_model is None: raise pymc.ZeroProbability # This sets up Adam Mantz's version of an MCMC sampler for production code calculations. # This is stored in mymcmc_adapter.py (converts to talk with other MCMC code) # Imported as pma above. manager = varcontainer.VarContainer() options = varcontainer.VarContainer() manager.options = options options.singlecore = True options.adapt_every = 100 options.adapt_after = 100 options.nsamples = self.nsamples manager.model = mcmc_model runner = pma.MyMCMemRunner() runner.run(manager) runner.finalize(manager) reducedchain = dict(cdelta = np.hstack(manager.chain['cdelta'][5000::2]).astype(np.float32), mdelta = np.hstack(manager.chain['mdelta'][5000::2]).astype(np.float32), likelihood = np.hstack(manager.chain['likelihood'][5000::2]).astype(np.float32)) chains[delta] = reducedchain return chains
def __call__(self, profile): chains = {} for delta in self.deltas: mcmc_model = None for i in range(20): try: mcmc_model = self.model.makeMCMCModel(profile, delta=delta) break except pymc.ZeroProbability: pass if mcmc_model is None: raise pymc.ZeroProbability manager = varcontainer.VarContainer() options = varcontainer.VarContainer() manager.options = options options.singlecore = True options.adapt_every = 100 options.adapt_after = 100 options.nsamples = self.nsamples manager.model = mcmc_model runner = pma.MyMCMemRunner() runner.run(manager) runner.finalize(manager) reducedchain = dict( cdelta=np.hstack(manager.chain['cdelta'][5000::2]).astype( np.float32), mdelta=np.hstack(manager.chain['mdelta'][5000::2]).astype( np.float32), likelihood=np.hstack( manager.chain['likelihood'][5000::2]).astype(np.float32)) chains[delta] = reducedchain return chains
def memsample(model, samples, adaptevery=100, adaptafter=100, outputFile=None): options = varcontainer.VarContainer() options.singlecore = True options.nsamples = samples options.adapt_every = adaptevery options.adapt_after = adaptafter if outputFile: options.outputFile = outputFile manager = varcontainer.VarContainer() manager.options = options manager.model = model runner = pma.MyMCMemRunner() runner.run(manager) if outputFile: runner.dump(manager) runner.finalize(manager) return manager.chain