本文整理汇总了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