Implementation of the Stretch Move

21 views
Skip to first unread message

Noemi Manara

unread,
Nov 23, 2022, 5:50:36 AM11/23/22
to emcee users
Hi everyone,

I have a doubt about the implementation of the stretch move: in both Goodman & Weare (2010) and Foreman-Mackey et al. (2013) the density distribution g(z) of the scaling variable Z is chosen as proportional to 1/sqrt(z) with z in the range [1/a, a], with a an arbitrary constant, by default set to 2. 

From what I understand, the sampling of this distribution is implemented in line 30 of "emcee/src/emcee/moves/stretch.py" :

zz = ((self.a - 1.0) * random.rand(Ns) + 1) ** 2.0 / self.a

where the random variable is the z of the papers.

I have a hard time figuring out how to map this expression to one proportional to 1/sqrt(z), even looking at the following lines (31-33), where nothing else seems to happen to the variable zz before the actual move proposal:

factors = (ndim - 1.0) * np.log(zz)
rint = random.randint(Nc, size=(Ns,))
return c[rint] - (c[rint] - s) * zz[:, None], factors


Wouldn't the following edit of line 30 be more consistent with the distribution discussed in the papers? 
Z = random.uniform(1.0/self.a, self.a, Ns)
zz = 1.0 / np.sqrt(Z)


Thank you in advance, any help would be highly appreciated!
Noemi Manara

Dan Foreman-Mackey

unread,
Nov 23, 2022, 10:05:42 PM11/23/22
to Noemi Manara, emcee users
Here's a notebook showing how you can derive and check this expression: https://gist.github.com/dfm/ed84d7aa9d039d95c42dd105ef5fae6e
Hope this helps!
Dan

--
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/82e0a9b3-a52a-489a-8298-7f31b5aa570bn%40googlegroups.com.


--
Dan Foreman-Mackey
Research Scientist
Flatiron Institute

Noemi Manara

unread,
Nov 24, 2022, 8:29:23 AM11/24/22
to Dan Foreman-Mackey, emcee users
Now everything is clear to me, thank you very much!

Noemi
--
Noemi Manara

Junior Software Developer, Intern
Akamas
email noemi.manara@akamas.io
Free Trial
Reply all
Reply to author
Forward
0 new messages