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