forked from JohannesBuchner/PyMultiNest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pymultinest_demo_minimal.py
38 lines (27 loc) · 964 Bytes
/
pymultinest_demo_minimal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import absolute_import, unicode_literals, print_function
import pymultinest
import math, os
if not os.path.exists("chains"): os.mkdir("chains")
# This "old" api may be a little bit faster and suitable for likelihoods
# written in C (via ctypes).
# our probability functions
# Taken from the eggbox problem.
# Take a look at pymultinest_demo.py for more pythonic convenience
def myprior(cube, ndim, nparams):
for i in range(ndim):
cube[i] = cube[i] * 10 * math.pi
def myloglike(cube, ndim, nparams):
chi = 1.
for i in range(ndim):
chi *= math.cos(cube[i] / 2.)
return math.pow(2. + chi, 5)
# number of dimensions our problem has
parameters = ["x", "y"]
n_params = len(parameters)
# run MultiNest
pymultinest.run(myloglike, myprior, n_params,
resume = True, verbose = True)
# run
# $ multinest_marginals.py chains/1-
# which will produce pretty marginal pdf plots
# for code to analyse the results, and make plots see full demo