Wie kann ich dieses Diagramm mit Knoten und Pfeilen zeichnen?

Wie kann ich dieses Diagramm mit Knoten und Pfeilen zeichnen?

Wie kann ich das zeichnen?

Bildbeschreibung hier eingeben

Ein zugehöriges Diagramm (komplizierter) finden Sie hierTikz zeichnet den Umriss eines neuronalen Netzwerks

Ich habe versucht, den von @Zarco bereitgestellten Code zu ändern, konnte aber nur die Knoten ändern. Die Pfeile haben mich wirklich verwirrt.

    \documentclass[tikz, margin=3mm]{standalone}
    \usetikzlibrary{chains, positioning}

    \begin{document}
        \begin{tikzpicture}[shorten >=1pt,->, draw=black!50,
            node distance = 6mm and 15mm,
              start chain = going below,
    every pin edge/.style = {<-,shorten <=1pt},
            neuron/.style = {circle, draw=black, fill=#1,   % <--- changed
                             minimum size=17pt, inner sep=0pt,
                             on chain},
             annot/.style = {text width=4em, align=center}
                            ]
    % Draw the input layer nodes
    \foreach \i in {1,...,3}
        \node[neuron=green!50,
              pin=180:] (I-\i)    {};
    % Draw the hidden layer nodes
        \node[neuron=blue!50,
              above right=6mm and 15mm of I-1.center] (H-1)     {$x_{1}$};
    \foreach \i [count=\j from 1] in {2}
        \node[neuron=blue!50,
              below=of H-\j]      (H-\i)    {$x_{\i}$};
    % Draw the output layer node
        \node[neuron=red!50,
              pin= {[pin edge=->]0:Output \#1},
              right=of I-2 -| H-1]  (O-1)   {$x_{1}$};
        \node[neuron=red!50,                            % <--- changed
              pin= {[pin edge=->]0:Output \#2},
              below=of O-1]         (O-2)   {$x_{2}$};  % <--- changed
\node[neuron=red!50,
              pin= {[pin edge=->]0:Output \#3},
              below=of 0-2]  (O-3)   {$x_{1}$};

    % Connect input nodes with hidden nodes and
    %  hiden nodes with output nodes with the output layer
        \foreach \i in {1,...,4}
            \foreach \j in {1,...,5}
    {
        \path (I-\i) edge (H-\j)
        \ifnum\i<3                  % <--- changed
              (H-\j) edge (O-\i)
        \fi;
    }
        \end{tikzpicture}
    \end{document}  

Vielen Dank im Voraus.

Antwort1

Die chainsBibliothek ist ein mächtiges Werkzeug, aber vielleicht nicht wirklich für solche Diagramme geeignet. Dies ist ein Versuch, die Dinge automatisierter und zugänglicher zu machen. Bitte lesen Sie die Anmerkungen im Code. Die Ein- und Ausgaben werden in Listen gespeichert, ebenso wie die Anzahl der Neuronen.

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{quotes,positioning}
\begin{document}
    \begin{tikzpicture}[shorten >=1pt,->, draw=black!50,>=stealth,
        every pin edge/.style = {<-,shorten <=1pt},
        every pin/.style={font=\small\sffamily,text=gray,inner sep=1pt},
        neuron/.style = {circle, draw=black, fill=#1,
                         minimum size=20pt, inner sep=0pt},
        neuron/.default=white,               
        layer 1/.style={neuron=green!50,pin={[alias=el1-\i]180:\myedgelabel}},
        layer 2/.style={neuron=blue!50},
        layer 3/.style={neuron=red!50,pin={[pin edge={->},alias=el3-\i]0:\myedgelabel}},
         annot/.style = {text width=4em, align=center},
         neuron list/.store in=\NeuronList,
         neuron list={3,2,3}, %<- # of neurons at each layer
         input list/.store in=\InputList,
         input list={200,150,200},%<- inputs
         output list/.store in=\OutputList,
         output list={200,250,100},%<- outputs
                        ]
% Draw the input layer nodes
 \pgfmathtruncatemacro{\imax}{{\NeuronList}[0]}
 \path foreach \i in {1,...,\imax}
    {(0,{(\imax/2-1/2-\i)*1.5})
    [/utils/exec=\pgfmathsetmacro{\myedgelabel}{{\InputList}[\i-1]}]
     node[layer 1] (P-\i)    {$P_\i$}};  
% Draw the hidden layer nodes
 \pgfmathtruncatemacro{\imax}{{\NeuronList}[1]}
 \path foreach \i in {1,...,\imax}
    {(25mm,{(\imax/2-1/2-\i)*1.5}) node[layer 2] (T-\i)    {$T_\i$}};  
% % Draw the output layer node
 \pgfmathtruncatemacro{\imax}{{\NeuronList}[2]}
 \path foreach \i in {1,...,\imax}
    {(60mm,{(\imax/2-1/2-\i)*1.5})
    [/utils/exec=\pgfmathsetmacro{\myedgelabel}{{\OutputList}[\i-1]}] 
        node[layer 3] (D-\i)    {$D_\i$}};  
% edges
  \path[nodes={text=red,font=\small\sffamily},->] 
   (P-1) edge["1"] (T-1)
   (P-1) edge["4"' {pos=0.2}] (T-2) %<- a prime swaps the label position
   (P-2) edge["2" {pos=0.15}] (T-2) %<- with pos you can control the position
   (P-3) edge["2"' {pos=0.3}] (T-1)
   (P-3) edge["3"] (P-2)
   (T-1) edge["2"] (D-1)
   (T-1) edge["3"] (D-2)
   (D-1) edge["2"] (D-2)
   (T-2) edge["1"] (D-2)
   (T-2) edge["3"] (D-3);
% extra 
  \begin{scope}[node distance=0pt,nodes={font=\small\sffamily,color=blue}]
   \node[above=of P-1]{(pure)};   
   \node[below=of P-3]{(pure)};   
   \node[below=of el3-2]{(pure)};   
  \end{scope}
\end{tikzpicture}
\end{document}  

Bildbeschreibung hier eingeben

verwandte Informationen