How to implement a neural network (3/5)
# Illustrate the transformation of x to h plt.figure(figsize=(6, 6)) gs = gridspec.GridSpec(2, 2, width_ratios=[6, 1], height_ratios=[6, 1]) gs.update(wspace=0., hspace=0.) plt.suptitle( 'Projection of the input samples $x$ ' 'to hidden layer output $h$.') # Plot input ax_in = plt.subplot(gs[2]) ax_in.plot(xs_blue, np.zeros_like(xs_blue), 'bo', alpha=0.75) ax_in.plot(xs_red, np.zeros_like(xs_red), 'r*', alpha=0.75) ax_in.yaxis.set_visible(False) ax_in.set_xlabel('$x$', fontsize=12) ax_in.set_xlim(-3,3) ax_in.set_ylim(-1,1) # Plot red star projections for xr in xs_red: ax_in.plot((xr, xr), (0, 1), 'r--', alpha=0.2) # Plot blue circle projections for xb in xs_blue: ax_in.plot((xb, xb), (0, 2), 'b--', alpha=0.2) # Plot RBF function ax_rbf = plt.subplot(gs[0]) xs_rbf = np.linspace(-3, 3, 100) ax_rbf.plot( xs_rbf, hidden_activations(xs_rbf, wh), 'k-', label='$h = RBF(x \cdot w_h)$') ax_rbf.legend() ax_rbf.set_xlim(-3, 3) ax_rbf.set_ylim(-0.1, 1.1) ax_rbf.xaxis.set_ticks_position('top') # Plot red star projections for xr in xs_red: xr = float(xr) h = hidden_activations(xr, wh) ax_rbf.plot((xr, xr), (-0.1, h), 'r--', alpha=0.2) ax_rbf.plot((xr, 3), [h, h], 'r--', alpha=0.2) # Plot blue circle projections for xb in xs_blue: xb = float(xb) h = hidden_activations(xb, wh) ax_rbf.plot((xb, xb), (-0.1, h), 'b--', alpha=0.2) ax_rbf.plot((xb, 3), [h, h], 'b--', alpha=0.2) # Plot output ax_out = plt.subplot(gs[1]) ax_out.plot( np.zeros_like(xs_blue), hidden_activations(xs_blue, wh), 'bo', alpha=0.75) ax_out.plot( np.zeros_like(xs_red), hidden_activations(xs_red, wh), 'r*', alpha=0.75) ax_out.xaxis.set_visible(False) ax_out.yaxis.set_label_position('right') ax_out.yaxis.set_ticks_position('right') ax_out.set_ylabel('$h$', fontsize=12) ax_out.set_ylim(-0.1, 1.1) ax_out.set_xlim(-1, 1) # Plot red star projections for xr in xs_red: h = hidden_activations(xr, wh) ax_out.plot((-1, 0), (h, h), 'r--', alpha=0.2) # Plot blue circle projections for xb, in xs_blue: h = hidden_activations(xb, wh) ax_out.plot((-1, 0), (h, h), 'b--', alpha=0.2) plt.show() #
网址:How to implement a neural network (3/5) https://mxgxt.com/news/view/1704560
相关内容
Understanding Neural Networks Through Deep VisualizationFacebook Social Network Dataset
how to revert back to normal after display:none for table row
How to Remove Display Flex in CSS?
How to Convert Temperature (K) to RGB: Algorithm and Sample Code
How to change the number system from indian to US number system on excel?
The Beacon Chain Ethereum 2.0 explainer you need to read first
How to reverse the effect of “display:none”
Cross Entropy and Log Likelihood
如何用英语与表达尊重 How to show respect in English