2015-07-26 08:46:59 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2015-08-01 17:46:14 +02:00
|
|
|
"""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
|
|
|
|
|
|
|
|
|
2015-08-01 17:52:48 +02:00
|
|
|
This is licensed under an MIT license. See the LICENSE.txt file
|
2015-08-01 17:46:14 +02:00
|
|
|
for more information.
|
2015-07-26 08:46:59 +02:00
|
|
|
"""
|
|
|
|
|
2015-08-01 17:46:14 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function,
|
|
|
|
unicode_literals)
|
|
|
|
|
2015-07-26 08:46:59 +02:00
|
|
|
import book_plots as bp
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
def plot_dog_track(xs, measurement_var, process_var):
|
|
|
|
N = len(xs)
|
|
|
|
bp.plot_track([0, N-1], [1, N])
|
|
|
|
bp.plot_measurements(xs, label='Sensor')
|
|
|
|
bp.set_labels('variance = {}, process variance = {}'.format(
|
|
|
|
measurement_var, process_var), 'time', 'pos')
|
|
|
|
plt.ylim([0, N])
|
|
|
|
bp.show_legend()
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
def print_gh(predict, update, z):
|
2015-08-01 17:46:14 +02:00
|
|
|
predict_template = ' {: 7.3f} {: 8.3f}'
|
|
|
|
update_template = '{: 7.3f} {: 7.3f}\t {:.3f}'
|
2015-07-26 08:46:59 +02:00
|
|
|
|
|
|
|
print(predict_template.format(predict[0], predict[1]),end='\t')
|
|
|
|
print(update_template.format(update[0], update[1], z))
|
|
|
|
|
|
|
|
|
|
|
|
def print_variance(positions):
|
|
|
|
print('Variance:')
|
|
|
|
for i in range(0, len(positions), 5):
|
|
|
|
print('\t{:.4f} {:.4f} {:.4f} {:.4f} {:.4f}'.format(
|
|
|
|
*[v[1] for v in positions[i:i+5]]))
|