-
Notifications
You must be signed in to change notification settings - Fork 1
/
pftest.py
51 lines (34 loc) · 1.21 KB
/
pftest.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
0import numpy as np
import cPickle as pickle
from matplotlib import pylab
import likelihood
import util
import model
np.random.seed(0)
d = pickle.load(open('simulate.pickle'))
env = util.Environment((1.5, 2), (240, 320))
eo = likelihood.EvaluateObj(240, 320)
eo.set_params(10, 4, 2)
le = likelihood.LikelihoodEvaluator(env, eo)
model_inst = model.LinearModel(env, le)
PARTICLEN = 4000
for frameno in range(1, 300, 30):
print "frame", frameno
prior_states = model_inst.sample_latent_from_prior(PARTICLEN)
img = d['video'][frameno]
scores = np.zeros(PARTICLEN)
for si, state in enumerate(prior_states):
scores[si] = model_inst.score_obs(img, state)
score_sort_idx = np.argsort(scores)
scores_sorted = scores[score_sort_idx]
states_sorted = prior_states[score_sort_idx]
f = pylab.figure()
ax1 = f.add_subplot(1, 1, 1)
ax1.imshow(img, interpolation='nearest', origin='lower',
cmap = pylab.cm.gray)
for i in range(1, 10):
best_state = states_sorted[-i]
pix_x, pix_y = env.gc.real_to_image(best_state['x'], best_state['y'])
pylab.axhline(pix_y)
pylab.axvline(pix_x)
f.savefig('good_particles.%04d.png' % frameno)