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