Author: Johannes Buchner (C) 2012-2013
This code allows likelihood functions written in R (https://www.r-project.org) to be used by MultiNest.
The main program will connect to R using Rserve. It will run MultiNest, and for each point evaluation call the user-defined R callback function.
You need MultiNest.
Download it (e.g. from https://github.com/JohannesBuchner/MultiNest)
Make sure libmultinest.so is in your library path if it is not already:
$ export LD_LIBRARY_PATH=/my/path/to/MultiNest/
Warning
If you do not do this, you will see this error:
./rbridge: error while loading shared libraries: libmultinest.so: cannot open shared object file: No such file or directory
Download this package (latest at https://github.com/JohannesBuchner/RMultiNest), and extract it into the MultiNest directory.
Hint
Quick installation:
$ R --no-save > install.packages("Rserve") > quit() $ make rbridge test
If that doesn't go through smoothly, follow the manual steps 2-6.
Please report issues at https://github.com/JohannesBuchner/RMultiNest/issues
Otherwise, follow these manual steps.
Download Rserve (the tar file, Rserve_xxxx.tar.gz) from https://www.rforge.net/Rserve/ and extract it into this directory. You should now have:
$ ls Makefile README.rst multinest.h rbridge.cc Rserve/
Configure Rserve:
$ ./Rserve/configure
Configure and build the Rserve C++ client (in Rserve/clients/cxx/):
$ cd Rserve/clients/cxx/ $ ./configure && make Rconnection.o $ cd ../../../
Run make to compile Rbridge:
$ make
In R, install RServe using the instructions on the website. In short:
$ R > install.packages("Rserve")
The "runtest.sh" script runs the steps below for testing whether the installation worked. But you probably want to understand how to run your own code, so follow these steps.
Write log likelihood function in a R file (has to be called "log_likelihood"), and a prior transformation (has to be called "prior")
test.r:
prior <- function(cube) cube log_likelihood <- function(params) { print (params); 0 }
This is an example flat log_likelihood, and a flat prior.
Write a config file that tells which file to load
conf.rs:
source test.r
Run Rserve
$ R > library(Rserve) # you installed this package before using install.packages > Rserve(args=c("--RS-conf", "conf.rs", "--no-save"))
run ./rbridge in shell
$ ./rbridge
This will connect to R using Rserve, and call R through that for each point evaluation.
Finally, terminate Rserve
$ killall Rserve-bin.so
Well, you should now have the MultiNest output files lying there. You can learn to understand them by reading the MultiNest README (https://github.com/JohannesBuchner/MultiNest/blob/master/README).
You can either use pymultinest to plot and analyse them, or write your own routines in R.