Interim check in.
dog_track_1d is just a file to test code before putting it into the Kalman filter chapter.
This commit is contained in:
parent
fdae26c7b8
commit
0b149352ed
File diff suppressed because one or more lines are too long
35
dog_track_1d.py
Normal file
35
dog_track_1d.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Wed Apr 30 10:35:19 2014
|
||||
|
||||
@author: rlabbe
|
||||
"""
|
||||
import numpy.random as random
|
||||
|
||||
class dog_sensor(object):
|
||||
def __init__(self, x0 = 0, motion=1, noise=0.0):
|
||||
self.x = x0
|
||||
self.motion = motion
|
||||
self.noise = math.sqrt(noise)
|
||||
|
||||
def sense(self):
|
||||
self.x = self.x + self.motion
|
||||
self.x += random.randn() * self.noise
|
||||
return self.x
|
||||
|
||||
|
||||
def measure_dog ():
|
||||
if not hasattr(measure_dog, "x"):
|
||||
measure_dog.x = 0
|
||||
measure_dog.motion = 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
dog = dog_sensor(noise = 1)
|
||||
for i in range(10):
|
||||
print (dog.sense())
|
||||
|
||||
|
||||
|
||||
|
10
gaussian.py
10
gaussian.py
@ -1,6 +1,6 @@
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def _to_array(x):
|
||||
""" returns any of a scalar, matrix, or array as a 1D numpy array
|
||||
@ -63,6 +63,14 @@ def multivariate_gaussian (x, mu, cov):
|
||||
fprime = (x - mu)**2
|
||||
return frac * np.exp(-0.5*np.dot(fprime, 1./np.diag(cov)))
|
||||
|
||||
def norm_plot (mean, var):
|
||||
min_x = mean - var * 1.5
|
||||
max_x = mean + var * 1.5
|
||||
|
||||
xs = np.arange (min_x, max_x, 0.1)
|
||||
ys = [gaussian (x,23,5) for x in xs]
|
||||
plt.plot (xs,ys)
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
from scipy.stats import norm
|
||||
|
Loading…
Reference in New Issue
Block a user