-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtester30.py
More file actions
56 lines (41 loc) · 1.25 KB
/
tester30.py
File metadata and controls
56 lines (41 loc) · 1.25 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from srfpython.standalone.display import *
from metropolis2 import *
"""
test Metropolis algorithm in 1D
"""
if True:
l = LogGaussND(vmeans=[1.], vuncs=[1.25],
vinfs=[-0.1], vsups=[1.8],
k=10000.0, nanbehavior=0)
logRHOM = l
elif 1:
l = LogUniND(vinfs=[-0.1], vsups=[1.],
k=30.0, nanbehavior=0)
logRHOM = l
x = np.linspace(-.5, 3., 1000)
y = np.exp([logRHOM([xx]) for xx in x])
A = np.sum(y * (x[1] - x[0]))
gca().plot(x, y / A)
def G(model):
return np.array([0.])
def logRHOD(data):
return 0.
M0 = np.array([0.])
MSTD = np.array([20.])
start = time.time()
models, _, weights, _ = \
metropolis(M0, MSTD, G, 1,
logRHOD, logRHOM,
nkeep = 50000,
HL = 100,
IK0 = 0.65,
adjustspeed=0.5,
MPMIN = .1,
MPMAX = 10.0)
print("total time %f" % (time.time() -start))
models = models.repeat(weights, axis = 0)
hist, bin_edges = np.histogram(models[:, 0], bins = 30, density=True)
for mid, width, height in zip(.5 * (bin_edges[:-1] + bin_edges[1:]), bin_edges[1:]-bin_edges[:-1], hist):
gca().bar(mid, height, width, bottom=0, align='center', color = "k", alpha = .4)
gca().set_xlim(-.5, 2.)
showme()