-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
69 lines (59 loc) · 1.82 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""
Copyright (C) 2016 by Tsubasa Hirakawa
"""
import sys
import numpy as np
import matplotlib.pyplot as plt
import dirichletParticleFilter as dpf
if __name__ == '__main__':
# import observation file and IPR file as numpy array
observations = np.loadtxt("obs.csv", delimiter=',')
confidence = np.loadtxt("confidence.csv", delimiter=',')
# compare data length and dimension
dimension = observations.shape[1]
data_length = observations.shape[0]
IPR_length = confidence.shape[0]
if data_length != IPR_length:
print "error: data length is different !"
sys.exit(-1)
# initialize DPF by initial observation
pf = dpf.DPF(theta=100, gamma=1, nPar=100)
ddpf = dpf.DDPF(theta=100, gamma=1, nPar=100)
pf.initialize(observations[0, :])
ddpf.initialize(observations[0, :])
# print parameters of DPF and DDPF
pf.print_parameters()
ddpf.print_parameters()
# smoothing
dpf_res = observations.copy()
ddpf_res = observations.copy()
for i in range(data_length):
# update
pf.update(observations[i, :])
ddpf.update(observations[i, :], confidence[i])
# parameter estimation
pf.estimateParameter()
ddpf.estimateParameter()
# compute mode
dpf_res[i, :] = pf.mode()
ddpf_res[i, :] = ddpf.mode()
# plot
plt.subplot(4,1,1)
plt.plot(observations)
plt.ylim(0, 1)
plt.title("observation")
plt.subplot(4,1,2)
plt.plot(dpf_res)
plt.ylim(0, 1)
plt.title("dirichlet particle filter")
plt.subplot(4,1,3)
plt.plot(ddpf_res)
plt.ylim(0, 1)
plt.title("defocus-aware dirichlet particle filter")
plt.subplot(4,1,4)
plt.plot(confidence)
plt.title("confidence values")
plt.tight_layout()
plt.show()