Walkers getting stuck outside uniform priors

224 views
Skip to first unread message

Nick Wogan

unread,
Apr 10, 2022, 11:14:34 AM4/10/22
to emcee users
Hi,

I'm using emcee to estimate atmospheric composition of a planet based on its spectrum. For these MCMC runs I use uniform priors for gas concentrations.In the prior I also say that sum(gas concentrations) > 1 has a zero probability (log(-infinity) probability). A sum larger than 1 would be unphysical.

In my experiments I find that many walkers often get stuck in part of the parameter space where sum(gas concentrations) > 1. I've attached an example of the walkers progress.

Looking for advice on how to prevent walkers from getting stuck in this unphysical region (sum(gas concetrations) > 1).

Thanks!
Nick
earth_refl_demo_snr8.5_14dim_walkers.png

Jo Bovy

unread,
Apr 10, 2022, 9:22:59 PM4/10/22
to Nick Wogan, emcee users
Hi Nick,

I think what you're doing is similar to sampling a simplex (the space of N numbers that sum to 1), but with the looser restriction that the sum has to be smaller than 1. I don't know whether there are standard ways of dealing with this, but there are standard changes of variables to sample the simplex. For example, I think stan uses the transformations presented in


I presented a similar transformation in appendix B of 


In your case, maybe you can re-parametrize your N concentration variables to be a) sum(concentrations) and b) the fractions concentration/sum(concentrations) and then transform a) such that it goes from -inf to inf (e.g., logit) and b) to be sampled as a simplex. Then you won't run into a hard boundary anywhere.

Best,

Jo


On Sun, Apr 10, 2022 at 9:20 PM Jo Bovy <bo...@astro.utoronto.ca> wrote:
Hi Nick,

I think what you're doing is similar to sampling a simplex (the space of N numbers that sum to 1), but with the looser restriction that the sum has to be smaller than 1. I don't know whether there are standard ways of dealing with this, but there are standard changes of variables to sample the simplex. For example, I think stan uses the transformations presented in


I presented a similar transformation in appendix B of 


In your case, maybe you can re-parametrize your N concentration variables to be a) sum(concentrations) and b) the fractions concentration/sum(concentrations) and then transform a) such that it goes from -inf to inf (e.g., logit) and b) to be sampled as a simplex. Then you won't run into a hard boundary anywhere.

Best,

Jo


--
Jo Bovy, University of Toronto


--
You received this message because you are subscribed to the Google Groups "emcee users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emcee-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emcee-users/ae5e3dfc-a4a0-48c4-a18b-321b76c3d07dn%40googlegroups.com.

Dan Foreman-Mackey

unread,
Apr 10, 2022, 9:48:06 PM4/10/22
to Jo Bovy, Nick Wogan, emcee users
Great suggestions, Jo! In my experience, these kinds of transformations tend to be less important for emcee than they are for Stan, but still can be super helpful. 

Nick: if you truly are returning -np.inf from your logprob when the condition is not satisfied, then the walkers won't ever move there, so I expect the issue isn't actually what you think. I'll email some suggestions off the list so we don't add too much noise. 



--
Dan Foreman-Mackey
Associate Research Scientist
Flatiron Institute

Nick Wogan

unread,
Apr 11, 2022, 8:49:55 AM4/11/22
to emcee users
Not sure if my previous message to Jo isn't showing up. I might resend it here in a bit. 

Dan, I am returning -np.inf from my logprob. I guess the walkers are not ever moving outside of the uniform priors. But they get in a position where every move they attempt is outside of the priors. Thanks for any feedback you give via Email!

Nick

Nick Wogan

unread,
Apr 11, 2022, 8:50:38 AM4/11/22
to emcee users
Response to Jo,

This is extremely helpful. Thanks so much!

I think what you are saying makes sense. I'll have to read Appendix B in your paper, and work through it a bit. But this overall seems like the right direction to take.

I'll report back to this thread once I have worked through the problem, and have a good understanding of it.

Thanks again,
Nick

Nick Wogan

unread,
Apr 11, 2022, 9:51:41 AM4/11/22
to emcee users
Jo,

In your paper, Eq B2, says

y_i = logit(x_i) - logit(X_N)

Where X_N = [\frac{N-1}{N}, \frac{N-2}{N-1}, ..., \frac{1}{2}]

I am confused by B2, because X_N is a vector of length N-1, and x_i and y_i are scalars in vectors that are length N.

Can you clarify X_N in B2?

Nick

Jo Bovy

unread,
Apr 11, 2022, 10:10:33 AM4/11/22
to Nick Wogan, emcee users
Hi Nick,

x_i in eq. (B1) is also a vector of length N-1 (that is, you only compute it for the first N-1 indices). My full code implementing everything in that appendix is here


that should hopefully clarify everything (note that variables have different names).

I do agree with Dan that just returning -inf should allow the algorithm to work without the simplex transformation, I've done this many times. Given that the simplex is convex, for every proposal step, there should be many possibilities that return a valid set of concentrations. However, because the stretch move extends out to twice the distance between points, I guess that's where your chains go into territory that they shouldn't. Maybe you can try fiddling with the 'a' parameter in the stretch move, making it smaller so there is less overshooting into -inf territory? Others on this list might be able to comment on whether this is a good idea or not, but I think it's at least technically allowed.

Best,

Jo

Nick Wogan

unread,
Apr 11, 2022, 12:59:19 PM4/11/22
to emcee users
Jo,

I tried several `a` parameters between 1 and 2. Resulted in similar behavior. MCMC started fine, but then "flatlined", where all moves led to sum(mixing ratios) > 1 regions of parameter space.

Your original suggestion of a variable transformation sounds promising. But would be happy to hear if there is an easier solution.

Nick

Dan Foreman-Mackey

unread,
Apr 11, 2022, 1:57:39 PM4/11/22
to emcee users
Hi all,
For those following along, Nick and I chatted off-list a bit and it looks like there was a separate bug that was causing the prior not to be enforced, so these coordinate transforms may not actually be necessary after all.
Dan
Reply all
Reply to author
Forward
0 new messages