def make_sampler(self): ens_samp=EnsembleSampler(self.nwalkers, len(list(self.model.parameters)), self.model.lnposterior, threads=self.threads, args=[self.data]) if self.seed is not None: seed_state=np.random.mtrand.RandomState(self.seed).get_state() ens_samp.random_state=seed_state return ens_samp
def sample_emcee(model, data, nwalkers, nsamples, walker_initial_pos, threads='auto', cleanup_threads=True, seed=None): sampler = EnsembleSampler(nwalkers, len(list(model.parameters)), model.lnposterior, threads=autothreads(threads), args=[data]) if seed is not None: np.random.seed(seed) seed_state = np.random.mtrand.RandomState(seed).get_state() sampler.random_state = seed_state sampler.run_mcmc(walker_initial_pos, nsamples) if sampler.pool is not None and cleanup_threads: sampler.pool.terminate() sampler.pool.join() return sampler
def sample_emcee(model, data, nwalkers, nsamples, walker_initial_pos, threads='auto', cleanup_threads=True, seed=None): sampler = EnsembleSampler(nwalkers, len(list(model.parameters)), model.lnposterior, threads=autothreads(threads), args=[data]) if seed is not None: np.random.seed(seed) seed_state = np.random.mtrand.RandomState(seed).get_state() sampler.random_state=seed_state sampler.run_mcmc(walker_initial_pos, nsamples) if sampler.pool is not None and cleanup_threads: sampler.pool.terminate() sampler.pool.join() return sampler