MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Hinton diagrams

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63071] Re: Hinton diagrams
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 13 Dec 2005 03:40:53 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <dnir4e$9ua$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

hans.sjunnesson at gmail.com wrote:
> I have created a neural network using the Fast Artificial Neural
> Networks package for Mathematica.
> In the end the weights of the finished network is represented thusly:
> 
> {{1, 8, -0.0354672}, {2, 8, 0.719431}, {3, 8, 0.538668}, {4, 8,
> 0.617062}, {5,
>    8, 2.69463}, {6, 8, 1.32144}, {7, 8, -0.386639}, {1, 9, 1.03297},
> {2,
>    9, 0.655591}, {3, 9, 0.806346}, {4,
>    9, 0.632072}, {5, 9, 0.55292}, {6, 9,
>     0.599058}, {7, 9, 1.0424}, {1, 10, -1.64471}, {2, 10, 2.62318}, {3,
>    10, 1.51706}, {4, 10, 1.68971}, {5, 10, 0.899632}, {6, 10,
> -1.15408}, {
>   7, 10, -0.157527}, {1, 11, -0.186235}, {2, 11, 1.39747}, {3, 11,
> 1.89406}, {
>     4, 11, -0.434147}, {5, 11, -1.88703}, {6,
>     11, 2.23624}, {7, 11, -3.17978}, {8, 13, 1.83855}, {9, 13,
> -0.912118}, {
>     10, 13, 4.37321}, {11, 13, 3.82373}, {12, 13, -5.73714}}
> 
> I looks quite messy, but it's fairly simple - the weight of the
> connection from unit 1 to unit 8 is -0.0354672, the connection from 2
> to 8 is 0.719431 and so forth.
> 
> Units 1 to 7 represents the first layer, units 8 to 12 the hidden
> middle layer and unit 13 is the single output layer.
> 
> A Hinton diagram is a matrix of squares. The squares' size represents
> the magnitude of the weight, and the color is the weight's sign.
> There's a screenshot here http://www.nd.com/products/nsv30/hinton.htm
> 
> I would like to create two Hinton diagrams from this data. One for the
> weights from the first to the second layer, and one for the weights
> from the second to the third layer.
> 
> Has anyone done something similar, or can propose a solution to this?
> I'd very much appreciate it.
> 
Hi Hans,

The following function should do more or less what you are looking for. 
At least, I believe it is a good starting point.

plotHinton[l_List, p_Integer, q_Integer] :=
	Module[{data, maxWeight, xmin, xmax, ymin, ymax},
   		
   	data = Select[l, p <= #1[[1]] <= q & ];
   	maxWeight = Max[Abs[data[[All,3]]]];
     	xmin = Min[data[[All,1]]] - 1;
     	xmax = Max[data[[All,1]]] + 1;
     	ymin = Min[data[[All,2]]] - 1;
     	ymax = Max[data[[All,2]]] + 1;
     	
     	hinton[pt_] :=
     		Module[{wg, gl, scale, px, py},
       			wg = pt[[3]];
       			gl = If[Sign[wg] > 0, 0, 0.8];
       			wg = Abs[wg];
       			scale = wg/maxWeight;
        			
        			px = {pt[[1]], pt[[2]]} - {scale, scale}/2;
        			py = {pt[[1]], pt[[2]]} + {scale, scale}/2;
        			
        			Graphics[{GrayLevel[gl], Rectangle[px, py]}]
        		];
        		
        	Show[hinton /@ data,
        		Frame -> True,
        		AspectRatio -> Automatic,
        		PlotRange -> {{xmin, xmax}, {ymin, ymax}},
        		ImageSize -> 500,
      		FrameTicks -> {Range[xmin, xmax], Range[ymin, ymax], None, None}]
   	]

Now we try it with your data

In[2]:=
data={{1,8,-0.0354672},{2,8,0.719431},{3,8,0.538668},{4,
         8,0.617062},{5,8,2.69463},{6,8,1.32144},{7,8,-0.386639},{1,
         9,1.03297},{2,9,0.655591},{3,9,0.806346},{4,9,0.632072},{5,
         9,0.55292},{6,9,0.599058},{7,9,1.0424},{1,10,-1.64471},{
         2,10,2.62318},{3,10,1.51706},{4,10,1.68971},{5,10,0.899632},{
         6,10,-1.15408},{7,10,-0.157527},{1,11,-0.186235},{
       2,11,1.39747},{3,11,1.89406},{4,11,-0.434147},{5,11,-1.88703},{6,11,
         2.23624},{7,11,-3.17978},{8,13,1.83855},{9,13,-0.912118},{10,
         13,4.37321},{11,13,3.82373},{12,13,-5.73714}};

In[3]:=
plotHinton[data,1,7];

plotHinton[data, 8, 12];

Hope this helps,
/J.M.


  • Prev by Date: Re: Types in Mathematica, a practical example
  • Next by Date: Re: Simple task with Mathematica
  • Previous by thread: Re: Hinton diagrams
  • Next by thread: PDF/Illustrator Oddity