Search code examples
algorithmbayesianjags

Random Permutations for MCMC


I'm new to JAGS (Just Another Gibbs Sampler) and I was wondering if it is possible to extend it to sample from a space of random permutations?

The reason I ask is that I came across this tutorial on extending JAGS, and one fo the required functions "logDensity" has a required input as a double however to work with permutations I would need to input a double.

http://www.cidlab.com/prints/wabersich2013extending.pdf

Also I don't have to work with just JAGS, if anyone has another suggestion that would work I would appreciate any input.


Solution

  • If the permutations are over 18 or fewer elements, you can represent a permutation as a double by computing its lexicographic rank. (It's possible to squeeze out a couple more elements by computing the rank as a 64-bit integer and then reinterpreting the bits as a double.)