-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Elaborate NS run using a loop #644
base: master
Are you sure you want to change the base?
Conversation
sampler.run_nested(dlogz_init=dlogz, maxiter=maxiter, print_progress=print_progress) | ||
#sampler.run_nested(dlogz_init=dlogz, maxiter=maxiter) | ||
|
||
for results in sampler.sample_initial(dlogz=dlogz, maxiter=maxiter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would enumerate this and run a log message every few seconds/every few samples. @mreboud ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every few samples is probably simpler to implement.
python/eos/analysis.py
Outdated
@@ -607,7 +607,7 @@ def _prior_transform(self, u): | |||
return self._u_to_par(u) | |||
|
|||
|
|||
def sample_nested(self, bound='multi', nlive=250, dlogz=1.0, maxiter=None, seed=10, print_progress=True): | |||
def sample_nested(self, bound='multi', nlive=250, dlogz=1.0, maxiter=None, seed=10, print_progress=True, save_intermediate=False, base_directory='./', posterior=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a reasonable idea to begin with, but I do not like it very much. So far, the design was to separate the tasks from the lower-level operations. I think we should and can keep doing that.
I would suggest to use a yield_intermediate
keyword argument. Instead of using return sampler.results
once at the end, we rather yield sampler.results
periodically. The task can then run a for loop over this function and save the results itself.
The main change in the implementation right now is that the intermediate results are stored every few loop, specified by |
To tick some of the boxes in issue #573 off:
Regarding the last point, currently we use the same variables I also thought about adding something like this if
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very reasonable! Some comments inline.
for p in self.varied_parameters: | ||
eos.error(' - {n}: {v}'.format(n=p.name(), v=p.evaluate())) | ||
eos.error(f' - {p.name()}: {p.evaluate()}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the changes above are due to pyupgrade
and should be moved to a separate commit.
python/eos/analysis.py
Outdated
@@ -653,14 +653,55 @@ def sample_nested(self, bound='multi', nlive=250, dlogz=1.0, maxiter=None, seed= | |||
:type maxiter: int, optional | |||
:param seed: The seed used to initialize the Mersenne Twister pseudo-random number generator. | |||
:type seed: {None, int, array_like[ints], SeedSequence}, optional | |||
:param save_intermediate: If set to True, the intemediate dynesty sampler results are stored in each loop iteration. | |||
:type save_intermediate: bool, optional | |||
:param checkpoint_every: The number of seconds between checkpoints at which the intermediate dynesty sampler results are stored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the checkpointing. Not so sure that I like the naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about backup
and backup_frequency
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just a checkpoint_interval
(float, larger zero)? If None
, no intermediate results are saved.
python/eos/analysis.py
Outdated
sampler = dynesty.DynamicNestedSampler(self.log_likelihood, self._prior_transform, len(self.varied_parameters), bound=bound, nlive=nlive, rstate = np.random.Generator(np.random.MT19937(seed))) | ||
sampler.run_nested(dlogz_init=dlogz, maxiter=maxiter, print_progress=print_progress) | ||
return sampler.results | ||
#sampler.run_nested(dlogz_init=dlogz, maxiter=maxiter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs to be removed.
python/eos/tasks.py
Outdated
posterior_values = results.logwt - results.logz[-1] | ||
weights = _np.exp(posterior_values) | ||
eos.data.DynestyResults.create(os.path.join(base_directory, posterior, f'dynesty_results-{iter:04}'), analysis.varied_parameters, results) | ||
eos.data.ImportanceSamples.create(os.path.join(base_directory, posterior, f'samples-{iter:04}'), analysis.varied_parameters, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the labelling of the dynesty result by the iteration number. However, doing so for the samples will break backward compatibility with e.g. the plotting framework. Please undo this labelling for samples
.
For comparison I calculated the chi**2 values from
and using this branch:
I haven't yet spotted a significant difference to the dynesty version that would tell me where the difference comes from: https://github.com/joshspeagle/dynesty/blob/f59d963fad80301e5d28bc5a6e3718c467c1bf94/py/dynesty/dynamicsampler.py#L1824 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clean up line 176 of analysis_TEST.py? There is a missing sqrt, but sigma is not used anyway ...
Use a loop to run a nested sampler internally as outlined here: https://dynesty.readthedocs.io/en/stable/dynamic.html
This is related to one or several points from issue #573.