wolffd@0: function h = hinton(w); wolffd@0: %HINTON Plot Hinton diagram for a weight matrix. wolffd@0: % wolffd@0: % Description wolffd@0: % wolffd@0: % HINTON(W) takes a matrix W and plots the Hinton diagram. wolffd@0: % wolffd@0: % H = HINTON(NET) also returns the figure handle H which can be used, wolffd@0: % for instance, to delete the figure when it is no longer needed. wolffd@0: % wolffd@0: % To print the figure correctly in black and white, you should call wolffd@0: % SET(H, 'INVERTHARDCOPY', 'OFF') before printing. wolffd@0: % wolffd@0: % See also wolffd@0: % DEMHINT, HINTMAT, MLPHINT wolffd@0: % wolffd@0: wolffd@0: % Copyright (c) Ian T Nabney (1996-2001) wolffd@0: wolffd@0: % Set scale to be up to 0.9 of maximum absolute weight value, where scale wolffd@0: % defined so that area of box proportional to weight value. wolffd@0: wolffd@0: % Use no more than 640x480 pixels wolffd@0: xmax = 640; ymax = 480; wolffd@0: wolffd@0: % Offset bottom left hand corner wolffd@0: x01 = 40; y01 = 40; wolffd@0: x02 = 80; y02 = 80; wolffd@0: wolffd@0: % Need to allow 5 pixels border for window frame: but 30 at top wolffd@0: border = 5; wolffd@0: top_border = 30; wolffd@0: wolffd@0: ymax = ymax - top_border; wolffd@0: xmax = xmax - border; wolffd@0: wolffd@0: % First layer wolffd@0: wolffd@0: [xvals, yvals, color] = hintmat(w); wolffd@0: % Try to preserve aspect ratio approximately wolffd@0: if (8*size(w, 1) < 6*size(w, 2)) wolffd@0: delx = xmax; dely = xmax*size(w, 1)/(size(w, 2)); wolffd@0: else wolffd@0: delx = ymax*size(w, 2)/size(w, 1); dely = ymax; wolffd@0: end wolffd@0: wolffd@0: h = figure('Color', [0.5 0.5 0.5], ... wolffd@0: 'Name', 'Hinton diagram', ... wolffd@0: 'NumberTitle', 'off', ... wolffd@0: 'Colormap', [0 0 0; 1 1 1], ... wolffd@0: 'Units', 'pixels', ... wolffd@0: 'Position', [x01 y01 delx dely]); wolffd@0: set(gca, 'Visible', 'off', 'Position', [0 0 1 1]); wolffd@0: hold on wolffd@0: patch(xvals', yvals', color', 'Edgecolor', 'none'); wolffd@0: axis equal; wolffd@0: