# Code

To get the ball rolling I figure it would be worthwhile to write a simple R script to implement nested sampling with MCMC moves for exploring the likelihood-constrained prior as benchmark for this comparison exercise. Ideally the prior and likelihood should be plug-in functions with minimal requirements such that those not familiar with nested sampling can easily get it up & running on their favourite toy problem. Eventually I suppose the same will have to be done for SMC; or alternatively, an SMC advocate may decide to contribute his/her go-to SMC script for this purpose.

I have created a github repository to store the code produced here, ~~though at present it contains only a readme file!~~ *which now contains a barely debugged R script I hacked together, along with a more refined Python script contributed by Brendon Brewer.*

https://github.com/drewancameron/NSwMCMC

Comment: In hacking together this nested sampling script (a script I’ve probably written from scratch on about five different occasions) I am reminded just how similar nested sampling is to SMC: that is, the live particle population is evolved through the sequence of target densities for a non-decreasing sequence, the only complexity being that the successive is chosen as the minimum of the likelihoods amongst particles in the th population. The need for an (e.g.) MCMC algorithm to find a replacement live particle is then no different to the need for the same to avoid particle degeneracy in an SMC / particle filtering code.

### Like this:

Like Loading...

I have this in Python. Is that of any use?

Definitely; email it across & I’ll make a quick hack to convert it to R. (Of course, there’s no reason why we can’t work in multiple languages, but R is my default.)