Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
Project: test
Views: 91872# -*- coding: utf-8 -*-1"""2Created on Sat May 2 09:46:06 201534@author: Roger5"""67import math8import numpy as np9from numpy.random import uniform10from numpy.random import randn11import scipy.stats12import matplotlib.pyplot as plt13import random14151617181920212223242526if __name__ == '__main__':27N = 200028pf = ParticleFilter(N, 100, 100)29#pf.particles[:,2] = np.random.randn(pf.N)*np.radians(10) + np.radians(45)3031z = np.array([20, 20])32#pf.create_particles(mean=z, variance=40)3334mu0 = np.array([0., 0.])35plot(pf, weights=False)363738fig = plt.gcf()39#fig.show()40#fig.canvas.draw()41#plt.ioff()4243for x in range(10):4445z[0] = x+1 + randn()*0.346z[1] = x+1 + randn()*0.3474849pf.predict((1,1), (0.2, 0.2))50pf.weight(z=z, var=.8)51neff = pf.neff()5253print('neff', neff)54if neff < N/2 or N <= 2000:55pf.resample()56mu, var = pf.estimate()57if x == 0:58mu0 = mu59#print(mu - z)60#print(var)6162plot(pf, weights=True)63#plt.plot(z[0], z[1], marker='v', c='r', ms=10)64plt.plot(x+1, x+1, marker='*', c='r', ms=10)65plt.scatter(mu[0], mu[1], c='g', s=100)#,66#s=min(500, abs((1./np.sum(var)))*20), alpha=0.5)67plt.plot([0,100], [0,100])68plt.tight_layout()69plt.pause(.002)7071#fig.canvas.draw()7273#pf.assign_speed_by_gaussian(1, 1.5)74#pf.move(h=[1,1], v=1.4, t=1)75#pf.control(mu-mu0)76mu0 = mu7778plt.ion()7980818283848586