2014-05-03 04:49:35 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Created on Thu May 1 16:56:49 2014
|
|
|
|
|
|
|
|
@author: rlabbe
|
|
|
|
"""
|
2014-05-12 05:44:25 +02:00
|
|
|
import numpy as np
|
|
|
|
from matplotlib.patches import Ellipse
|
2014-05-05 00:33:39 +02:00
|
|
|
import matplotlib.pyplot as plt
|
2014-05-12 05:44:25 +02:00
|
|
|
import stats
|
2014-05-03 04:49:35 +02:00
|
|
|
|
|
|
|
def show_residual_chart():
|
2014-05-05 00:33:39 +02:00
|
|
|
plt.xlim([0.9,2.5])
|
|
|
|
plt.ylim([0.5,2.5])
|
2014-05-03 04:49:35 +02:00
|
|
|
|
2014-05-05 00:33:39 +02:00
|
|
|
plt.scatter ([1,2,2],[1,2,1.3])
|
|
|
|
plt.scatter ([2],[1.8],marker='o')
|
2014-05-03 04:49:35 +02:00
|
|
|
ax = plt.axes()
|
|
|
|
ax.annotate('', xy=(2,2), xytext=(1,1),
|
|
|
|
arrowprops=dict(arrowstyle='->', ec='b',shrinkA=3, shrinkB=4))
|
2014-05-17 02:10:23 +02:00
|
|
|
ax.annotate('prediction', xy=(2.04,2.), color='b')
|
2014-05-03 04:49:35 +02:00
|
|
|
ax.annotate('measurement', xy=(2.05, 1.28))
|
|
|
|
ax.annotate('prior measurement', xy=(1, 0.9))
|
|
|
|
ax.annotate('residual', xy=(2.04,1.6), color='r')
|
2014-05-17 02:10:23 +02:00
|
|
|
ax.annotate('new estimate', xy=(2,1.8),xytext=(2.1,1.8),
|
|
|
|
arrowprops=dict(arrowstyle='->', ec="k", shrinkA=3, shrinkB=4))
|
2014-05-03 04:49:35 +02:00
|
|
|
ax.annotate('', xy=(2,2), xytext=(2,1.3),
|
2014-05-17 02:10:23 +02:00
|
|
|
arrowprops=dict(arrowstyle="-",
|
2014-05-03 04:49:35 +02:00
|
|
|
ec="r",
|
|
|
|
shrinkA=5, shrinkB=5))
|
2014-05-05 00:33:39 +02:00
|
|
|
plt.title("Kalman Filter Prediction Update Step")
|
2014-05-12 05:44:25 +02:00
|
|
|
plt.show()
|
|
|
|
|
2014-05-17 02:10:23 +02:00
|
|
|
|
2014-05-12 05:44:25 +02:00
|
|
|
def show_position_chart():
|
|
|
|
""" Displays 3 measurements at t=1,2,3, with x=1,2,3"""
|
|
|
|
|
2014-05-17 02:10:23 +02:00
|
|
|
plt.scatter ([1,2,3], [1,2,3], s=128)
|
2014-05-12 05:44:25 +02:00
|
|
|
plt.xlim([0,4]);
|
|
|
|
plt.ylim([0,4])
|
|
|
|
|
|
|
|
plt.xlabel("Position")
|
|
|
|
plt.ylabel("Time")
|
|
|
|
|
|
|
|
plt.xticks(np.arange(1,4,1))
|
|
|
|
plt.yticks(np.arange(1,4,1))
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
def show_position_prediction_chart():
|
|
|
|
""" displays 3 measurements, with the next position predicted"""
|
|
|
|
|
2014-05-17 02:10:23 +02:00
|
|
|
plt.scatter ([1,2,3], [1,2,3], s=128)
|
2014-05-12 05:44:25 +02:00
|
|
|
|
|
|
|
plt.xlim([0,5])
|
|
|
|
plt.ylim([0,5])
|
|
|
|
|
|
|
|
plt.xlabel("Position")
|
|
|
|
plt.ylabel("Time")
|
|
|
|
|
|
|
|
plt.xticks(np.arange(1,5,1))
|
|
|
|
plt.yticks(np.arange(1,5,1))
|
|
|
|
|
|
|
|
plt.scatter ([4], [4], c='g',s=128)
|
|
|
|
ax = plt.axes()
|
|
|
|
ax.annotate('', xy=(4,4), xytext=(3,3),
|
2014-06-22 23:18:04 +02:00
|
|
|
arrowprops=dict(arrowstyle='->',
|
|
|
|
ec='g',
|
|
|
|
shrinkA=6, shrinkB=5,
|
|
|
|
lw=3))
|
2014-05-12 05:44:25 +02:00
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
2014-06-22 23:18:04 +02:00
|
|
|
def show_x_error_chart():
|
2014-05-12 05:44:25 +02:00
|
|
|
""" displays x=123 with covariances showing error"""
|
|
|
|
|
|
|
|
cov = np.array([[0.003,0], [0,12]])
|
|
|
|
sigma=[0.5,1.,1.5,2]
|
2014-06-22 23:18:04 +02:00
|
|
|
e = stats.covariance_ellipse (cov)
|
2014-05-12 05:44:25 +02:00
|
|
|
|
2014-06-22 23:18:04 +02:00
|
|
|
stats.plot_covariance_ellipse ((1,1), ellipse=e, variance=sigma, axis_equal=False)
|
|
|
|
stats.plot_covariance_ellipse ((2,1), ellipse=e, variance=sigma, axis_equal=False)
|
|
|
|
stats.plot_covariance_ellipse ((3,1), ellipse=e, variance=sigma, axis_equal=False)
|
2014-05-12 05:44:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
plt.ylim([0,11])
|
|
|
|
plt.xticks(np.arange(1,4,1))
|
|
|
|
|
|
|
|
plt.xlabel("Position")
|
|
|
|
plt.ylabel("Time")
|
|
|
|
|
|
|
|
plt.show()
|
|
|
|
|
|
|
|
def show_x_with_unobserved():
|
|
|
|
""" shows x=1,2,3 with velocity superimposed on top """
|
|
|
|
|
2014-06-22 23:18:04 +02:00
|
|
|
# plot velocity
|
2014-05-12 05:44:25 +02:00
|
|
|
sigma=[0.5,1.,1.5,2]
|
|
|
|
cov = np.array([[1,1],[1,1.1]])
|
2014-06-22 23:18:04 +02:00
|
|
|
stats.plot_covariance_ellipse ((2,2), cov=cov, variance=sigma, axis_equal=False)
|
2014-05-12 05:44:25 +02:00
|
|
|
|
2014-06-22 23:18:04 +02:00
|
|
|
# plot positions
|
2014-05-12 05:44:25 +02:00
|
|
|
cov = np.array([[0.003,0], [0,12]])
|
2014-06-22 23:18:04 +02:00
|
|
|
sigma=[0.5,1.,1.5,2]
|
|
|
|
e = stats.covariance_ellipse (cov)
|
|
|
|
|
|
|
|
stats.plot_covariance_ellipse ((1,1), ellipse=e, variance=sigma, axis_equal=False)
|
|
|
|
stats.plot_covariance_ellipse ((2,1), ellipse=e, variance=sigma, axis_equal=False)
|
|
|
|
stats.plot_covariance_ellipse ((3,1), ellipse=e, variance=sigma, axis_equal=False)
|
2014-05-12 05:44:25 +02:00
|
|
|
|
2014-06-22 23:18:04 +02:00
|
|
|
# plot intersection cirle
|
2014-05-12 05:44:25 +02:00
|
|
|
isct = Ellipse(xy=(2,2), width=.2, height=1.2, edgecolor='r', fc='None', lw=4)
|
2014-06-22 23:18:04 +02:00
|
|
|
plt.gca().add_artist(isct)
|
2014-05-12 05:44:25 +02:00
|
|
|
|
|
|
|
plt.ylim([0,11])
|
2014-06-22 23:18:04 +02:00
|
|
|
plt.xlim([0,4])
|
2014-05-12 05:44:25 +02:00
|
|
|
plt.xticks(np.arange(1,4,1))
|
|
|
|
|
|
|
|
plt.xlabel("Position")
|
|
|
|
plt.ylabel("Time")
|
|
|
|
|
2014-06-22 23:18:04 +02:00
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
show_x_with_unobserved()
|