Formatting and experiments.
Let this check in get away from me. Bunch of small formatting sttuf in the various chapters, some experimental animations and code, etc. Not a clearly delineated check in.
This commit is contained in:
parent
a3cd023d3b
commit
752320ad01
4070
01_g-h_filter.ipynb
4070
01_g-h_filter.ipynb
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 501 KiB After Width: | Height: | Size: 502 KiB |
BIN
animations/13_particle_move.gif
Normal file
BIN
animations/13_particle_move.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 MiB |
File diff suppressed because one or more lines are too long
342
animations/particle_animate.ipynb
Normal file
342
animations/particle_animate.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -1,62 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sun May 18 11:09:23 2014
|
||||
|
||||
@author: rlabbe
|
||||
"""
|
||||
|
||||
from __future__ import division
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def plot_transfer_func(data, f, lims, num_bins=1000):
|
||||
ys = f(data)
|
||||
|
||||
|
||||
h = np.histogram(ys, num_bins, density=False)
|
||||
|
||||
#plot output
|
||||
plt.subplot(2,2,1)
|
||||
plt.plot(h[0], h[1][1:], lw=4)
|
||||
plt.ylim(lims)
|
||||
plt.gca().xaxis.set_ticklabels([])
|
||||
plt.title('output')
|
||||
|
||||
plt.axhline(np.mean(ys), ls='--', lw=2)
|
||||
|
||||
# plot transfer function
|
||||
plt.subplot(2,2,2)
|
||||
x = np.arange(lims[0], lims[1],0.1)
|
||||
y = f(x)
|
||||
plt.plot (x,y)
|
||||
isct = f(0)
|
||||
plt.plot([0,0,lims[0]],[lims[0],isct,isct],c='r')
|
||||
plt.xlim(lims)
|
||||
plt.ylim(lims)
|
||||
plt.title('transfer function')
|
||||
|
||||
# plot input
|
||||
h = np.histogram(data, num_bins, density=True)
|
||||
|
||||
plt.subplot(2,2,4)
|
||||
plt.plot(h[1][1:], h[0], lw=4)
|
||||
plt.xlim(lims)
|
||||
plt.gca().yaxis.set_ticklabels([])
|
||||
plt.title('input')
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from numpy.random import normal
|
||||
import numpy as np
|
||||
|
||||
data = normal(loc=0.0, scale=1, size=500000)
|
||||
|
||||
def g(x):
|
||||
return (np.cos(4*(x/2+0.7)))*np.sin(0.3*x)-1.6*x
|
||||
|
||||
|
||||
plot_transfer_func (data, g, lims=(-3,3), num_bins=100)
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sun May 18 11:09:23 2014
|
||||
|
||||
@author: rlabbe
|
||||
"""
|
||||
|
||||
from __future__ import division
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def plot_transfer_func(data, f, gaussian, num_bins=300):
|
||||
ys = f(data)
|
||||
x0 = gaussian[0]
|
||||
in_std = np.sqrt(gaussian[1])
|
||||
y = f(x0)
|
||||
m = np.mean(ys)
|
||||
std = np.std(ys)
|
||||
|
||||
in_lims = [x0-in_std*3, x0+in_std*3]
|
||||
out_lims = [y-std*3, y+std*3]
|
||||
|
||||
|
||||
|
||||
#plot output
|
||||
h = np.histogram(ys, num_bins, density=False)
|
||||
plt.subplot(2,2,4)
|
||||
plt.plot(h[0], h[1][1:], lw=4)
|
||||
plt.ylim(out_lims[1], out_lims[0])
|
||||
plt.gca().xaxis.set_ticklabels([])
|
||||
plt.title('output')
|
||||
|
||||
plt.axhline(np.mean(ys), ls='--', lw=2)
|
||||
plt.axhline(f(x0), lw=1)
|
||||
|
||||
# plot transfer function
|
||||
plt.subplot(2,2,3)
|
||||
x = np.arange(in_lims[0], in_lims[1], 0.1)
|
||||
y = f(x)
|
||||
plt.plot (x,y)
|
||||
isct = f(x0)
|
||||
plt.plot([x0, x0, in_lims[1]], [out_lims[1], isct, isct], color='r', lw=1)
|
||||
plt.xlim(in_lims)
|
||||
plt.ylim(out_lims)
|
||||
#plt.axis('equal')
|
||||
plt.title('function')
|
||||
|
||||
# plot input
|
||||
h = np.histogram(data, num_bins, density=True)
|
||||
|
||||
plt.subplot(2,2,1)
|
||||
plt.plot(h[1][1:], h[0], lw=4)
|
||||
plt.xlim(in_lims)
|
||||
plt.gca().yaxis.set_ticklabels([])
|
||||
plt.title('input')
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from numpy.random import normal
|
||||
import numpy as np
|
||||
|
||||
x0 = (1, 1)
|
||||
data = normal(loc=x0[0], scale=x0[1], size=500000)
|
||||
|
||||
def g(x):
|
||||
return x*x
|
||||
return (np.cos(3*(x/2+0.7)))*np.sin(0.7*x)-1.6*x
|
||||
return -2*x
|
||||
|
||||
|
||||
#plot_transfer_func (data, g, lims=(-3,3), num_bins=100)
|
||||
plot_transfer_func (data, g, gaussian=x0,
|
||||
num_bins=100)
|
||||
|
@ -1,46 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Tue Apr 28 08:19:21 2015
|
||||
|
||||
@author: Roger
|
||||
"""
|
||||
|
||||
|
||||
from math import *
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
wheelbase = 100 #inches
|
||||
|
||||
vel = 20 *12 # fps to inches per sec
|
||||
steering_angle = radians(1)
|
||||
t = 1 # second
|
||||
orientation = 0. # radians
|
||||
|
||||
pos = np.array([0., 0.])
|
||||
|
||||
|
||||
for i in range(100):
|
||||
#if abs(steering_angle) > 1.e-8:
|
||||
dist = vel*t
|
||||
turn_radius = tan(steering_angle)
|
||||
radius = wheelbase / tan(steering_angle)
|
||||
|
||||
arc_len = dist / (2*pi*radius)
|
||||
|
||||
turn_angle = 2*pi * arc_len
|
||||
|
||||
|
||||
cx = pos[0] - (sin(orientation) * radius)
|
||||
cy = pos[1] + (cos(orientation) * radius)
|
||||
|
||||
orientation = (orientation + turn_angle) % (2.0 * pi)
|
||||
pos[0] = cx + (sin(orientation) * radius)
|
||||
pos[1] = cy - (cos(orientation) * radius)
|
||||
|
||||
plt.scatter(pos[0], pos[1])
|
||||
|
||||
plt.axis('equal')
|
||||
|
||||
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Tue Apr 28 08:19:21 2015
|
||||
|
||||
@author: Roger
|
||||
"""
|
||||
|
||||
|
||||
from math import *
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
wheelbase = 100 #inches
|
||||
|
||||
vel = 20 *12 # fps to inches per sec
|
||||
steering_angle = radians(1)
|
||||
t = 1 # second
|
||||
orientation = 0. # radians
|
||||
|
||||
pos = np.array([0., 0.]
|
||||
|
||||
for i in range(100):
|
||||
#if abs(steering_angle) > 1.e-8:
|
||||
dist = vel*t
|
||||
turn_radius = tan(steering_angle)
|
||||
radius = wheelbase / tan(steering_angle)
|
||||
|
||||
arc_len = dist / (2*pi*radius)
|
||||
|
||||
turn_angle = 2*pi * arc_len
|
||||
|
||||
|
||||
cx = pos[0] - (sin(orientation) * radius)
|
||||
cy = pos[1] + (cos(orientation) * radius)
|
||||
|
||||
orientation = (orientation + turn_angle) % (2.0 * pi)
|
||||
pos[0] = cx + (sin(orientation) * radius)
|
||||
pos[1] = cy - (cos(orientation) * radius)
|
||||
|
||||
plt.scatter(pos[0], pos[1])
|
||||
|
||||
plt.axis('equal')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user