dfm / emcee

The Python ensemble sampling toolkit for affine-invariant MCMC
https://emcee.readthedocs.io
MIT License
1.47k stars 430 forks source link

Best parameter set at each iteration #89

Closed nmearl closed 10 years ago

nmearl commented 10 years ago

Is there a way to access the current best parameter set while emcee is running? Either for it to be printed out, or accessed somehow?

ipashchenko commented 10 years ago

Do you mean maximum a posteriori probability (MAP) estimate of parameter? Or some credible interval? Anyway I think you can try incrementally save progress (see http://dan.iel.fm/emcee/current/user/advanced/#incrementally-saving-progress). At each iteration sample() method yields pos, lnprob, rstate. You need to save incrementally your positions pos to file (see example above) and your lnprob. Then you can trace what position has maximum lnprob using some external program/script (if you need MAP). Or each iteration (or each time interval) calculate credible interval from saved chains (using your own program/script - in this case you don't even need to save lnprob).

EDIT: In issue#93 Dan gave example how to store lnprob values at each step of sample() method at some container (list or array) and you can find max(container) at each step.

dfm commented 10 years ago

Like Ilya says, it'll look something like:

for pos, lnprob, state in sampler.sample(pos0, iterations=N):
    best = pos[np.argmax(lnprob), :]
    print(best)

Does this answer your question?

nmearl commented 10 years ago

It does; thank you guys very much!

Nicholas Earl Graduate Research Assistant San Diego State University

On Sat, Jan 18, 2014 at 9:54 AM, Dan Foreman-Mackey < notifications@github.com> wrote:

Like Ilya says, it'll look something like:

for pos, lnprob, state in sampler.sample(pos0, iterations=N): best = pos[np.argmax(lnprob), :] print(best)

Does this answer your question?

— Reply to this email directly or view it on GitHubhttps://github.com/dfm/emcee/issues/89#issuecomment-32687978 .