Drawing neural network with tikz












16














I'm trying to draw a neural network diagram with tikz. I found this code online:



begin{figure}[htp]
centering
begin{tikzpicture}[
plain/.style={
draw=none,
fill=none,
},
net/.style={
matrix of nodes,
nodes={
draw,
circle,
inner sep=8.5pt
},
nodes in empty cells,
column sep=0.6cm,
row sep=-11pt
},
>=latex
]
matrix[net] (mat)
{
|[plain]| parbox{1cm}{centering Input\layer} & |[plain]| parbox{1cm}{centering Hidden\layer} & |[plain]| parbox{1cm}{centering Output\layer} \
& |[plain]| \
|[plain]| & \
& |[plain]| \
|[plain]| & |[plain]| \
& & \
|[plain]| & |[plain]| \
& |[plain]| \
|[plain]| & \
& |[plain]| \
};
foreach ai [count=mi ]in {2,4,...,10}
draw[<-] (mat-ai-1) -- node[above] {Imi} +(-1cm,0);
foreach ai in {2,4,...,10}
{foreach aii in {3,6,9}
draw[->] (mat-ai-1) -- (mat-aii-2);
}
foreach ai in {3,6,9}
draw[->] (mat-ai-2) -- (mat-6-3);
draw[->] (mat-6-3) -- node[above] {O1} +(1cm,0);
end{tikzpicture}

caption{ANN diagram for Speed Sign recognition.}
label{fig_m_3}
end{figure}


It produces the following image:



enter image description here



It has 5 input nodes but I want to generalize this drawing by having n nodes in each of the layers. So in input layer, number of node shown will be 4 with vertical '...' in middle, the hidden layer would contain 3 nodes with vertical '...' in middle and output would have 2 nodes with vertical '...' in middle. I want to maintain their conical shape. Something like this:



enter image description here



It is a really bad drawing, sorry about that, one can now imagine how bad I must be with tikz. The dots in middle are actually fully filled, in my drawing they are hollow. Any help or advice would be appreciated.










share|improve this question
























  • Related/duplicate: tex.stackexchange.com/questions/40718/…
    – morbusg
    Jan 14 '14 at 8:42


















16














I'm trying to draw a neural network diagram with tikz. I found this code online:



begin{figure}[htp]
centering
begin{tikzpicture}[
plain/.style={
draw=none,
fill=none,
},
net/.style={
matrix of nodes,
nodes={
draw,
circle,
inner sep=8.5pt
},
nodes in empty cells,
column sep=0.6cm,
row sep=-11pt
},
>=latex
]
matrix[net] (mat)
{
|[plain]| parbox{1cm}{centering Input\layer} & |[plain]| parbox{1cm}{centering Hidden\layer} & |[plain]| parbox{1cm}{centering Output\layer} \
& |[plain]| \
|[plain]| & \
& |[plain]| \
|[plain]| & |[plain]| \
& & \
|[plain]| & |[plain]| \
& |[plain]| \
|[plain]| & \
& |[plain]| \
};
foreach ai [count=mi ]in {2,4,...,10}
draw[<-] (mat-ai-1) -- node[above] {Imi} +(-1cm,0);
foreach ai in {2,4,...,10}
{foreach aii in {3,6,9}
draw[->] (mat-ai-1) -- (mat-aii-2);
}
foreach ai in {3,6,9}
draw[->] (mat-ai-2) -- (mat-6-3);
draw[->] (mat-6-3) -- node[above] {O1} +(1cm,0);
end{tikzpicture}

caption{ANN diagram for Speed Sign recognition.}
label{fig_m_3}
end{figure}


It produces the following image:



enter image description here



It has 5 input nodes but I want to generalize this drawing by having n nodes in each of the layers. So in input layer, number of node shown will be 4 with vertical '...' in middle, the hidden layer would contain 3 nodes with vertical '...' in middle and output would have 2 nodes with vertical '...' in middle. I want to maintain their conical shape. Something like this:



enter image description here



It is a really bad drawing, sorry about that, one can now imagine how bad I must be with tikz. The dots in middle are actually fully filled, in my drawing they are hollow. Any help or advice would be appreciated.










share|improve this question
























  • Related/duplicate: tex.stackexchange.com/questions/40718/…
    – morbusg
    Jan 14 '14 at 8:42
















16












16








16


16





I'm trying to draw a neural network diagram with tikz. I found this code online:



begin{figure}[htp]
centering
begin{tikzpicture}[
plain/.style={
draw=none,
fill=none,
},
net/.style={
matrix of nodes,
nodes={
draw,
circle,
inner sep=8.5pt
},
nodes in empty cells,
column sep=0.6cm,
row sep=-11pt
},
>=latex
]
matrix[net] (mat)
{
|[plain]| parbox{1cm}{centering Input\layer} & |[plain]| parbox{1cm}{centering Hidden\layer} & |[plain]| parbox{1cm}{centering Output\layer} \
& |[plain]| \
|[plain]| & \
& |[plain]| \
|[plain]| & |[plain]| \
& & \
|[plain]| & |[plain]| \
& |[plain]| \
|[plain]| & \
& |[plain]| \
};
foreach ai [count=mi ]in {2,4,...,10}
draw[<-] (mat-ai-1) -- node[above] {Imi} +(-1cm,0);
foreach ai in {2,4,...,10}
{foreach aii in {3,6,9}
draw[->] (mat-ai-1) -- (mat-aii-2);
}
foreach ai in {3,6,9}
draw[->] (mat-ai-2) -- (mat-6-3);
draw[->] (mat-6-3) -- node[above] {O1} +(1cm,0);
end{tikzpicture}

caption{ANN diagram for Speed Sign recognition.}
label{fig_m_3}
end{figure}


It produces the following image:



enter image description here



It has 5 input nodes but I want to generalize this drawing by having n nodes in each of the layers. So in input layer, number of node shown will be 4 with vertical '...' in middle, the hidden layer would contain 3 nodes with vertical '...' in middle and output would have 2 nodes with vertical '...' in middle. I want to maintain their conical shape. Something like this:



enter image description here



It is a really bad drawing, sorry about that, one can now imagine how bad I must be with tikz. The dots in middle are actually fully filled, in my drawing they are hollow. Any help or advice would be appreciated.










share|improve this question















I'm trying to draw a neural network diagram with tikz. I found this code online:



begin{figure}[htp]
centering
begin{tikzpicture}[
plain/.style={
draw=none,
fill=none,
},
net/.style={
matrix of nodes,
nodes={
draw,
circle,
inner sep=8.5pt
},
nodes in empty cells,
column sep=0.6cm,
row sep=-11pt
},
>=latex
]
matrix[net] (mat)
{
|[plain]| parbox{1cm}{centering Input\layer} & |[plain]| parbox{1cm}{centering Hidden\layer} & |[plain]| parbox{1cm}{centering Output\layer} \
& |[plain]| \
|[plain]| & \
& |[plain]| \
|[plain]| & |[plain]| \
& & \
|[plain]| & |[plain]| \
& |[plain]| \
|[plain]| & \
& |[plain]| \
};
foreach ai [count=mi ]in {2,4,...,10}
draw[<-] (mat-ai-1) -- node[above] {Imi} +(-1cm,0);
foreach ai in {2,4,...,10}
{foreach aii in {3,6,9}
draw[->] (mat-ai-1) -- (mat-aii-2);
}
foreach ai in {3,6,9}
draw[->] (mat-ai-2) -- (mat-6-3);
draw[->] (mat-6-3) -- node[above] {O1} +(1cm,0);
end{tikzpicture}

caption{ANN diagram for Speed Sign recognition.}
label{fig_m_3}
end{figure}


It produces the following image:



enter image description here



It has 5 input nodes but I want to generalize this drawing by having n nodes in each of the layers. So in input layer, number of node shown will be 4 with vertical '...' in middle, the hidden layer would contain 3 nodes with vertical '...' in middle and output would have 2 nodes with vertical '...' in middle. I want to maintain their conical shape. Something like this:



enter image description here



It is a really bad drawing, sorry about that, one can now imagine how bad I must be with tikz. The dots in middle are actually fully filled, in my drawing they are hollow. Any help or advice would be appreciated.







tikz-pgf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 18 '18 at 15:37









SRhm

1033




1033










asked Jan 14 '14 at 4:38









Shivam

2862311




2862311












  • Related/duplicate: tex.stackexchange.com/questions/40718/…
    – morbusg
    Jan 14 '14 at 8:42




















  • Related/duplicate: tex.stackexchange.com/questions/40718/…
    – morbusg
    Jan 14 '14 at 8:42


















Related/duplicate: tex.stackexchange.com/questions/40718/…
– morbusg
Jan 14 '14 at 8:42






Related/duplicate: tex.stackexchange.com/questions/40718/…
– morbusg
Jan 14 '14 at 8:42












4 Answers
4






active

oldest

votes


















16














Here, we a have a festival of foreach:



documentclass[border=0.125cm]{standalone}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}

tikzset{%
every neuron/.style={
circle,
draw,
minimum size=1cm
},
neuron missing/.style={
draw=none,
scale=4,
text height=0.333cm,
execute at begin node=color{black}$vdots$
},
}

begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]

foreach m/l [count=y] in {1,2,3,missing,4}
node [every neuron/.try, neuron m/.try] (input-m) at (0,2.5-y) {};

foreach m [count=y] in {1,missing,2}
node [every neuron/.try, neuron m/.try ] (hidden-m) at (2,2-y*1.25) {};

foreach m [count=y] in {1,missing,2}
node [every neuron/.try, neuron m/.try ] (output-m) at (4,1.5-y) {};

foreach l [count=i] in {1,2,3,n}
draw [<-] (input-i) -- ++(-1,0)
node [above, midway] {$I_l$};

foreach l [count=i] in {1,n}
node [above] at (hidden-i.north) {$H_l$};

foreach l [count=i] in {1,n}
draw [->] (output-i) -- ++(1,0)
node [above, midway] {$O_l$};

foreach i in {1,...,4}
foreach j in {1,...,2}
draw [->] (input-i) -- (hidden-j);

foreach i in {1,...,2}
foreach j in {1,...,2}
draw [->] (hidden-i) -- (output-j);

foreach l [count=x from 0] in {Input, Hidden, Ouput}
node [align=center, above] at (x*2,2) {l \ layer};

end{tikzpicture}

end{document}


Although it seems unwise to have n denote the number of nodes in each layer when they could be different and the arrangement of the diagram suggests they are not.



enter image description here






share|improve this answer





















  • Both the answers are perfect and I learned from both. But I had to choose one. I easily changed this code to my requirements. Thanks.
    – Shivam
    Jan 14 '14 at 16:59










  • And how would one have dots to show that there are many hidden layers?
    – patapouf_ai
    Apr 8 '17 at 17:20










  • Very minor comment: I guess the first foreach does not need the l because it seems not to be used.
    – marmot
    Mar 29 '18 at 2:29



















7














This is a solution where a dot with fully filled with black circle, whose size is changeable via minimum size=xx <dimension>, is defined as a style.



enter image description here



Code



documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{tikz,pgfplots,pgf}
usetikzlibrary{matrix,shapes,arrows,positioning}
begin{document}

begin{figure}[htp]
centering
begin{tikzpicture}[
plain/.style={
draw=none,
fill=none,
},
dot/.style={draw,shape=circle,minimum size=3pt,inner sep=0,fill=black
},
net/.style={
matrix of nodes,
nodes={
draw,
circle,
inner sep=8.5pt
},
nodes in empty cells,
column sep=0.6cm,
row sep=-11pt
},
>=latex
]
matrix[net] (mat)
{
|[plain]| parbox{1cm}{centering Input\layer}
& |[plain]| parbox{1cm}{centering Hidden\layer}
& |[plain]| parbox{1cm}{centering Output\layer} \
& |[plain]| \
|[plain]| & & |[plain]| \
& |[plain]| & \
|[plain]| & |[dot]| \
& |[plain]| & |[dot]| \
|[plain]| & |[dot]| & |[plain]| \
|[dot]| & |[plain]| & |[dot]| \
|[dot]| & |[dot]| & |[plain]| \
|[dot]| & |[plain]| & \
|[plain]| & & |[plain]| \
& |[plain]| \
};
foreach ai/mi in {2/I1,4/I2,6/I3,12/In}
draw[<-] (mat-ai-1) -- node[above] {mi} +(-1cm,0);
foreach ai in {2,4,6,12}
{foreach aii/mii in {3/H1,11/Hn}
draw[->] (mat-ai-1) -- (mat-aii-2) node[yshift=0.6cm] {mii};
}
foreach ai in {3,11}
{ draw[->] (mat-ai-2) -- (mat-4-3);
draw[->] (mat-4-3) -- node[above] {O1} +(1cm,0);}
foreach ai in {3,11}
{ draw[->] (mat-ai-2) -- (mat-10-3);
draw[->] (mat-10-3) -- node[above] {On} +(1cm,0);}
end{tikzpicture}

caption{ANN diagram for Speed Sign recognition.}
label{fig_m_3}
end{figure}

end{document}





share|improve this answer























  • And how would one have dots to show that there are many hidden layers?
    – patapouf_ai
    Apr 8 '17 at 17:20



















1














I know that this is an old question. But I just found this code by Kjell Magne Fauske on TeXample about a neural network and I think it can be helpful to future readers since it's easy to modify.



example



documentclass{article}

usepackage{tikz}
begin{document}
pagestyle{empty}

deflayersep{2.5cm}

begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=layersep]
tikzstyle{every pin edge}=[<-,shorten <=1pt]
tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
tikzstyle{input neuron}=[neuron, fill=green!50];
tikzstyle{output neuron}=[neuron, fill=red!50];
tikzstyle{hidden neuron}=[neuron, fill=blue!50];
tikzstyle{annot} = [text width=4em, text centered]

% Draw the input layer nodes
foreach name / y in {1,...,4}
% This is the same as writing foreach name / y in {1/1,2/2,3/3,4/4}
node[input neuron, pin=left:Input #y] (I-name) at (0,-y) {};

% Draw the hidden layer nodes
foreach name / y in {1,...,5}
path[yshift=0.5cm]
node[hidden neuron] (H-name) at (layersep,-y cm) {};

% Draw the output layer node
node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-3] (O) {};

% Connect every node in the input layer with every node in the
% hidden layer.
foreach source in {1,...,4}
foreach dest in {1,...,5}
path (I-source) edge (H-dest);

% Connect every node in the hidden layer with the output layer
foreach source in {1,...,5}
path (H-source) edge (O);

% Annotate the layers
node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
node[annot,left of=hl] {Input layer};
node[annot,right of=hl] {Output layer};
end{tikzpicture}
% End of code
end{document}





share|improve this answer





























    0














    I found this package neuralnetwork, made by Mark K Cowan, which makes drawing neural networks pretty simple. For example:



    documentclass{standalone}

    usepackage{neuralnetwork}

    begin{document}
    begin{neuralnetwork}[height=4]
    newcommand{x}[2]{$x_#2$}
    newcommand{y}[2]{$hat{y}_#2$}
    newcommand{hfirst}[2]{small $h^{(1)}_#2$}
    newcommand{hsecond}[2]{small $h^{(2)}_#2$}
    inputlayer[count=3, bias=true, title=Input\layer, text=x]
    hiddenlayer[count=4, bias=false, title=Hidden\layer 1, text=hfirst] linklayers
    hiddenlayer[count=3, bias=false, title=Hidden\layer 2, text=hsecond] linklayers
    outputlayer[count=2, title=Output\layer, text=y] linklayers
    end{neuralnetwork}
    end{document}


    enter image description here






    share|improve this answer























    • The question really seems to be about the dots, although your code is very elegant.
      – Benjamin McKay
      Dec 12 '18 at 9:09











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f153957%2fdrawing-neural-network-with-tikz%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    16














    Here, we a have a festival of foreach:



    documentclass[border=0.125cm]{standalone}
    usepackage{tikz}
    usetikzlibrary{positioning}
    begin{document}

    tikzset{%
    every neuron/.style={
    circle,
    draw,
    minimum size=1cm
    },
    neuron missing/.style={
    draw=none,
    scale=4,
    text height=0.333cm,
    execute at begin node=color{black}$vdots$
    },
    }

    begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]

    foreach m/l [count=y] in {1,2,3,missing,4}
    node [every neuron/.try, neuron m/.try] (input-m) at (0,2.5-y) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (hidden-m) at (2,2-y*1.25) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (output-m) at (4,1.5-y) {};

    foreach l [count=i] in {1,2,3,n}
    draw [<-] (input-i) -- ++(-1,0)
    node [above, midway] {$I_l$};

    foreach l [count=i] in {1,n}
    node [above] at (hidden-i.north) {$H_l$};

    foreach l [count=i] in {1,n}
    draw [->] (output-i) -- ++(1,0)
    node [above, midway] {$O_l$};

    foreach i in {1,...,4}
    foreach j in {1,...,2}
    draw [->] (input-i) -- (hidden-j);

    foreach i in {1,...,2}
    foreach j in {1,...,2}
    draw [->] (hidden-i) -- (output-j);

    foreach l [count=x from 0] in {Input, Hidden, Ouput}
    node [align=center, above] at (x*2,2) {l \ layer};

    end{tikzpicture}

    end{document}


    Although it seems unwise to have n denote the number of nodes in each layer when they could be different and the arrangement of the diagram suggests they are not.



    enter image description here






    share|improve this answer





















    • Both the answers are perfect and I learned from both. But I had to choose one. I easily changed this code to my requirements. Thanks.
      – Shivam
      Jan 14 '14 at 16:59










    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20










    • Very minor comment: I guess the first foreach does not need the l because it seems not to be used.
      – marmot
      Mar 29 '18 at 2:29
















    16














    Here, we a have a festival of foreach:



    documentclass[border=0.125cm]{standalone}
    usepackage{tikz}
    usetikzlibrary{positioning}
    begin{document}

    tikzset{%
    every neuron/.style={
    circle,
    draw,
    minimum size=1cm
    },
    neuron missing/.style={
    draw=none,
    scale=4,
    text height=0.333cm,
    execute at begin node=color{black}$vdots$
    },
    }

    begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]

    foreach m/l [count=y] in {1,2,3,missing,4}
    node [every neuron/.try, neuron m/.try] (input-m) at (0,2.5-y) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (hidden-m) at (2,2-y*1.25) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (output-m) at (4,1.5-y) {};

    foreach l [count=i] in {1,2,3,n}
    draw [<-] (input-i) -- ++(-1,0)
    node [above, midway] {$I_l$};

    foreach l [count=i] in {1,n}
    node [above] at (hidden-i.north) {$H_l$};

    foreach l [count=i] in {1,n}
    draw [->] (output-i) -- ++(1,0)
    node [above, midway] {$O_l$};

    foreach i in {1,...,4}
    foreach j in {1,...,2}
    draw [->] (input-i) -- (hidden-j);

    foreach i in {1,...,2}
    foreach j in {1,...,2}
    draw [->] (hidden-i) -- (output-j);

    foreach l [count=x from 0] in {Input, Hidden, Ouput}
    node [align=center, above] at (x*2,2) {l \ layer};

    end{tikzpicture}

    end{document}


    Although it seems unwise to have n denote the number of nodes in each layer when they could be different and the arrangement of the diagram suggests they are not.



    enter image description here






    share|improve this answer





















    • Both the answers are perfect and I learned from both. But I had to choose one. I easily changed this code to my requirements. Thanks.
      – Shivam
      Jan 14 '14 at 16:59










    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20










    • Very minor comment: I guess the first foreach does not need the l because it seems not to be used.
      – marmot
      Mar 29 '18 at 2:29














    16












    16








    16






    Here, we a have a festival of foreach:



    documentclass[border=0.125cm]{standalone}
    usepackage{tikz}
    usetikzlibrary{positioning}
    begin{document}

    tikzset{%
    every neuron/.style={
    circle,
    draw,
    minimum size=1cm
    },
    neuron missing/.style={
    draw=none,
    scale=4,
    text height=0.333cm,
    execute at begin node=color{black}$vdots$
    },
    }

    begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]

    foreach m/l [count=y] in {1,2,3,missing,4}
    node [every neuron/.try, neuron m/.try] (input-m) at (0,2.5-y) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (hidden-m) at (2,2-y*1.25) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (output-m) at (4,1.5-y) {};

    foreach l [count=i] in {1,2,3,n}
    draw [<-] (input-i) -- ++(-1,0)
    node [above, midway] {$I_l$};

    foreach l [count=i] in {1,n}
    node [above] at (hidden-i.north) {$H_l$};

    foreach l [count=i] in {1,n}
    draw [->] (output-i) -- ++(1,0)
    node [above, midway] {$O_l$};

    foreach i in {1,...,4}
    foreach j in {1,...,2}
    draw [->] (input-i) -- (hidden-j);

    foreach i in {1,...,2}
    foreach j in {1,...,2}
    draw [->] (hidden-i) -- (output-j);

    foreach l [count=x from 0] in {Input, Hidden, Ouput}
    node [align=center, above] at (x*2,2) {l \ layer};

    end{tikzpicture}

    end{document}


    Although it seems unwise to have n denote the number of nodes in each layer when they could be different and the arrangement of the diagram suggests they are not.



    enter image description here






    share|improve this answer












    Here, we a have a festival of foreach:



    documentclass[border=0.125cm]{standalone}
    usepackage{tikz}
    usetikzlibrary{positioning}
    begin{document}

    tikzset{%
    every neuron/.style={
    circle,
    draw,
    minimum size=1cm
    },
    neuron missing/.style={
    draw=none,
    scale=4,
    text height=0.333cm,
    execute at begin node=color{black}$vdots$
    },
    }

    begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]

    foreach m/l [count=y] in {1,2,3,missing,4}
    node [every neuron/.try, neuron m/.try] (input-m) at (0,2.5-y) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (hidden-m) at (2,2-y*1.25) {};

    foreach m [count=y] in {1,missing,2}
    node [every neuron/.try, neuron m/.try ] (output-m) at (4,1.5-y) {};

    foreach l [count=i] in {1,2,3,n}
    draw [<-] (input-i) -- ++(-1,0)
    node [above, midway] {$I_l$};

    foreach l [count=i] in {1,n}
    node [above] at (hidden-i.north) {$H_l$};

    foreach l [count=i] in {1,n}
    draw [->] (output-i) -- ++(1,0)
    node [above, midway] {$O_l$};

    foreach i in {1,...,4}
    foreach j in {1,...,2}
    draw [->] (input-i) -- (hidden-j);

    foreach i in {1,...,2}
    foreach j in {1,...,2}
    draw [->] (hidden-i) -- (output-j);

    foreach l [count=x from 0] in {Input, Hidden, Ouput}
    node [align=center, above] at (x*2,2) {l \ layer};

    end{tikzpicture}

    end{document}


    Although it seems unwise to have n denote the number of nodes in each layer when they could be different and the arrangement of the diagram suggests they are not.



    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 14 '14 at 8:51









    Mark Wibrow

    61.6k4112176




    61.6k4112176












    • Both the answers are perfect and I learned from both. But I had to choose one. I easily changed this code to my requirements. Thanks.
      – Shivam
      Jan 14 '14 at 16:59










    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20










    • Very minor comment: I guess the first foreach does not need the l because it seems not to be used.
      – marmot
      Mar 29 '18 at 2:29


















    • Both the answers are perfect and I learned from both. But I had to choose one. I easily changed this code to my requirements. Thanks.
      – Shivam
      Jan 14 '14 at 16:59










    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20










    • Very minor comment: I guess the first foreach does not need the l because it seems not to be used.
      – marmot
      Mar 29 '18 at 2:29
















    Both the answers are perfect and I learned from both. But I had to choose one. I easily changed this code to my requirements. Thanks.
    – Shivam
    Jan 14 '14 at 16:59




    Both the answers are perfect and I learned from both. But I had to choose one. I easily changed this code to my requirements. Thanks.
    – Shivam
    Jan 14 '14 at 16:59












    And how would one have dots to show that there are many hidden layers?
    – patapouf_ai
    Apr 8 '17 at 17:20




    And how would one have dots to show that there are many hidden layers?
    – patapouf_ai
    Apr 8 '17 at 17:20












    Very minor comment: I guess the first foreach does not need the l because it seems not to be used.
    – marmot
    Mar 29 '18 at 2:29




    Very minor comment: I guess the first foreach does not need the l because it seems not to be used.
    – marmot
    Mar 29 '18 at 2:29











    7














    This is a solution where a dot with fully filled with black circle, whose size is changeable via minimum size=xx <dimension>, is defined as a style.



    enter image description here



    Code



    documentclass{article}
    usepackage[margin=1cm]{geometry}
    usepackage{tikz,pgfplots,pgf}
    usetikzlibrary{matrix,shapes,arrows,positioning}
    begin{document}

    begin{figure}[htp]
    centering
    begin{tikzpicture}[
    plain/.style={
    draw=none,
    fill=none,
    },
    dot/.style={draw,shape=circle,minimum size=3pt,inner sep=0,fill=black
    },
    net/.style={
    matrix of nodes,
    nodes={
    draw,
    circle,
    inner sep=8.5pt
    },
    nodes in empty cells,
    column sep=0.6cm,
    row sep=-11pt
    },
    >=latex
    ]
    matrix[net] (mat)
    {
    |[plain]| parbox{1cm}{centering Input\layer}
    & |[plain]| parbox{1cm}{centering Hidden\layer}
    & |[plain]| parbox{1cm}{centering Output\layer} \
    & |[plain]| \
    |[plain]| & & |[plain]| \
    & |[plain]| & \
    |[plain]| & |[dot]| \
    & |[plain]| & |[dot]| \
    |[plain]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & |[dot]| \
    |[dot]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & \
    |[plain]| & & |[plain]| \
    & |[plain]| \
    };
    foreach ai/mi in {2/I1,4/I2,6/I3,12/In}
    draw[<-] (mat-ai-1) -- node[above] {mi} +(-1cm,0);
    foreach ai in {2,4,6,12}
    {foreach aii/mii in {3/H1,11/Hn}
    draw[->] (mat-ai-1) -- (mat-aii-2) node[yshift=0.6cm] {mii};
    }
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-4-3);
    draw[->] (mat-4-3) -- node[above] {O1} +(1cm,0);}
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-10-3);
    draw[->] (mat-10-3) -- node[above] {On} +(1cm,0);}
    end{tikzpicture}

    caption{ANN diagram for Speed Sign recognition.}
    label{fig_m_3}
    end{figure}

    end{document}





    share|improve this answer























    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20
















    7














    This is a solution where a dot with fully filled with black circle, whose size is changeable via minimum size=xx <dimension>, is defined as a style.



    enter image description here



    Code



    documentclass{article}
    usepackage[margin=1cm]{geometry}
    usepackage{tikz,pgfplots,pgf}
    usetikzlibrary{matrix,shapes,arrows,positioning}
    begin{document}

    begin{figure}[htp]
    centering
    begin{tikzpicture}[
    plain/.style={
    draw=none,
    fill=none,
    },
    dot/.style={draw,shape=circle,minimum size=3pt,inner sep=0,fill=black
    },
    net/.style={
    matrix of nodes,
    nodes={
    draw,
    circle,
    inner sep=8.5pt
    },
    nodes in empty cells,
    column sep=0.6cm,
    row sep=-11pt
    },
    >=latex
    ]
    matrix[net] (mat)
    {
    |[plain]| parbox{1cm}{centering Input\layer}
    & |[plain]| parbox{1cm}{centering Hidden\layer}
    & |[plain]| parbox{1cm}{centering Output\layer} \
    & |[plain]| \
    |[plain]| & & |[plain]| \
    & |[plain]| & \
    |[plain]| & |[dot]| \
    & |[plain]| & |[dot]| \
    |[plain]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & |[dot]| \
    |[dot]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & \
    |[plain]| & & |[plain]| \
    & |[plain]| \
    };
    foreach ai/mi in {2/I1,4/I2,6/I3,12/In}
    draw[<-] (mat-ai-1) -- node[above] {mi} +(-1cm,0);
    foreach ai in {2,4,6,12}
    {foreach aii/mii in {3/H1,11/Hn}
    draw[->] (mat-ai-1) -- (mat-aii-2) node[yshift=0.6cm] {mii};
    }
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-4-3);
    draw[->] (mat-4-3) -- node[above] {O1} +(1cm,0);}
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-10-3);
    draw[->] (mat-10-3) -- node[above] {On} +(1cm,0);}
    end{tikzpicture}

    caption{ANN diagram for Speed Sign recognition.}
    label{fig_m_3}
    end{figure}

    end{document}





    share|improve this answer























    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20














    7












    7








    7






    This is a solution where a dot with fully filled with black circle, whose size is changeable via minimum size=xx <dimension>, is defined as a style.



    enter image description here



    Code



    documentclass{article}
    usepackage[margin=1cm]{geometry}
    usepackage{tikz,pgfplots,pgf}
    usetikzlibrary{matrix,shapes,arrows,positioning}
    begin{document}

    begin{figure}[htp]
    centering
    begin{tikzpicture}[
    plain/.style={
    draw=none,
    fill=none,
    },
    dot/.style={draw,shape=circle,minimum size=3pt,inner sep=0,fill=black
    },
    net/.style={
    matrix of nodes,
    nodes={
    draw,
    circle,
    inner sep=8.5pt
    },
    nodes in empty cells,
    column sep=0.6cm,
    row sep=-11pt
    },
    >=latex
    ]
    matrix[net] (mat)
    {
    |[plain]| parbox{1cm}{centering Input\layer}
    & |[plain]| parbox{1cm}{centering Hidden\layer}
    & |[plain]| parbox{1cm}{centering Output\layer} \
    & |[plain]| \
    |[plain]| & & |[plain]| \
    & |[plain]| & \
    |[plain]| & |[dot]| \
    & |[plain]| & |[dot]| \
    |[plain]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & |[dot]| \
    |[dot]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & \
    |[plain]| & & |[plain]| \
    & |[plain]| \
    };
    foreach ai/mi in {2/I1,4/I2,6/I3,12/In}
    draw[<-] (mat-ai-1) -- node[above] {mi} +(-1cm,0);
    foreach ai in {2,4,6,12}
    {foreach aii/mii in {3/H1,11/Hn}
    draw[->] (mat-ai-1) -- (mat-aii-2) node[yshift=0.6cm] {mii};
    }
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-4-3);
    draw[->] (mat-4-3) -- node[above] {O1} +(1cm,0);}
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-10-3);
    draw[->] (mat-10-3) -- node[above] {On} +(1cm,0);}
    end{tikzpicture}

    caption{ANN diagram for Speed Sign recognition.}
    label{fig_m_3}
    end{figure}

    end{document}





    share|improve this answer














    This is a solution where a dot with fully filled with black circle, whose size is changeable via minimum size=xx <dimension>, is defined as a style.



    enter image description here



    Code



    documentclass{article}
    usepackage[margin=1cm]{geometry}
    usepackage{tikz,pgfplots,pgf}
    usetikzlibrary{matrix,shapes,arrows,positioning}
    begin{document}

    begin{figure}[htp]
    centering
    begin{tikzpicture}[
    plain/.style={
    draw=none,
    fill=none,
    },
    dot/.style={draw,shape=circle,minimum size=3pt,inner sep=0,fill=black
    },
    net/.style={
    matrix of nodes,
    nodes={
    draw,
    circle,
    inner sep=8.5pt
    },
    nodes in empty cells,
    column sep=0.6cm,
    row sep=-11pt
    },
    >=latex
    ]
    matrix[net] (mat)
    {
    |[plain]| parbox{1cm}{centering Input\layer}
    & |[plain]| parbox{1cm}{centering Hidden\layer}
    & |[plain]| parbox{1cm}{centering Output\layer} \
    & |[plain]| \
    |[plain]| & & |[plain]| \
    & |[plain]| & \
    |[plain]| & |[dot]| \
    & |[plain]| & |[dot]| \
    |[plain]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & |[dot]| \
    |[dot]| & |[dot]| & |[plain]| \
    |[dot]| & |[plain]| & \
    |[plain]| & & |[plain]| \
    & |[plain]| \
    };
    foreach ai/mi in {2/I1,4/I2,6/I3,12/In}
    draw[<-] (mat-ai-1) -- node[above] {mi} +(-1cm,0);
    foreach ai in {2,4,6,12}
    {foreach aii/mii in {3/H1,11/Hn}
    draw[->] (mat-ai-1) -- (mat-aii-2) node[yshift=0.6cm] {mii};
    }
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-4-3);
    draw[->] (mat-4-3) -- node[above] {O1} +(1cm,0);}
    foreach ai in {3,11}
    { draw[->] (mat-ai-2) -- (mat-10-3);
    draw[->] (mat-10-3) -- node[above] {On} +(1cm,0);}
    end{tikzpicture}

    caption{ANN diagram for Speed Sign recognition.}
    label{fig_m_3}
    end{figure}

    end{document}






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 14 '14 at 8:24

























    answered Jan 14 '14 at 8:16









    Jesse

    26.3k72577




    26.3k72577












    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20


















    • And how would one have dots to show that there are many hidden layers?
      – patapouf_ai
      Apr 8 '17 at 17:20
















    And how would one have dots to show that there are many hidden layers?
    – patapouf_ai
    Apr 8 '17 at 17:20




    And how would one have dots to show that there are many hidden layers?
    – patapouf_ai
    Apr 8 '17 at 17:20











    1














    I know that this is an old question. But I just found this code by Kjell Magne Fauske on TeXample about a neural network and I think it can be helpful to future readers since it's easy to modify.



    example



    documentclass{article}

    usepackage{tikz}
    begin{document}
    pagestyle{empty}

    deflayersep{2.5cm}

    begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=layersep]
    tikzstyle{every pin edge}=[<-,shorten <=1pt]
    tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
    tikzstyle{input neuron}=[neuron, fill=green!50];
    tikzstyle{output neuron}=[neuron, fill=red!50];
    tikzstyle{hidden neuron}=[neuron, fill=blue!50];
    tikzstyle{annot} = [text width=4em, text centered]

    % Draw the input layer nodes
    foreach name / y in {1,...,4}
    % This is the same as writing foreach name / y in {1/1,2/2,3/3,4/4}
    node[input neuron, pin=left:Input #y] (I-name) at (0,-y) {};

    % Draw the hidden layer nodes
    foreach name / y in {1,...,5}
    path[yshift=0.5cm]
    node[hidden neuron] (H-name) at (layersep,-y cm) {};

    % Draw the output layer node
    node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-3] (O) {};

    % Connect every node in the input layer with every node in the
    % hidden layer.
    foreach source in {1,...,4}
    foreach dest in {1,...,5}
    path (I-source) edge (H-dest);

    % Connect every node in the hidden layer with the output layer
    foreach source in {1,...,5}
    path (H-source) edge (O);

    % Annotate the layers
    node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
    node[annot,left of=hl] {Input layer};
    node[annot,right of=hl] {Output layer};
    end{tikzpicture}
    % End of code
    end{document}





    share|improve this answer


























      1














      I know that this is an old question. But I just found this code by Kjell Magne Fauske on TeXample about a neural network and I think it can be helpful to future readers since it's easy to modify.



      example



      documentclass{article}

      usepackage{tikz}
      begin{document}
      pagestyle{empty}

      deflayersep{2.5cm}

      begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=layersep]
      tikzstyle{every pin edge}=[<-,shorten <=1pt]
      tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
      tikzstyle{input neuron}=[neuron, fill=green!50];
      tikzstyle{output neuron}=[neuron, fill=red!50];
      tikzstyle{hidden neuron}=[neuron, fill=blue!50];
      tikzstyle{annot} = [text width=4em, text centered]

      % Draw the input layer nodes
      foreach name / y in {1,...,4}
      % This is the same as writing foreach name / y in {1/1,2/2,3/3,4/4}
      node[input neuron, pin=left:Input #y] (I-name) at (0,-y) {};

      % Draw the hidden layer nodes
      foreach name / y in {1,...,5}
      path[yshift=0.5cm]
      node[hidden neuron] (H-name) at (layersep,-y cm) {};

      % Draw the output layer node
      node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-3] (O) {};

      % Connect every node in the input layer with every node in the
      % hidden layer.
      foreach source in {1,...,4}
      foreach dest in {1,...,5}
      path (I-source) edge (H-dest);

      % Connect every node in the hidden layer with the output layer
      foreach source in {1,...,5}
      path (H-source) edge (O);

      % Annotate the layers
      node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
      node[annot,left of=hl] {Input layer};
      node[annot,right of=hl] {Output layer};
      end{tikzpicture}
      % End of code
      end{document}





      share|improve this answer
























        1












        1








        1






        I know that this is an old question. But I just found this code by Kjell Magne Fauske on TeXample about a neural network and I think it can be helpful to future readers since it's easy to modify.



        example



        documentclass{article}

        usepackage{tikz}
        begin{document}
        pagestyle{empty}

        deflayersep{2.5cm}

        begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=layersep]
        tikzstyle{every pin edge}=[<-,shorten <=1pt]
        tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
        tikzstyle{input neuron}=[neuron, fill=green!50];
        tikzstyle{output neuron}=[neuron, fill=red!50];
        tikzstyle{hidden neuron}=[neuron, fill=blue!50];
        tikzstyle{annot} = [text width=4em, text centered]

        % Draw the input layer nodes
        foreach name / y in {1,...,4}
        % This is the same as writing foreach name / y in {1/1,2/2,3/3,4/4}
        node[input neuron, pin=left:Input #y] (I-name) at (0,-y) {};

        % Draw the hidden layer nodes
        foreach name / y in {1,...,5}
        path[yshift=0.5cm]
        node[hidden neuron] (H-name) at (layersep,-y cm) {};

        % Draw the output layer node
        node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-3] (O) {};

        % Connect every node in the input layer with every node in the
        % hidden layer.
        foreach source in {1,...,4}
        foreach dest in {1,...,5}
        path (I-source) edge (H-dest);

        % Connect every node in the hidden layer with the output layer
        foreach source in {1,...,5}
        path (H-source) edge (O);

        % Annotate the layers
        node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
        node[annot,left of=hl] {Input layer};
        node[annot,right of=hl] {Output layer};
        end{tikzpicture}
        % End of code
        end{document}





        share|improve this answer












        I know that this is an old question. But I just found this code by Kjell Magne Fauske on TeXample about a neural network and I think it can be helpful to future readers since it's easy to modify.



        example



        documentclass{article}

        usepackage{tikz}
        begin{document}
        pagestyle{empty}

        deflayersep{2.5cm}

        begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=layersep]
        tikzstyle{every pin edge}=[<-,shorten <=1pt]
        tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
        tikzstyle{input neuron}=[neuron, fill=green!50];
        tikzstyle{output neuron}=[neuron, fill=red!50];
        tikzstyle{hidden neuron}=[neuron, fill=blue!50];
        tikzstyle{annot} = [text width=4em, text centered]

        % Draw the input layer nodes
        foreach name / y in {1,...,4}
        % This is the same as writing foreach name / y in {1/1,2/2,3/3,4/4}
        node[input neuron, pin=left:Input #y] (I-name) at (0,-y) {};

        % Draw the hidden layer nodes
        foreach name / y in {1,...,5}
        path[yshift=0.5cm]
        node[hidden neuron] (H-name) at (layersep,-y cm) {};

        % Draw the output layer node
        node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-3] (O) {};

        % Connect every node in the input layer with every node in the
        % hidden layer.
        foreach source in {1,...,4}
        foreach dest in {1,...,5}
        path (I-source) edge (H-dest);

        % Connect every node in the hidden layer with the output layer
        foreach source in {1,...,5}
        path (H-source) edge (O);

        % Annotate the layers
        node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
        node[annot,left of=hl] {Input layer};
        node[annot,right of=hl] {Output layer};
        end{tikzpicture}
        % End of code
        end{document}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 16 '18 at 13:22









        gvgramazio

        1,447520




        1,447520























            0














            I found this package neuralnetwork, made by Mark K Cowan, which makes drawing neural networks pretty simple. For example:



            documentclass{standalone}

            usepackage{neuralnetwork}

            begin{document}
            begin{neuralnetwork}[height=4]
            newcommand{x}[2]{$x_#2$}
            newcommand{y}[2]{$hat{y}_#2$}
            newcommand{hfirst}[2]{small $h^{(1)}_#2$}
            newcommand{hsecond}[2]{small $h^{(2)}_#2$}
            inputlayer[count=3, bias=true, title=Input\layer, text=x]
            hiddenlayer[count=4, bias=false, title=Hidden\layer 1, text=hfirst] linklayers
            hiddenlayer[count=3, bias=false, title=Hidden\layer 2, text=hsecond] linklayers
            outputlayer[count=2, title=Output\layer, text=y] linklayers
            end{neuralnetwork}
            end{document}


            enter image description here






            share|improve this answer























            • The question really seems to be about the dots, although your code is very elegant.
              – Benjamin McKay
              Dec 12 '18 at 9:09
















            0














            I found this package neuralnetwork, made by Mark K Cowan, which makes drawing neural networks pretty simple. For example:



            documentclass{standalone}

            usepackage{neuralnetwork}

            begin{document}
            begin{neuralnetwork}[height=4]
            newcommand{x}[2]{$x_#2$}
            newcommand{y}[2]{$hat{y}_#2$}
            newcommand{hfirst}[2]{small $h^{(1)}_#2$}
            newcommand{hsecond}[2]{small $h^{(2)}_#2$}
            inputlayer[count=3, bias=true, title=Input\layer, text=x]
            hiddenlayer[count=4, bias=false, title=Hidden\layer 1, text=hfirst] linklayers
            hiddenlayer[count=3, bias=false, title=Hidden\layer 2, text=hsecond] linklayers
            outputlayer[count=2, title=Output\layer, text=y] linklayers
            end{neuralnetwork}
            end{document}


            enter image description here






            share|improve this answer























            • The question really seems to be about the dots, although your code is very elegant.
              – Benjamin McKay
              Dec 12 '18 at 9:09














            0












            0








            0






            I found this package neuralnetwork, made by Mark K Cowan, which makes drawing neural networks pretty simple. For example:



            documentclass{standalone}

            usepackage{neuralnetwork}

            begin{document}
            begin{neuralnetwork}[height=4]
            newcommand{x}[2]{$x_#2$}
            newcommand{y}[2]{$hat{y}_#2$}
            newcommand{hfirst}[2]{small $h^{(1)}_#2$}
            newcommand{hsecond}[2]{small $h^{(2)}_#2$}
            inputlayer[count=3, bias=true, title=Input\layer, text=x]
            hiddenlayer[count=4, bias=false, title=Hidden\layer 1, text=hfirst] linklayers
            hiddenlayer[count=3, bias=false, title=Hidden\layer 2, text=hsecond] linklayers
            outputlayer[count=2, title=Output\layer, text=y] linklayers
            end{neuralnetwork}
            end{document}


            enter image description here






            share|improve this answer














            I found this package neuralnetwork, made by Mark K Cowan, which makes drawing neural networks pretty simple. For example:



            documentclass{standalone}

            usepackage{neuralnetwork}

            begin{document}
            begin{neuralnetwork}[height=4]
            newcommand{x}[2]{$x_#2$}
            newcommand{y}[2]{$hat{y}_#2$}
            newcommand{hfirst}[2]{small $h^{(1)}_#2$}
            newcommand{hsecond}[2]{small $h^{(2)}_#2$}
            inputlayer[count=3, bias=true, title=Input\layer, text=x]
            hiddenlayer[count=4, bias=false, title=Hidden\layer 1, text=hfirst] linklayers
            hiddenlayer[count=3, bias=false, title=Hidden\layer 2, text=hsecond] linklayers
            outputlayer[count=2, title=Output\layer, text=y] linklayers
            end{neuralnetwork}
            end{document}


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 12 '18 at 8:43

























            answered Dec 12 '18 at 8:19









            Andyk

            15316




            15316












            • The question really seems to be about the dots, although your code is very elegant.
              – Benjamin McKay
              Dec 12 '18 at 9:09


















            • The question really seems to be about the dots, although your code is very elegant.
              – Benjamin McKay
              Dec 12 '18 at 9:09
















            The question really seems to be about the dots, although your code is very elegant.
            – Benjamin McKay
            Dec 12 '18 at 9:09




            The question really seems to be about the dots, although your code is very elegant.
            – Benjamin McKay
            Dec 12 '18 at 9:09


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f153957%2fdrawing-neural-network-with-tikz%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to send String Array data to Server using php in android

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Is anime1.com a legal site for watching anime?