Joe Romano and myself have written an implementation of MultiNest in Matlab, which (after a while of sitting just on our computers) is now available as a Beta release from the MultiNest repository.
This can be used to perform evidence calculation and posterior parameter estimation using nested sampling for a given dataset, likelihood function and model function. The release includes examples of how to set up these functions for use with the nested sampling routine. The code can use the MultiNest algorithm (implementing the method in “Algorithm 1” of Section 5.2 and Section 5.3 of Feroz, Hobson & Bridges, MNRAS, 398, pp. 1601-1614, 2009, but not the extra steps in Sections 5.4 through 5.7) to draw samples from the prior volume. Or, it can use an MCMC method to draw new samples (based on the method proposed in Veitch & Vecchio, PRD, 81, 062003, 2010), where the proposal is a Student-t distribution with 2 degrees of freedom defined by the covariance of the current “live points” (and also using differential evolution 10% of the time to aid hopping between modes in the likelihood).
These functions haven’t undergone much testing or been optimsed for efficiency, so if you use them and have any feedback please let me know.
The code has a license allowing free academic use and modification.
Update (24/03/15): I have now placed the development version of the code in github, so others can easily download it and contribute to its development.
was wondering if the author had a plan to implement the extra features in the fortran 90 version.
Thanks!
Yun
Hi Yun,
I don’t have any plan to implement the extra features in the main fortran version of MultiNest. I’ve only done minimal amounts of coding in fortran and don’t have the time to add this.
Cheers,
Matt
Thanks for the prompt answer Matt!
Best regards,
Yun
Hi,
I just downloaded your MATLAB implementation of multinest from CCForge. Running the examples with a non-zero MCMC steps parameter (that the examples request when first running it) seems to work all right, but if I enter zero (indicating that the program should use the sampling scheme from multinest), it fails with the errors:
Input number of iterations for MCMC sampling: (enter 0 for multinest sampling)
0
??? Error using ==> mldivide
Matrix dimensions must agree.
Error in ==> calc_ellipsoid at 56
invC = 1/C;
Error in ==> optimal_ellipsoids at 27
[B, invB, mu, VE, flag] = calc_ellipsoid(u, VS);
Error in ==> nested_sampler at 205
[Bs, mus, VEs, ns] = optimal_ellipsoids(livepoints, VS);
Error in ==> example_line_with_outliers_and_marginalization at 29
[logZ, nest_samples, post_samples] = nested_sampler(data, Nlive, Nmcmc, …
>>
—–
I added all three of the directories to my path so that all of the .m files can be seen by each script before I ran them.
If I go into the source code to this line in calc_ellipsoid, I uncomment the line that uses inv(C) and comment the line that uses 1/C:
% calculate inverse covariance matrix
invC = inv(C);
%invC = 1/C;
—
Then the program appears to run OK using the setting of 0 for MCMC steps.
Just FYI and hope any comments you can provide will be seen by others; I think actually MATLAB encourages use of 1/C for the inverse instead of inv, as you’ve done, but in this case it seems to fail for some reason.
David
Hi David,
Sorry for the slow response. Thanks very much for spotting this and contacting me. I’d not seen the problem before, but from the looks of it I think I changed from using
inv(C)
to1/C
at Matlab’s suggestion without properly testing that it works! Retesting withexample_sinusiod.m
and I see the same error as you.Looking at this again I suggest changing the
calc_ellipsiod.m
function to not outputinvB
at all, removing the variableinvC
from the code, changing the line:f = (u(i,:)-mu) * invC * (u(i,:)-mu)';
tof = ( (u(i,:)-mu) / C ) * (u(i,:)-mu)';
and removing the line defining
invB
.This also requires editing the
optimal_ellipsoids.m
function to removeinvB
from the call tocalc_ellipsiod
(it’s not actually used elsewhere in the function), and editing thesplit_ellipsiod.m
function to again removeinvB
from the two calls tocalc_ellipsiod
and then changing lines definingdu1
anddu2
to be:du1 = ( (u(i,:)-mu1) / B1 ) * (u(i,:)-mu1)';
and
du2 = ( (u(i,:)-mu2) / B2 ) * (u(i,:)-mu2)';
I’ll update the version on CCForge.
Cheers,
Matt
Hi,
I’ve downloaded the Matlab version of multinest, and I’m using it to analyse some neutron reflectivity data. I got it running very easily and it seems to run very smoothly, so thanks very much for this code!
I’m essentially using it to analyse some 1d (i.e. x-y) data fitted with a multiparameter model, and I’m getting very sensible posterior distributions out of it. What I would like to do though is to then plot the resulting fits with shaded 95% (or any other) probability regions shown around the best fit curves. Looking at the main multinest page, the package ‘superplot’ looks like it would do this, but that’s for the Python implementation, so I’m a bit stuck….
Have you got any functions that would calculate these regions, or at least suggest how I can proceed? So for example its says that Superplot will calculate these from “….Multinest output files”. If I could work out what the format of those is, then maybe I could format the Matlab output in a way that I can then feed through the Superplot calculation routines or something…. Anyway, any ideas as to what I might try would be most welcome…
Many thanks,
Arwel
Hi Arwel,
Thanks for your comments. Sorry for the extremely slow response. I hope you found out how to do what you were wanting elsewhere, but below’s an example of how I would go about calculating and plotting a confidence region (or credible interval). Note that this example produces a region that is the shortest region to bound the given interval and as such is not necessarily symmetric about the best fit value.
That method gets the interval directly from the samples, but you could get it from the cumulative probability distribution (from which you could get an interval symmetric about the best fit).
Ah thanks Matthew, that’s great.
Id does sound as though it’s the cumulative probability distribution I need. How can I get the cumulative distribution from the output of multinest??
Cheers,
Arwel
Here’s a method for getting a confidence interval from the cumulative probability distribution. Given posterior samples from the nested sampling code in the array
post
you can get the cumulative distribution for the first parameter with e.g.:That method has the probability interval centred around the point where 50% of the probability is on either side (the 0.5 in
lowrange
andhighrange
).Hope that helps.
Hi, I tried the Matlab version of MultiNest. Is there a reason why the egg-box example runs forever and do not finally converge? Also is there a way to calculate the error in the evidence as in the original MultiNest paper? Also how do you calculate number of likelihood evaluations? The number of iterations (displayed in the workspace) and number of rows of the posterior samples are different. Which one is the number of likelihood calls?