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