Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlab3.3/mlphint.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [h1, h2] = mlphint(net); | |
2 %MLPHINT Plot Hinton diagram for 2-layer feed-forward network. | |
3 % | |
4 % Description | |
5 % | |
6 % MLPHINT(NET) takes a network structure NET and plots the Hinton | |
7 % diagram comprised of two figure windows, one displaying the first- | |
8 % layer weights and biases, and one displaying the second-layer weights | |
9 % and biases. | |
10 % | |
11 % [H1, H2] = MLPHINT(NET) also returns handles H1 and H2 to the | |
12 % figures which can be used, for instance, to delete the figures when | |
13 % they are no longer needed. | |
14 % | |
15 % To print the figure correctly, you should call SET(H, | |
16 % 'INVERTHARDCOPY', 'ON') before printing. | |
17 % | |
18 % See also | |
19 % DEMHINT, HINTMAT, MLP, MLPPAK, MLPUNPAK | |
20 % | |
21 | |
22 % Copyright (c) Ian T Nabney (1996-2001) | |
23 | |
24 % Set scale to be up to 0.9 of maximum absolute weight value, where scale | |
25 % defined so that area of box proportional to weight value. | |
26 | |
27 % Use no more than 640x480 pixels | |
28 xmax = 640; ymax = 480; | |
29 | |
30 % Offset bottom left hand corner | |
31 x01 = 40; y01 = 40; | |
32 x02 = 80; y02 = 80; | |
33 | |
34 % Need to allow 5 pixels border for window frame: but 30 at top | |
35 border = 5; | |
36 top_border = 30; | |
37 | |
38 ymax = ymax - top_border; | |
39 xmax = xmax - border; | |
40 | |
41 % First layer | |
42 | |
43 wb1 = [net.w1; net.b1]; | |
44 [xvals, yvals, color] = hintmat(wb1'); | |
45 % Try to preserve aspect ratio approximately | |
46 if (8*net.nhidden < 6*(net.nin + 1)) | |
47 delx = xmax; dely = xmax*net.nhidden/(net.nin + 1); | |
48 else | |
49 delx = ymax*(net.nin + 1)/net.nhidden; dely = ymax; | |
50 end | |
51 | |
52 h1 = figure('Color', [0.5 0.5 0.5], ... | |
53 'Name', 'Hinton diagram: first-layer weights and biases', ... | |
54 'NumberTitle', 'off', ... | |
55 'Colormap', [0 0 0; 1 1 1], ... | |
56 'Units', 'pixels', ... | |
57 'Position', [x01 y01 delx dely]); | |
58 set(gca, 'Visible', 'off', 'Position', [0 0 1 1]); | |
59 hold on | |
60 | |
61 cmap = [0 0 0; 1 1 1]; | |
62 colors(1, :, :) = cmap(color, :); | |
63 patch(xvals', yvals', colors, 'Edgecolor', 'none'); | |
64 axis equal; | |
65 xpos = net.nin; | |
66 line([xpos xpos], [0 net.nhidden], 'color', 'red', 'linewidth', 3); | |
67 | |
68 % Second layer | |
69 | |
70 wb2 = [net.w2; net.b2]; | |
71 [xvals, yvals, color] = hintmat(wb2'); | |
72 if (8*net.nout < 6*(net.nhidden + 1)) | |
73 delx = xmax; dely = xmax*net.nout/(net.nhidden + 1); | |
74 else | |
75 delx = ymax*(net.nhidden + 1)/net.nout; dely = ymax; | |
76 end | |
77 | |
78 h2 = figure('Color', [0.5 0.5 0.5], ... | |
79 'Name', 'Hinton diagram: second-layer weights and biases', ... | |
80 'NumberTitle', 'off', ... | |
81 'Colormap', [0 0 0; 1 1 1], ... | |
82 'Units', 'pixels', ... | |
83 'Position', [x02 y02 delx dely]); | |
84 set(gca, 'Visible', 'off', 'Position', [0 0 1 1]); | |
85 | |
86 hold on | |
87 colors2(1, :, :) = cmap(color, :); | |
88 patch(xvals', yvals', colors2, 'Edgecolor', 'none'); | |
89 axis equal; | |
90 xpos = net.nhidden; | |
91 line([xpos xpos], [0 net.nout], 'color', 'red', 'linewidth', 3); | |
92 |