本文整理匯總了Python中dynesty.NestedSampler方法的典型用法代碼示例。如果您正苦於以下問題:Python dynesty.NestedSampler方法的具體用法?Python dynesty.NestedSampler怎麽用?Python dynesty.NestedSampler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dynesty
的用法示例。
在下文中一共展示了dynesty.NestedSampler方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _run_test
# 需要導入模塊: import dynesty [as 別名]
# 或者: from dynesty import NestedSampler [as 別名]
def _run_test(self):
import dynesty
import pandas as pd
self.sampler = dynesty.NestedSampler(
loglikelihood=self.log_likelihood,
prior_transform=self.prior_transform,
ndim=self.ndim, **self.sampler_init_kwargs)
sampler_kwargs = self.sampler_function_kwargs.copy()
sampler_kwargs['maxiter'] = 2
self.sampler.run_nested(**sampler_kwargs)
N = 100
self.result.samples = pd.DataFrame(
self.priors.sample(N))[self.search_parameter_keys].values
self.result.nested_samples = self.result.samples
self.result.log_likelihood_evaluations = np.ones(N)
self.result.log_evidence = 1
self.result.log_evidence_err = 0.1
return self.result
示例2: __init__
# 需要導入模塊: import dynesty [as 別名]
# 或者: from dynesty import NestedSampler [as 別名]
def __init__(self, model, nlive, nprocesses=1,
loglikelihood_function=None, use_mpi=False, run_kwds=None,
**kwargs):
self.model = model
log_likelihood_call, prior_call = setup_calls(
model,
nprocesses=nprocesses,
loglikelihood_function=loglikelihood_function)
# Set up the pool
pool = choose_pool(mpi=use_mpi, processes=nprocesses)
if pool is not None:
pool.size = nprocesses
self.run_kwds = {} if run_kwds is None else run_kwds
self.nlive = nlive
self.names = model.sampling_params
self.ndim = len(model.sampling_params)
self.checkpoint_file = None
if self.nlive < 0:
# Interpret a negative input value for the number of live points
# (which is clearly an invalid input in all senses)
# as the desire to dynamically determine that number
self._sampler = dynesty.DynamicNestedSampler(log_likelihood_call,
prior_call, self.ndim,
pool=pool, **kwargs)
else:
self._sampler = dynesty.NestedSampler(log_likelihood_call,
prior_call, self.ndim,
nlive=self.nlive,
pool=pool, **kwargs)
示例3: run_sampler
# 需要導入模塊: import dynesty [as 別名]
# 或者: from dynesty import NestedSampler [as 別名]
def run_sampler(self):
import dynesty
logger.info("Using dynesty version {}".format(dynesty.__version__))
if self.kwargs['live_points'] is None:
self.kwargs['live_points'] = (
self.get_initial_points_from_prior(
self.kwargs['nlive']))
if self.kwargs.get("sample", "rwalk") == "rwalk":
logger.info(
"Using the bilby-implemented rwalk sample method with ACT estimated walks")
dynesty.dynesty._SAMPLING["rwalk"] = sample_rwalk_bilby
dynesty.nestedsamplers._SAMPLING["rwalk"] = sample_rwalk_bilby
if self.kwargs.get("walks", 25) > self.kwargs.get("maxmcmc"):
raise DynestySetupError("You have maxmcmc > walks (minimum mcmc)")
if self.kwargs.get("nact", 5) < 1:
raise DynestySetupError("Unable to run with nact < 1")
elif self.kwargs.get("sample") == "rwalk_dynesty":
self._kwargs["sample"] = "rwalk"
logger.info(
"Using the dynesty-implemented rwalk sample method")
elif self.kwargs.get("sample") == "rstagger_dynesty":
self._kwargs["sample"] = "rstagger"
logger.info(
"Using the dynesty-implemented rstagger sample method")
self._setup_pool()
self.sampler = dynesty.NestedSampler(
loglikelihood=_log_likelihood_wrapper,
prior_transform=_prior_transform_wrapper,
ndim=self.ndim, **self.sampler_init_kwargs)
if self.check_point:
out = self._run_external_sampler_with_checkpointing()
else:
out = self._run_external_sampler_without_checkpointing()
self._close_pool()
# Flushes the output to force a line break
if self.kwargs["verbose"]:
self.pbar.close()
print("")
check_directory_exists_and_if_not_mkdir(self.outdir)
dynesty_result = "{}/{}_dynesty.pickle".format(self.outdir, self.label)
with open(dynesty_result, 'wb') as file:
pickle.dump(out, file)
self._generate_result(out)
self.calc_likelihood_count()
self.result.sampling_time = self.sampling_time
if self.plot:
self.generate_trace_plots(out)
return self.result