노드와 화살표가 있는 이 다이어그램을 어떻게 그릴 수 있나요?

노드와 화살표가 있는 이 다이어그램을 어떻게 그릴 수 있나요?

이걸 어떻게 그릴 수 있나요?

여기에 이미지 설명을 입력하세요

관련 다이어그램(더 복잡함)은 여기에 있습니다.Tikz는 신경망 개요를 그립니다.

@Zarco가 제공한 코드를 수정하려고 시도했지만 노드만 수정할 수 있었습니다. 나는 결국 화살표와 정말 혼란스러워졌습니다.

    \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}  

미리 감사드립니다.

답변1

라이브러리 chains는 강력한 도구이지만 그러한 다이어그램에는 실제로 적합하지 않을 수도 있습니다. 이는 일을 보다 자동적이고 접근 가능하게 만들려는 시도입니다. 코드의 주석을 읽어보세요. 입력과 출력은 목록에 저장되며 뉴런의 수도 마찬가지입니다.

\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}  

여기에 이미지 설명을 입력하세요

관련 정보