-
Notifications
You must be signed in to change notification settings - Fork 26
Rollup: New sampler API -> support for emcee #68
Conversation
Hello @cdcapano! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on August 04, 2018 at 19:11 Hours UTC |
6038ba5
to
e871582
Compare
I think this is ready to be merged onto the I tested this with emcee and on the normal2D analytic model, gw150914, and an injection. I haven't updated the plotting code yet, so I haven't checked the distributions. I've just checked that the executable runs ok and produces an output file that looks ok. For the analytic test with running for a set number of iterations, the ini file looks like:
To run until a desired number of effective samples is achieved, the ini file looks like:
(prior and model sections are the same). Both of these run with:
If you approve, I'll squash and merge this onto the project branch, then fill out a new PR to track the project branch to master (apparently you can't start a PR until there is at least one difference). After that, I'll work on updating the plotting codes, and then add back support for |
@vivienr poke |
@vivienr pokity poke |
the travis failure is unrelated to this MR, correct? |
No, the travis failures are due to this MR, but that's because I haven't updated the unit tests yet. That's why this is a pull request on to the project branch, not master. I figure we can fix up all the unit tests on a future PR to the project branch (which would be needed before the project could be merged on to master). The main point of this PR is to provide a checkpoint, so subsequent changes to the project aren't a single massive diff. |
@vivienr poke |
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 good !
This introduces the new sampler API, and includes all changes such that emcee works with it. The other samplers are not supported yet, so this will break using them. A summary of the changes:
BaseSampler
has been turned into an abstract base class, with only methods required of all samplers defined. All future samplers (including any nested samplers) should inherit from this.BaseMCMC
class that adds methods unique to all MCMC samplers. It fulfills some of the methods required byBaseSampler
, but also introduces some abstract methods that all MCMC samplers need to implement.EmceeEnsembleSampler
inherits fromMCMCAutocorrSupport, BaseMCMC, BaseSampler
(in that order).[sampler]
section in the config file, instead of by options on the command line.FieldArray
s, other dictionaries, and yet others structure arrays. Now, all arrays of samples are passed between sampler methods as dictionaries of arrays. Only when samples are read from a file usingread_samples
are the results wrapped with aFieldArray
.BaseInferenceFile
that implements common methods for reading/writing for all samplers. Things specific to MCMCs have been moved toMCMCIO
. Finally, there is an IO class for each sampler that inherits from these base classes. For example, foremcee
there isEmceeFile
which inherits fromMCMCIO, BaseInferenceFile
.io
, which is the IO class that that sampler uses. For example,EmceeEnsembleSampler.io = EmceeFile
. This is used for checkpointing, and is the type of file that gets written bygwin
. Ingwin.io
there is a convenience function,loadfile
, that will check what kind of file a file is, then load it with the appropriate IO class.PosteriorFile
which inherits fromBaseInferenceFile
that will be used for storing 1D arrays of posterior samples. All IO classes will have a method that allows them to write their contents to such a file.MCMCBurnInTests
class in which each of the burn-in tests are instance methods. It is initialized from the config file. An instance of it is saved to the sampler'sburn_in
attribute. This is called at each checkpoint by theBaseMCMC
to test for burn-in.[sampler-burn_in]
section you must provide aburn-in-test = <stuff>
string. The<stuff>
gets read by the class. For example, you could have justburn-in-test = max_posterior
in which case only themax_posterior
test will be applied. Or you could haveburn-in-test = max_posterior & nacl
in which the sampler is not considered burned-in until both themax_posterior
test and thenacl
test are satisfied. If you hadmax_posterior | nacl
, then the sampler is considered burned-in if either test is satisfied. More complicated chains are supported, such as(max_posterior | nacl) & ks_test
, etc.sampler_info/burn_in
.BaseInferenceFile
hasthin_start
,thin_interval
, andthin_end
attributes. These define what samples should be loaded by default from the file. If they are not specified, then they default to0, 1, None
, which loads all samples. This separates what samples should be loaded from the burn-in iteration and acl, which are unique to MCMC samplers. (Granted, Nested samplers will probably never use these attributes). This will allow the posterior file to still have metadata about when the sampler burned in.