
A bit different function that always places vertices symmetrically:
LayersGraph[layers_]:=
Module[{
uni=Table[Unique[],#]&/@layers,
coor=Flatten[Table[{k,#}&/@(Range[#]-Mean[Range[#]]&/@layers)[[k]],{k,Length[layers]}],1]},
Graph[
Flatten[uni],
Flatten[Outer[Rule,#1,#2]&@@@Partition[uni,2,1]],
VertexCoordinates->coor,
EdgeShapeFunction->"Line",VertexSize->.3]
]
Usage that gives the image above:
LayersGraph[{2, 2, 3, 7, 2, 5, 3, 4, 1}]
A bit different version would go like:
LayersGraph[layers_]:=
Module[{
vert=TakeList[Range[Total[layers]],layers],
coor=Flatten[Table[{k,#}&/@(Range[#]-Mean[Range[#]]&/@layers)[[k]],{k,Length[layers]}],1]},
Graph[
Flatten[vert],
Flatten[Outer[Rule,#1,#2]&@@@Partition[vert,2,1]],
VertexCoordinates->coor,
EdgeShapeFunction->"Line",GraphStyle->"SmallNetwork"]
]
LayersGraph[{2, 2, 3, 7, 2, 5, 3, 4, 1}]
