예제 #1
0
 def run_minuit(self, kwargs={}):
     solver = Minuit(self._core_lsq, [0.5] * len(self._activelist),
                     name=sorted(self._activelist))
     solver.limits = (0., 1.)
     solver.migrad()
     best = np.array(solver.values)
     solver.minos()
     err = np.array(solver.errors)
     names = sorted(self._activelist)
     for i in range(len(names)):
         low, high = self.paramrange[names[i]]
         best[i] = umap(best[i], [low, high])
         err[i] = umap(err[i], [low, high])
     return (best, err)
예제 #2
0
 def run_dynesty(self, kwargs={}):
     # dynesty solver
     solver = DynamicNestedSampler(self._core_likelihood, self.prior,
                                   len(self._activelist))
     solver.run_nested(**kwargs)
     results = solver.results
     names = sorted(self._activelist)
     for i in range(len(names)):
         low, high = self.paramrange[names[i]]
         results.samples[:, i] = umap(results.samples[:, i], [low, high])
     return results
예제 #3
0
 def _core_lsq(self, cube):
     if np.any(cube > 1.) or np.any(cube < 0.):
         return np.nan_to_num(np.inf)
     name_list = sorted(self._activelist)
     for i in range(len(name_list)):
         name = name_list[i]
         tmp = umap(cube[i], self._paramrange[name])
         if self._foreground is not None:
             self._foreground.reset({name: tmp})
         if self._background is not None:
             self._background.reset({name: tmp})
     # predict data
     if self._foreground is None:
         return self.lsq(self._background.bandpower())
     elif self._background is None:
         return self.lsq(self._foreground.bandpower())
     else:
         return self.lsq(self._foreground.bandpower() +
                         self._background.bandpower())
예제 #4
0
 def run_emcee(self, kwargs={'nwalker': 100, 'nstep': 10000}):
     # emcee solver
     solver = emcee.EnsembleSampler(kwargs['nwalker'],
                                    len(self._activelist),
                                    self._core_likelihood)
     state = solver.run_mcmc(
         np.random.uniform(size=(kwargs['nwalker'], len(self._activelist))),
         kwargs['nstep'] // 10)  # burn-in
     solver.reset()
     state = solver.run_mcmc(state, kwargs['nstep'])
     tau = int(np.mean(solver.get_autocorr_time())
               )  # estimate integral auto-correlation time
     if (kwargs['nstep'] < 50 * tau):  # if the pre-set step is not enough
         solver.reset()
         solver.run_mcmc(state, 100 * tau)
     results = solver.get_chain(discard=10 * tau, flat=True)
     names = sorted(self._activelist)
     for i in range(len(names)):
         low, high = self.paramrange[names[i]]
         results[:, i] = umap(results[:, i], [low, high])
     return results