Skip to content

Commit 9190552

Browse files
committed
small changes
1 parent 844bccd commit 9190552

3 files changed

Lines changed: 56 additions & 55 deletions

File tree

py/dynesty/dynamicsampler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def _configure_batch_sampler(main_sampler,
758758
batch_sampler.live_u = live_u
759759
batch_sampler.live_v = live_v
760760
batch_sampler.live_logl = live_logl
761-
batch_sampler.inner_sampler.scale = live_scale
761+
batch_sampler.internal_sampler.scale = live_scale
762762
batch_sampler.live_blobs = live_blobs
763763

764764
batch_sampler.update_bound_if_needed(logl_min)
@@ -1333,7 +1333,7 @@ def sample_initial(self,
13331333
blob=results.blob,
13341334
boundidx=results.boundidx,
13351335
bounditer=results.bounditer,
1336-
scale=self.sampler.inner_sampler.scale)
1336+
scale=self.sampler.internal_sampler.scale)
13371337

13381338
self.base_run.append(add_info)
13391339
self.saved_run.append(add_info)
@@ -1378,7 +1378,7 @@ def sample_initial(self,
13781378
n=self.nlive_init - it,
13791379
boundidx=results.boundidx,
13801380
bounditer=results.bounditer,
1381-
scale=self.sampler.inner_sampler.scale)
1381+
scale=self.sampler.internal_sampler.scale)
13821382

13831383
self.base_run.append(add_info)
13841384
self.saved_run.append(add_info)
@@ -1586,7 +1586,7 @@ def sample_batch(self,
15861586
n=nlive_new,
15871587
boundidx=results.boundidx,
15881588
bounditer=results.bounditer,
1589-
scale=batch_sampler.inner_sampler.scale)
1589+
scale=batch_sampler.internal_sampler.scale)
15901590
self.new_run.append(D)
15911591
# Increment relevant counters.
15921592
self.ncall += results.nc
@@ -1635,7 +1635,7 @@ def sample_batch(self,
16351635
blob=results.blob,
16361636
boundidx=results.boundidx,
16371637
bounditer=results.bounditer,
1638-
scale=batch_sampler.inner_sampler.scale)
1638+
scale=batch_sampler.internal_sampler.scale)
16391639
self.new_run.append(D)
16401640

16411641
# Increment relevant counters.

py/dynesty/sampler.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,23 @@ def __init__(self,
136136

137137
self.sampling = sampling
138138
if sampling == 'rslice':
139-
inner_sampler = RSliceSampler(slices=kwargs.get('slices'),
140-
**sampler_kw)
139+
internal_sampler = RSliceSampler(slices=kwargs.get('slices'),
140+
**sampler_kw)
141141
elif sampling == 'slice':
142-
inner_sampler = SliceSampler(slices=kwargs.get('slices'),
143-
**sampler_kw)
142+
internal_sampler = SliceSampler(slices=kwargs.get('slices'),
143+
**sampler_kw)
144144
elif sampling == 'rwalk':
145-
inner_sampler = RWalkSampler(ncdim=self.ncdim,
146-
walks=kwargs.get('walks'),
147-
**sampler_kw)
145+
internal_sampler = RWalkSampler(ncdim=self.ncdim,
146+
walks=kwargs.get('walks'),
147+
**sampler_kw)
148148
elif sampling == 'unif':
149-
inner_sampler = UniformBoundSampler(**sampler_kw)
149+
internal_sampler = UniformBoundSampler(**sampler_kw)
150150
else:
151151
raise ValueError(f'Unsupported Sampler {sampling}')
152152
# This is the sampler that will be used to sample after we
153153
# are done with the unit cube sampling
154-
self.inner_sampler_next = inner_sampler
155-
self.inner_sampler = UnitCubeSampler(ndim=ndim)
154+
self.internal_sampler_next = internal_sampler
155+
self.internal_sampler = UnitCubeSampler(ndim=ndim)
156156

157157
# parallelism
158158
self.pool = pool # provided pool
@@ -469,7 +469,7 @@ def update_bound_if_needed(self, loglstar, ncall=None, force=False):
469469
if self.unit_cube_sampling:
470470
self.unit_cube_sampling = False
471471
self.logl_first_update = loglstar
472-
self.inner_sampler = self.inner_sampler_next
472+
self.internal_sampler = self.internal_sampler_next
473473
bound = self.update_bound(subset=subset)
474474
if self.save_bounds:
475475
self.bound_list.append(bound)
@@ -509,15 +509,15 @@ def _fill_queue(self, loglstar):
509509
# function.
510510
mapper = map
511511

512-
args = self.inner_sampler.prepare_sampler(
512+
args = self.internal_sampler.prepare_sampler(
513513
loglstar=loglstar,
514514
points=point_queue,
515515
axes=axes_queue,
516516
seeds=seeds,
517517
prior_transform=self.prior_transform,
518518
loglikelihood=self.loglikelihood,
519519
nested_sampler=self)
520-
self.queue = list(mapper(self.inner_sampler.sample, args))
520+
self.queue = list(mapper(self.internal_sampler.sample, args))
521521

522522
def _get_point_value(self, loglstar):
523523
"""Grab the first live point proposal in the queue."""
@@ -550,7 +550,8 @@ def _new_point(self, loglstar):
550550
# with our proposal (sampling) method.
551551
# If it's not empty we are just accumulating the
552552
# the history of evaluations
553-
self.inner_sampler.tune(sampling_info, update=self.nqueue <= 0)
553+
self.internal_sampler.tune(sampling_info,
554+
update=self.nqueue <= 0)
554555

555556
# the reason I'm not using self.ncall is that it's updated at
556557
# higher level
@@ -679,7 +680,7 @@ def add_live_points(self):
679680
boundidx=boundidx,
680681
it=point_it,
681682
bounditer=bounditer,
682-
scale=self.inner_sampler.scale,
683+
scale=self.internal_sampler.scale,
683684
blob=old_blob))
684685
self.eff = 100. * (self.it + i) / self.ncall # efficiency
685686

@@ -995,7 +996,7 @@ def sample(self,
995996
nc=nc,
996997
it=worst_it,
997998
bounditer=bounditer,
998-
scale=self.inner_sampler.scale,
999+
scale=self.internal_sampler.scale,
9991000
blob=old_blob))
10001001

10011002
# Update the live point (previously our "worst" point).

py/dynesty/sampling.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class InternalSampler:
4444

4545
def __init__(self, **kwargs):
4646
"""Initialize the internal sampler.
47-
47+
4848
Parameters
4949
----------
5050
kwargs : dict
@@ -95,7 +95,7 @@ def prepare_sampler(self,
9595
`~numpy` array of length `ndim`.
9696
nested_sampler : `~dynesty.samplers.Sampler`
9797
The nested sampler object used to sample.
98-
98+
9999
Returns
100100
-------
101101
arglist:
@@ -116,8 +116,8 @@ def prepare_sampler(self,
116116
arg_list.append(curarg)
117117
return arg_list
118118

119-
@classmethod
120-
def sample(cls, args):
119+
@staticmethod
120+
def sample(args):
121121
"""
122122
Sample a new live point.
123123
@@ -141,15 +141,15 @@ def sample(cls, args):
141141
"""
142142
pass
143143

144-
def tune(sample_info, update=False):
144+
def tune(self, sampling_info, update=False):
145145
"""
146146
147-
Accumulate sampling info and optionally update the proposal scale and
147+
Accumulate sampling info and optionally update the proposal scale and
148148
other tuning parameters.
149149
150150
Parameters
151151
----------
152-
sample_info : dict
152+
sampling_info : dict
153153
Dictionary containing the sampling information.
154154
update : bool
155155
Whether to update the proposal scale or not (default: False).
@@ -176,8 +176,8 @@ def prepare_sampler(self,
176176
"""
177177
Prepare the list of arguments for sampling.
178178
179-
This is is overriding the base class method and providing the bound itself
180-
to the sampler through kwargs.
179+
This is is overriding the base class method and providing the bound
180+
itself to the sampler through kwargs.
181181
182182
"""
183183
self.kwargs['bound'] = nested_sampler.bound
@@ -194,8 +194,8 @@ def prepare_sampler(self,
194194
loglikelihood=loglikelihood,
195195
nested_sampler=nested_sampler)
196196

197-
@classmethod
198-
def sample(cls, args):
197+
@staticmethod
198+
def sample(args):
199199
"""
200200
Return a new live point sampling uniformly within the
201201
boundary.
@@ -309,8 +309,8 @@ def prepare_sampler(self,
309309
loglikelihood=loglikelihood,
310310
nested_sampler=nested_sampler)
311311

312-
@classmethod
313-
def sample(cls, args):
312+
@staticmethod
313+
def sample(args):
314314
"""
315315
Return a new live point sampling uniformly within the
316316
boundary.
@@ -425,8 +425,8 @@ def tune(self, sampling_info, update=True):
425425
hist['naccept'] = 0
426426
hist['nreject'] = 0
427427

428-
@classmethod
429-
def sample(cls, args):
428+
@staticmethod
429+
def sample(args):
430430
"""
431431
Return a new live point proposed by random walking away from an
432432
existing live point.
@@ -449,11 +449,11 @@ def sample(cls, args):
449449
Value used to scale the provided axes.
450450
451451
prior_transform : function
452-
Function transforming a sample from the a unit cube to the parameter
453-
space of interest according to the prior.
452+
Function transforming a sample from the a unit cube to the
453+
parameter space of interest according to the prior.
454454
455455
loglikelihood : function
456-
Function returning ln(likelihood) given parameters as a 1-d
456+
Function returning ln(likelihood) given parameters as a 1-d
457457
`~numpy` array of length `ndim`.
458458
459459
kwargs : dict
@@ -498,8 +498,8 @@ def __init__(self, **kwargs):
498498
def tune(self, sampler_info, update=True):
499499
tune_slice(self, sampler_info, update=update)
500500

501-
@classmethod
502-
def sample(cls, args):
501+
@staticmethod
502+
def sample(args):
503503
"""
504504
Return a new live point proposed by a series of random slices
505505
away from an existing live point. Standard "Gibbs-like" implementation
@@ -510,8 +510,8 @@ def sample(cls, args):
510510
Parameters
511511
----------
512512
u : `~numpy.ndarray` with shape (ndim,)
513-
Position of the initial sample. **This is a copy of an existing live
514-
point.**
513+
Position of the initial sample. **This is a copy of an existing
514+
live point.**
515515
516516
loglstar : float
517517
Ln(likelihood) bound.
@@ -524,12 +524,12 @@ def sample(cls, args):
524524
Value used to scale the provided axes.
525525
526526
prior_transform : function
527-
Function transforming a sample from the a unit cube to the parameter
528-
space of interest according to the prior.
527+
Function transforming a sample from the a unit cube to the
528+
parameter space of interest according to the prior.
529529
530530
loglikelihood : function
531-
Function returning ln(likelihood) given parameters as a 1-d `~numpy`
532-
array of length `ndim`.
531+
Function returning ln(likelihood) given parameters as a 1-d
532+
`~numpy` array of length `ndim`.
533533
534534
kwargs : dict
535535
A dictionary of additional method-specific parameters.
@@ -571,8 +571,8 @@ def sample(cls, args):
571571

572572
# Modifying axes and computing lengths.
573573
axes = scale * axes.T # scale based on past tuning
574-
# Note we are transposing as axes[:,i] corresponds to i-th principal axis
575-
# of the ellipsoid
574+
# Note we are transposing as axes[:,i] corresponds to i-th principal
575+
# axis of the ellipsoid
576576
expansion_warning_set = False
577577
# Slice sampling loop.
578578
for _ in range(slices):
@@ -623,8 +623,8 @@ def __init__(self, **kwargs):
623623
def tune(self, sampler_info, update=True):
624624
tune_slice(self, sampler_info, update=update)
625625

626-
@classmethod
627-
def sample(cls, args):
626+
@staticmethod
627+
def sample(args):
628628
"""
629629
Return a new live point proposed by a series of random slices
630630
away from an existing live point. Standard "random" implementation
@@ -647,12 +647,12 @@ def sample(cls, args):
647647
Value used to scale the provided axes.
648648
649649
prior_transform : function
650-
Function transforming a sample from the a unit cube to the parameter
651-
space of interest according to the prior.
650+
Function transforming a sample from the a unit cube to the
651+
parameter space of interest according to the prior.
652652
653653
loglikelihood : function
654-
Function returning ln(likelihood) given parameters as a 1-d `~numpy`
655-
array of length `ndim`.
654+
Function returning ln(likelihood) given parameters as a 1-d
655+
`~numpy` array of length `ndim`.
656656
657657
kwargs : dict
658658
A dictionary of additional method-specific parameters.

0 commit comments

Comments
 (0)