annotate toolboxes/FullBNT-1.0.7/netlab3.3/mlphint.m @ 0:cc4b1211e677 tip

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