This documentation is for astroML version 0.1Other versions

astroML Mailing List

# Neural Network DiagramΒΆ

```# Author: Jake VanderPlas <vanderplas@astro.washington.edu>
#   The figure produced by this code is published in the textbook
#   "Statistics, Data Mining, and Machine Learning in Astronomy" (2013)

import numpy as np
from matplotlib import pyplot as plt

fig = plt.figure(facecolor='w')
ax = fig.add_axes([0, 0, 1, 1],
xticks=[], yticks=[])
plt.box(False)
circ = plt.Circle((1, 1), 2)

# function to draw arrows
theta = np.arctan2(circ2[1] - circ1[1],
circ2[0] - circ1[0])

starting_point = (circ1[0] + rad1 * np.cos(theta),

length = (circ2[0] - circ1[0] - (rad1 + 1.4 * rad2) * np.cos(theta),

ax.arrow(starting_point[0], starting_point[1],
length[0], length[1], **arrow_kwargs)

# function to draw circles
circ = plt.Circle(center, radius, fc='none', lw=2)

x1 = -2
x2 = 0
x3 = 2
y3 = 0

#------------------------------------------------------------
# draw circles
for i, y1 in enumerate(np.linspace(1.5, -1.5, 4)):
ax.text(x1 - 0.9, y1, 'Input #%i' % (i + 1),
ha='right', va='center', fontsize=16)
draw_connecting_arrow(ax, (x1 - 0.9, y1), 0.1, (x1, y1), radius)

for y2 in np.linspace(-2, 2, 5):

ax.text(x3 + 0.8, y3, 'Output', ha='left', va='center', fontsize=16)
draw_connecting_arrow(ax, (x3, y3), radius, (x3 + 0.8, y3), 0.1)

#------------------------------------------------------------
# draw connecting arrows
for y1 in np.linspace(-1.5, 1.5, 4):
for y2 in np.linspace(-2, 2, 5):

for y2 in np.linspace(-2, 2, 5):