forked from elfi-dev/elfi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMA2_bolfirun.py
52 lines (39 loc) · 1.37 KB
/
MA2_bolfirun.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
sys.path.append("/Users/nicholascroucher/Documents/frequencyDependence/model_fitting/elfi")
import elfi
from elfi.examples import ma2
import matplotlib.pyplot as plt
import numpy as np
# load the model from elfi.examples
model = ma2.get_model(n_obs=10, true_params=[-0.5,0.1])
# setup and run rejection sampling
bolfi = elfi.BOLFI(model['d'], batch_size=1, initial_evidence=5,
update_interval=5, bounds={'t1':(-2,2),'t2':(-1,1)},
acq_noise_var=[0.1,0.1])
result = bolfi.fit(n_evidence=300)
#### Henri
#result_BOLFI = bolfi.sample(n_samples = 10000, algorithm = 'smc')
#samples = np.append(result_BOLFI.samples['t1'].reshape(-1,1),
# result_BOLFI.samples['t2'].reshape(-1,1),axis=1)
#
#plt.hist2d(samples[:,0],samples[:,1],(50,50),cmap=plt.cm.jet)
#plt.show()
#print(samples)
#### NJC
test_out = result.logpdf(np.asarray([0.2,0.2]))
print("Posterior: " + str(test_out))
#samples = np.append(result_BOLFI.samples['t1'].reshape(-1,1),
# result_BOLFI.samples['t2'].reshape(-1,1),axis=1)
# plt.plot(result_BOLFI.samples['t1'].reshape(-1,1))
# plt.show()
# sample(self,
# n_samples=,
# warmup=None,
# n_chains=4,
# threshold=None,
# initials=None,
# algorithm='nuts',
# n_evidence=None,
# **kwargs):
# Minimizer
# print(bolfi.extract_result().x_min)