[Date Index]
[Thread Index]
[Author Index]
Re: Hinton diagrams
*To*: mathgroup at smc.vnet.net
*Subject*: [mg63166] Re: [mg63052] Hinton diagrams
*From*: Sseziwa Mukasa <mukasa at jeol.com>
*Date*: Fri, 16 Dec 2005 07:22:22 -0500 (EST)
*References*: <200512120325.WAA10001@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
On Dec 11, 2005, at 10:25 PM, 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.
I've never done anything similar but here is my attempt
Options[hinton]={AspectRatio->1,Background->GrayLevel[0.5],
colorFunction->GrayLevel[UnitStep[#]]&};
hinton[data_,from_List,to_List,opts___?OptionsQ]:=
Block[{aspectratio,background,
colorfunction},{aspectratio,background,
colorfunction}={AspectRatio,Background,
colorFunction}/.{opts}/.Options[hinton];
GraphicsArray[
Prepend[MapThread[{#1,
Sequence@@#2}&,{Graphics[{Text[#,{0,0}]},
Background->background,AspectRatio->aspectratio]&/@
to,Partition[
Block[{d=Select[data,MemberQ[from,#[[1]]]&&MemberQ[to,#
[[2]]]&],
m},m=Max[Abs[d[[All,3]]]];
With[{mag=#[[3]]/m,
bottomleft=Table[0.5 (1-Abs[#[[3]]/m]),{2}],
topright=Table[0.5 (1+Abs[#[[3]]/m]),{2}]},
Graphics[{colorfunction[mag],
Rectangle[Scaled[bottomleft],Scaled
[topright]]},
Background->background,
AspectRatio->aspectratio]]&/@d],Length
[from]]}],
Graphics[{Text[#,{0,0}]},Background->background,
AspectRatio->aspectratio]&/@Prepend[from," "]],
GraphicsSpacing->0]]
It seems from your data that there are no connections between the
first layer and unit 12, is this what the diagram is supposed to
demonstrate? If so my code won't work, although you can easily test
for that case by seeing if MemberQ[Select[data,MemberQ[<layer>,#[[1]]]
&][[All,2]],unit] is true, where <layer> is the list of units in a
layer and add appropriate entries for 0 weight connections to the
data. At any rate to use my function with your data, the following
expressions return the Hinton diagrams for the first and second
layers respectively:
Show[hinton[Join[data,Table[{i,12,0},{i,7}]],Range[7],Range[8,12]]];
Show[hinton[Join[data,Table[{i,12,0},{i,7}]],Range[8,12],{13}]];
I added options to hinton to allow for different coloring functions
based on magnitude (colorfunction->Graylevel[UnitStep[#]]& is the
default) and different aspect ratios and background colors.
Regards,
Ssezi
Prev by Date:
**Re: Re: Mathematica Programmer vs. Programming in Mathematica**
Next by Date:
**Re: Can I define 0^0 to be 1 for a notebook**
Previous by thread:
**Hinton diagrams**
Next by thread:
**Re: Hinton diagrams**
| |