joshspeagle / dynesty

Dynamic Nested Sampling package for computing Bayesian posteriors and evidences
https://dynesty.readthedocs.io/
MIT License
347 stars 76 forks source link

Refactor iterators #307

Closed segasai closed 3 years ago

segasai commented 3 years ago

Currently various sampling iterators in the code return tuples yield (idx, ustar, vstar, loglstar, logvol, logwt, logz, logzvar, h, 1, point_it, boundidx, bounditer, self.eff, delta_logz) which are then unpacked (worst, ustar, vstar, loglstar, logvol, logwt, logz, logzvar, h, nc, worst_it, boundidx, bounditer, eff, delta_logz) = results which is error-prone and pollutes the namespace with unused/confusing variables.

I think we need to do yield namedtuples and extract from them just what we need.

In [7]: NT=collections.namedtuple('R',['worst','ustar'])

In [8]: x=NT(worst=33,ustar=[3,5])

In [9]: x.worst
Out[9]: 33

In [10]: x.ustar
Out[10]: [3, 5]
joshspeagle commented 3 years ago

100% agreed this would make things a lot cleaner.