wolffd@0: function [h1, h2] = mlphint(net); wolffd@0: %MLPHINT Plot Hinton diagram for 2-layer feed-forward network. wolffd@0: % wolffd@0: % Description wolffd@0: % wolffd@0: % MLPHINT(NET) takes a network structure NET and plots the Hinton wolffd@0: % diagram comprised of two figure windows, one displaying the first- wolffd@0: % layer weights and biases, and one displaying the second-layer weights wolffd@0: % and biases. wolffd@0: % wolffd@0: % [H1, H2] = MLPHINT(NET) also returns handles H1 and H2 to the wolffd@0: % figures which can be used, for instance, to delete the figures when wolffd@0: % they are no longer needed. wolffd@0: % wolffd@0: % To print the figure correctly, you should call SET(H, wolffd@0: % 'INVERTHARDCOPY', 'ON') before printing. wolffd@0: % wolffd@0: % See also wolffd@0: % DEMHINT, HINTMAT, MLP, MLPPAK, MLPUNPAK 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: wb1 = [net.w1; net.b1]; wolffd@0: [xvals, yvals, color] = hintmat(wb1'); wolffd@0: % Try to preserve aspect ratio approximately wolffd@0: if (8*net.nhidden < 6*(net.nin + 1)) wolffd@0: delx = xmax; dely = xmax*net.nhidden/(net.nin + 1); wolffd@0: else wolffd@0: delx = ymax*(net.nin + 1)/net.nhidden; dely = ymax; wolffd@0: end wolffd@0: wolffd@0: h1 = figure('Color', [0.5 0.5 0.5], ... wolffd@0: 'Name', 'Hinton diagram: first-layer weights and biases', ... 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: wolffd@0: cmap = [0 0 0; 1 1 1]; wolffd@0: colors(1, :, :) = cmap(color, :); wolffd@0: patch(xvals', yvals', colors, 'Edgecolor', 'none'); wolffd@0: axis equal; wolffd@0: xpos = net.nin; wolffd@0: line([xpos xpos], [0 net.nhidden], 'color', 'red', 'linewidth', 3); wolffd@0: wolffd@0: % Second layer wolffd@0: wolffd@0: wb2 = [net.w2; net.b2]; wolffd@0: [xvals, yvals, color] = hintmat(wb2'); wolffd@0: if (8*net.nout < 6*(net.nhidden + 1)) wolffd@0: delx = xmax; dely = xmax*net.nout/(net.nhidden + 1); wolffd@0: else wolffd@0: delx = ymax*(net.nhidden + 1)/net.nout; dely = ymax; wolffd@0: end wolffd@0: wolffd@0: h2 = figure('Color', [0.5 0.5 0.5], ... wolffd@0: 'Name', 'Hinton diagram: second-layer weights and biases', ... wolffd@0: 'NumberTitle', 'off', ... wolffd@0: 'Colormap', [0 0 0; 1 1 1], ... wolffd@0: 'Units', 'pixels', ... wolffd@0: 'Position', [x02 y02 delx dely]); wolffd@0: set(gca, 'Visible', 'off', 'Position', [0 0 1 1]); wolffd@0: wolffd@0: hold on wolffd@0: colors2(1, :, :) = cmap(color, :); wolffd@0: patch(xvals', yvals', colors2, 'Edgecolor', 'none'); wolffd@0: axis equal; wolffd@0: xpos = net.nhidden; wolffd@0: line([xpos xpos], [0 net.nout], 'color', 'red', 'linewidth', 3); wolffd@0: