CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download
Project: test
Views: 91872
1
# -*- coding: utf-8 -*-
2
"""
3
Created on Sat May 2 09:46:06 2015
4
5
@author: Roger
6
"""
7
8
import math
9
import numpy as np
10
from numpy.random import uniform
11
from numpy.random import randn
12
import scipy.stats
13
import matplotlib.pyplot as plt
14
import random
15
16
17
18
19
20
21
22
23
24
25
26
27
if __name__ == '__main__':
28
N = 2000
29
pf = ParticleFilter(N, 100, 100)
30
#pf.particles[:,2] = np.random.randn(pf.N)*np.radians(10) + np.radians(45)
31
32
z = np.array([20, 20])
33
#pf.create_particles(mean=z, variance=40)
34
35
mu0 = np.array([0., 0.])
36
plot(pf, weights=False)
37
38
39
fig = plt.gcf()
40
#fig.show()
41
#fig.canvas.draw()
42
#plt.ioff()
43
44
for x in range(10):
45
46
z[0] = x+1 + randn()*0.3
47
z[1] = x+1 + randn()*0.3
48
49
50
pf.predict((1,1), (0.2, 0.2))
51
pf.weight(z=z, var=.8)
52
neff = pf.neff()
53
54
print('neff', neff)
55
if neff < N/2 or N <= 2000:
56
pf.resample()
57
mu, var = pf.estimate()
58
if x == 0:
59
mu0 = mu
60
#print(mu - z)
61
#print(var)
62
63
plot(pf, weights=True)
64
#plt.plot(z[0], z[1], marker='v', c='r', ms=10)
65
plt.plot(x+1, x+1, marker='*', c='r', ms=10)
66
plt.scatter(mu[0], mu[1], c='g', s=100)#,
67
#s=min(500, abs((1./np.sum(var)))*20), alpha=0.5)
68
plt.plot([0,100], [0,100])
69
plt.tight_layout()
70
plt.pause(.002)
71
72
#fig.canvas.draw()
73
74
#pf.assign_speed_by_gaussian(1, 1.5)
75
#pf.move(h=[1,1], v=1.4, t=1)
76
#pf.control(mu-mu0)
77
mu0 = mu
78
79
plt.ion()
80
81
82
83
84
85
86