Adding Particle filter chapter.
This is an early, incomplete draft, but it is time to get it into source control so I can track changes. Not ready for public consumption.
This commit is contained in:
@@ -102,6 +102,62 @@ def plot_filter(xs, ys=None, c='#013afe', label='Filter', vars=None, **kwargs):
|
||||
facecolor='yellow', alpha=0.2)
|
||||
|
||||
|
||||
|
||||
|
||||
def _blob(x, y, area, colour):
|
||||
"""
|
||||
Draws a square-shaped blob with the given area (< 1) at
|
||||
the given coordinates.
|
||||
"""
|
||||
hs = np.sqrt(area) / 2
|
||||
xcorners = np.array([x - hs, x + hs, x + hs, x - hs])
|
||||
ycorners = np.array([y - hs, y - hs, y + hs, y + hs])
|
||||
plt.fill(xcorners, ycorners, colour, edgecolor=colour)
|
||||
|
||||
def hinton(W, maxweight=None):
|
||||
"""
|
||||
Draws a Hinton diagram for visualizing a weight matrix.
|
||||
Temporarily disables matplotlib interactive mode if it is on,
|
||||
otherwise this takes forever.
|
||||
"""
|
||||
reenable = False
|
||||
if plt.isinteractive():
|
||||
plt.ioff()
|
||||
|
||||
plt.clf()
|
||||
height, width = W.shape
|
||||
if not maxweight:
|
||||
maxweight = 2**np.ceil(np.log(np.max(np.abs(W)))/np.log(2))
|
||||
|
||||
plt.fill(np.array([0, width, width, 0]),
|
||||
np.array([0, 0, height, height]),
|
||||
'gray')
|
||||
|
||||
plt.axis('off')
|
||||
plt.axis('equal')
|
||||
for x in range(width):
|
||||
for y in range(height):
|
||||
_x = x+1
|
||||
_y = y+1
|
||||
w = W[y, x]
|
||||
if w > 0:
|
||||
_blob(_x - 0.5,
|
||||
height - _y + 0.5,
|
||||
min(1, w/maxweight),
|
||||
'white')
|
||||
elif w < 0:
|
||||
_blob(_x - 0.5,
|
||||
height - _y + 0.5,
|
||||
min(1, -w/maxweight),
|
||||
'black')
|
||||
if reenable:
|
||||
plt.ion()
|
||||
|
||||
if __name__ == "__main__":
|
||||
hinton(np.random.randn(20, 20))
|
||||
plt.title('Example Hinton diagram - 20x20 random normal')
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
p = [0.2245871, 0.06288015, 0.06109133, 0.0581008, 0.09334062, 0.2245871,
|
||||
0.06288015, 0.06109133, 0.0581008, 0.09334062]*2
|
||||
|
||||
Reference in New Issue
Block a user