forked from JohannesBuchner/PyMultiNest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpymultinest_demo.py
More file actions
33 lines (25 loc) · 851 Bytes
/
pymultinest_demo.py
File metadata and controls
33 lines (25 loc) · 851 Bytes
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
#!/usr/bin/env python
from __future__ import absolute_import, unicode_literals, print_function
import numpy
from numpy import pi, cos
from pymultinest.solve import solve
import os
if not os.path.exists("chains"): os.mkdir("chains")
# probability function, taken from the eggbox problem.
def myprior(cube):
return cube * 10 * pi
def myloglike(cube):
chi = (cos(cube / 2.)).prod()
return (2. + chi)**5
# number of dimensions our problem has
parameters = ["x", "y"]
n_params = len(parameters)
# run MultiNest
result = solve(LogLikelihood=myloglike, Prior=myprior,
n_dims=n_params, outputfiles_basename="chains/3-")
print()
print('evidence: %(logZ).1f +- %(logZerr).1f' % result)
print()
print('parameter values:')
for name, col in zip(parameters, result['samples'].transpose()):
print('%15s : %.3f +- %.3f' % (name, col.mean(), col.std()))