Skip to content

How to use NS

Remco Bouckaert edited this page Sep 10, 2019 · 6 revisions

Nested sampling

  1. Create an XML file in BEAUti with an MCMC analysis

  2. Open the XML file in a text editor

  3. Replace the <run line that says something like

    < run id="mcmc" spec="MCMC" chainLength="100000000">

with

<run id="mcmc" spec="beast.gss.NS" chainLength="20000" particleCount="1" subChainLength="5000" epsilon="1e-12">

Here

  • particleCount = number of particles (also known as active points).
  • subChainLength = length of MCMC chain used to generate a new point.
  • chainLength = maximum number of newly generated points.
  • epsilon = used in stopping criterion. Lower means a higher accuracy in estimating the marginal likelihood, but the run will take a longer time to stop.

Save the XML and you should be able to run with BEAST. The estimates for marginal likelihood and standard deviation will be printed on the screen output.

Multi threaded nested sampling

Use

<run id="mcmc" spec="beast.gss.MultiThreadedNS" threads="4" chainLength="20000" particleCount="1" subChainLength="5000" epsilon="1e-12">

Apart from the parameters for nested sampling, there is a "threads" attribute that allow you to specify the number of threads. All other parameters apply to each individual thread, so with 4 threads and 1 particles there are a total of 4 particles.

Getting Multi threaded nested sampling estimates

Probably the best way to think of an n-thread MultiThreadedNS analysis is as if they were n individual NS analyses. At the end of a MultiThreaded NS analysis, SDs will be reported that are the SD estimates for the individual threads, so you should have 4 estimates reported with 4 threads.

The individual SD estimates have relative high variance, so to get a better estimate of the SD it is better to include all 4 runs than just a single estimate.

You can do this by running the NSLogAnalyser app that is part of the NS package, like so:

/path/to/applauncher NSLogAnalyser -N 1 -noposterior -log 0tracelog.log 1tracelog.log 2tracelog.log 3tracelog.log

of the shorter

/path/to/applauncher NSLogAnalyser -N 1 -noposterior -log ?tracelog.log

where "-N 1” indicates there is 1 particle per thread, and “?tracelog.log” assumes your log file is called “tracelog.log”. MultiThreadedNS will create one trace log file for each thread called “0tracelog.log”, “1tracelog.log”, etc. so you want to include all of these.

ML and SD estimates will be reported based on all the MultiThreadedNS runs.

Posterior sample

If you are interested in the posterior samples, you need an "NSLogger" for the tracelog. For this, you replace

<logger id="tracelog" ...

with

<logger id="tracelog" spec="NSLogger" ...

To post-process the file and get estimates for quantities of interest, you can use the NSLogAnalyser. The easiest way to start the analyser is by starting BEAUti, select menu File/Launch Apps, and a window pops up where you can choose the "NSLogAnalyser" icon to launch.