annotate toolboxes/FullBNT-1.0.7/netlab3.3/hinton.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 h = hinton(w);
wolffd@0 2 %HINTON Plot Hinton diagram for a weight matrix.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 %
wolffd@0 6 % HINTON(W) takes a matrix W and plots the Hinton diagram.
wolffd@0 7 %
wolffd@0 8 % H = HINTON(NET) also returns the figure handle H which can be used,
wolffd@0 9 % for instance, to delete the figure when it is no longer needed.
wolffd@0 10 %
wolffd@0 11 % To print the figure correctly in black and white, you should call
wolffd@0 12 % SET(H, 'INVERTHARDCOPY', 'OFF') before printing.
wolffd@0 13 %
wolffd@0 14 % See also
wolffd@0 15 % DEMHINT, HINTMAT, MLPHINT
wolffd@0 16 %
wolffd@0 17
wolffd@0 18 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 19
wolffd@0 20 % Set scale to be up to 0.9 of maximum absolute weight value, where scale
wolffd@0 21 % defined so that area of box proportional to weight value.
wolffd@0 22
wolffd@0 23 % Use no more than 640x480 pixels
wolffd@0 24 xmax = 640; ymax = 480;
wolffd@0 25
wolffd@0 26 % Offset bottom left hand corner
wolffd@0 27 x01 = 40; y01 = 40;
wolffd@0 28 x02 = 80; y02 = 80;
wolffd@0 29
wolffd@0 30 % Need to allow 5 pixels border for window frame: but 30 at top
wolffd@0 31 border = 5;
wolffd@0 32 top_border = 30;
wolffd@0 33
wolffd@0 34 ymax = ymax - top_border;
wolffd@0 35 xmax = xmax - border;
wolffd@0 36
wolffd@0 37 % First layer
wolffd@0 38
wolffd@0 39 [xvals, yvals, color] = hintmat(w);
wolffd@0 40 % Try to preserve aspect ratio approximately
wolffd@0 41 if (8*size(w, 1) < 6*size(w, 2))
wolffd@0 42 delx = xmax; dely = xmax*size(w, 1)/(size(w, 2));
wolffd@0 43 else
wolffd@0 44 delx = ymax*size(w, 2)/size(w, 1); dely = ymax;
wolffd@0 45 end
wolffd@0 46
wolffd@0 47 h = figure('Color', [0.5 0.5 0.5], ...
wolffd@0 48 'Name', 'Hinton diagram', ...
wolffd@0 49 'NumberTitle', 'off', ...
wolffd@0 50 'Colormap', [0 0 0; 1 1 1], ...
wolffd@0 51 'Units', 'pixels', ...
wolffd@0 52 'Position', [x01 y01 delx dely]);
wolffd@0 53 set(gca, 'Visible', 'off', 'Position', [0 0 1 1]);
wolffd@0 54 hold on
wolffd@0 55 patch(xvals', yvals', color', 'Edgecolor', 'none');
wolffd@0 56 axis equal;
wolffd@0 57