diff --git a/code/DogSimulation.py b/code/DogSimulation.py index f846da2..daaa033 100644 --- a/code/DogSimulation.py +++ b/code/DogSimulation.py @@ -1,14 +1,24 @@ # -*- coding: utf-8 -*- -""" -Created on Sun May 11 13:21:39 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ -from __future__ import print_function, division +from __future__ import (absolute_import, division, print_function, + unicode_literals) + -from numpy.random import randn import math +from numpy.random import randn class DogSimulation(object): diff --git a/code/RobotLocalizationParticleFilter.py b/code/RobotLocalizationParticleFilter.py index 1a980d9..1bdcc7d 100644 --- a/code/RobotLocalizationParticleFilter.py +++ b/code/RobotLocalizationParticleFilter.py @@ -1,12 +1,23 @@ # -*- coding: utf-8 -*- -""" -Created on Sat Jun 27 19:45:45 2015 -@author: Roger +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import numpy as np -import numpy.random + from numpy.random import randn, random, uniform import scipy.stats diff --git a/code/adaptive_internal.py b/code/adaptive_internal.py index f8044eb..ec861dc 100644 --- a/code/adaptive_internal.py +++ b/code/adaptive_internal.py @@ -1,12 +1,23 @@ # -*- coding: utf-8 -*- -""" -Created on Tue Jun 30 19:48:21 2015 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ -import matplotlib.pyplot as plt +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import book_plots as bp +import matplotlib.pyplot as plt def plot_track_and_residuals(t, xs, z_xs, res): @@ -26,6 +37,3 @@ def plot_track_and_residuals(t, xs, z_xs, res): plt.ylabel('residual') plt.title('residuals') plt.show() - - - diff --git a/code/book_format.py b/code/book_format.py index 387b595..c9a0467 100644 --- a/code/book_format.py +++ b/code/book_format.py @@ -1,5 +1,20 @@ # -*- coding: utf-8 -*- +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. +""" + +from __future__ import (absolute_import, division, print_function, + unicode_literals) from contextlib import contextmanager from IPython.core.display import HTML diff --git a/code/book_plots.py b/code/book_plots.py index a0a06d7..4408bc9 100644 --- a/code/book_plots.py +++ b/code/book_plots.py @@ -1,9 +1,22 @@ # -*- coding: utf-8 -*- -""" -Created on Fri May 2 12:21:40 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ + + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import matplotlib.pyplot as plt import numpy as np @@ -133,7 +146,7 @@ def plot_track(xs, ys=None, label='Track', c='k', lw=2, **kwargs): plt.plot(xs, color=c, lw=lw, ls=':', label=label, **kwargs) -def plot_filter(xs, ys=None, c='#013afe', label='Filter', vars=None, **kwargs): +def plot_filter(xs, ys=None, c='#013afe', label='Filter', var=None, **kwargs): #def plot_filter(xs, ys=None, c='#6d904f', label='Filter', vars=None, **kwargs): @@ -143,12 +156,12 @@ def plot_filter(xs, ys=None, c='#013afe', label='Filter', vars=None, **kwargs): plt.plot(xs, ys, color=c, label=label, **kwargs) - if vars is None: + if var is None: return - print('here') - vars = np.asarray(vars) - std = np.sqrt(vars) + var = np.asarray(var) + + std = np.sqrt(var) std_top = ys+std std_btm = ys-std diff --git a/code/ekf_internal.py b/code/ekf_internal.py index 147a2d5..a5e9070 100644 --- a/code/ekf_internal.py +++ b/code/ekf_internal.py @@ -1,16 +1,27 @@ # -*- coding: utf-8 -*- -""" -Created on Fri Jul 18 23:23:08 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import book_plots as bp -from math import radians, sin, cos, sqrt, exp -import numpy.random as random -import matplotlib.pyplot as plt import filterpy.kalman as kf +from math import radians, sin, cos, sqrt, exp +import matplotlib.pyplot as plt import numpy as np +import numpy.random as random def ball_kf(x, y, omega, v0, dt, r=0.5, q=0.02): diff --git a/code/gaussian_internal.py b/code/gaussian_internal.py index 77a5c25..b87682f 100644 --- a/code/gaussian_internal.py +++ b/code/gaussian_internal.py @@ -1,15 +1,25 @@ # -*- coding: utf-8 -*- -""" -Created on Thu May 8 23:16:31 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import filterpy.stats as stats import math -import matplotlib.pylab as pylab import matplotlib.pyplot as plt import numpy as np -import filterpy.stats as stats def plot_height_std(x, lw=10): m = np.mean(x) diff --git a/code/gh_internal.py b/code/gh_internal.py index 05b719e..4a37437 100644 --- a/code/gh_internal.py +++ b/code/gh_internal.py @@ -1,8 +1,26 @@ -import numpy as np -import pylab as plt -from matplotlib.patches import Circle, Rectangle, Polygon, Arrow, FancyArrow -import book_plots +# -*- coding: utf-8 -*- + +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. +""" + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import book_format +import book_plots +import numpy as np +from matplotlib.patches import Circle, Rectangle, Polygon, Arrow, FancyArrow +import pylab as plt def plot_errorbar1(): with book_format.figsize(y=1.5): diff --git a/code/gif_animate.py b/code/gif_animate.py index e135500..ff51069 100644 --- a/code/gif_animate.py +++ b/code/gif_animate.py @@ -1,10 +1,21 @@ # -*- coding: utf-8 -*- -""" -Created on Sun Sep 14 12:41:24 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + from matplotlib import animation import matplotlib.pyplot as plt diff --git a/code/kf_design_internal.py b/code/kf_design_internal.py index a084dcd..76998b7 100644 --- a/code/kf_design_internal.py +++ b/code/kf_design_internal.py @@ -1,10 +1,21 @@ # -*- coding: utf-8 -*- -""" -Created on Mon Jul 13 13:20:27 2015 -@author: Roger +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + from filterpy.kalman import UnscentedKalmanFilter as UKF from filterpy.kalman import JulierSigmaPoints from math import atan2 diff --git a/code/kf_internal.py b/code/kf_internal.py index b93f7ac..568b84c 100644 --- a/code/kf_internal.py +++ b/code/kf_internal.py @@ -1,10 +1,21 @@ # -*- coding: utf-8 -*- -""" -Created on Sat Jul 25 17:13:23 2015 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import book_plots as bp import matplotlib.pyplot as plt @@ -20,8 +31,8 @@ def plot_dog_track(xs, measurement_var, process_var): def print_gh(predict, update, z): - predict_template = 'PREDICT: {: 6.2f} {: 6.2f}' - update_template = 'UPDATE: {: 6.2f} {: 6.2f}\tZ: {:.2f}' + predict_template = ' {: 7.3f} {: 8.3f}' + update_template = '{: 7.3f} {: 7.3f}\t {:.3f}' print(predict_template.format(predict[0], predict[1]),end='\t') print(update_template.format(update[0], update[1], z)) diff --git a/code/mkf_internal.py b/code/mkf_internal.py index a597a02..2172842 100644 --- a/code/mkf_internal.py +++ b/code/mkf_internal.py @@ -1,16 +1,28 @@ # -*- coding: utf-8 -*- -""" -Created on Thu May 1 16:56:49 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import filterpy.stats as stats from filterpy.stats import plot_covariance_ellipse -import numpy as np from matplotlib.patches import Ellipse import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D +import numpy as np from numpy.random import multivariate_normal diff --git a/code/nonlinear_internal.py b/code/nonlinear_internal.py index a1445a9..703ee71 100644 --- a/code/nonlinear_internal.py +++ b/code/nonlinear_internal.py @@ -1,13 +1,23 @@ # -*- coding: utf-8 -*- -""" -Created on Thu Jul 9 13:02:32 2015 -@author: Roger Labbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import filterpy.stats as stats import matplotlib.pyplot as plt -from matplotlib.patches import Ellipse import numpy as np diff --git a/code/nonlinear_plots.py b/code/nonlinear_plots.py index 05fa096..9eb12e6 100644 --- a/code/nonlinear_plots.py +++ b/code/nonlinear_plots.py @@ -1,11 +1,20 @@ # -*- coding: utf-8 -*- -""" -Created on Sun May 18 11:09:23 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ -from __future__ import division +from __future__ import (absolute_import, division, print_function, + unicode_literals) from filterpy.stats import multivariate_gaussian from matplotlib import cm diff --git a/code/particle_filter.py b/code/particle_filter.py index 395fa0c..6dcab3a 100644 --- a/code/particle_filter.py +++ b/code/particle_filter.py @@ -1,29 +1,32 @@ # -*- coding: utf-8 -*- -""" -Created on Sat May 2 09:46:06 2015 -@author: Roger +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + + import math +import matplotlib.pyplot as plt import numpy as np from numpy.random import uniform from numpy.random import randn import scipy.stats -import matplotlib.pyplot as plt import random - - - - - - - - - if __name__ == '__main__': N = 2000 pf = ParticleFilter(N, 100, 100) @@ -33,7 +36,7 @@ if __name__ == '__main__': #pf.create_particles(mean=z, variance=40) mu0 = np.array([0., 0.]) - plot(pf, weights=False) + plt.plot(pf, weights=False) fig = plt.gcf() diff --git a/code/pf_internal.py b/code/pf_internal.py index f491247..36db871 100644 --- a/code/pf_internal.py +++ b/code/pf_internal.py @@ -1,3 +1,22 @@ +# -*- coding: utf-8 -*- + +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. +""" + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + + from filterpy.monte_carlo import stratified_resample import matplotlib as mpl import matplotlib.pyplot as plt @@ -5,7 +24,6 @@ import matplotlib.pyplot as plt import numpy as np from numpy.random import randn, random, uniform, multivariate_normal, seed #from nonlinear_plots import plot_monte_carlo_mean -import pylab as plt import scipy.stats from RobotLocalizationParticleFilter import * diff --git a/code/smoothing_internal.py b/code/smoothing_internal.py index 9922d4f..ebef714 100644 --- a/code/smoothing_internal.py +++ b/code/smoothing_internal.py @@ -1,9 +1,21 @@ # -*- coding: utf-8 -*- -""" -Created on Tue May 27 21:21:19 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + import matplotlib.pyplot as plt diff --git a/code/ukf_internal.py b/code/ukf_internal.py index 8e90736..9d5e9b4 100644 --- a/code/ukf_internal.py +++ b/code/ukf_internal.py @@ -1,9 +1,21 @@ # -*- coding: utf-8 -*- -""" -Created on Tue May 27 21:21:19 2014 -@author: rlabbe +"""Copyright 2015 Roger R Labbe Jr. + + +Code supporting the book + +Kalman and Bayesian Filters in Python +https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python + + +This is licensed under an MIT license. See the readme.MD file +for more information. """ + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + from filterpy.kalman import UnscentedKalmanFilter as UKF from filterpy.kalman import MerweScaledSigmaPoints import filterpy.stats as stats