-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_lognormal.py
37 lines (31 loc) · 1023 Bytes
/
test_lognormal.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
37
"""
Test the step method when trying to sample a lognormal random variable.
"""
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
import pysmc
import pymc
import math
import matplotlib.pyplot as plt
import numpy as np
def make_model():
#c = pymc.Container([pymc.Lognormal('x', mu=math.log(1.), tau=1.),
# pymc.Lognormal('z', mu=math.log(2.), tau=3.)])
#x = pymc.Exponential('x', beta=0.1)
x = pymc.Lognormal('x', mu=np.array([math.log(1.), math.log(2.)]),
tau=np.array([1., 3.]))
@pymc.stochastic(observed=True)
def y(value=0.001, x=x):
return pymc.lognormal_like(value, mu=x[0], tau=1.)
return locals()
if __name__ == '__main__':
m = make_model()
mcmc = pymc.MCMC(m)
mcmc.assign_step_methods()
print(mcmc.step_method_dict)
mcmc.sample(100000, thin=100, burn=10000)
s = mcmc.step_method_dict[m['x']][0]
print('\n', s.accepted / (s.accepted + s.rejected))
pymc.Matplot.plot(mcmc)
plt.show()