tizk를 사용하여 단일 신경 단위 그리기

tizk를 사용하여 단일 신경 단위 그리기

나는 다음과 같은 그림을 그리고 싶습니다. 여기에 이미지 설명을 입력하세요

다음은 내 라텍스 코드입니다.

  \documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta,calc}

\tikzset{
  arro/.style={
    ->,
    >=latex
  },
  bloque/.style={
    draw,
    minimum height=1cm,
    minimum width=0.5cm
  }  
}

\begin{document}

\begin{tikzpicture}[]
\node[]
  (input)
  {Input};
\node[below=of input,label={left:$x_{1}$}]
  (inputi)
  {};
\node[below=of inputi,label={left:$x_{2}$}]
  (inputii)
  {};
\coordinate[below=of inputii] (aux);  
\node[below=of aux,label={left:$x_{3}$}]
  (inputiii)
  {};
\node[below=of inputiii,label={left:$+1$}]
  (inputiv)
  {};

\node[right=of input]
  (proje)
  {Projection};
\node[circle,label={above:\textsc{sum}}]
  at (proje|-aux)
  (projei)
  {};

\node[right=of proje]
  (out)
  {Output};
\node[label={right:$h_{w,b}(x)$}]
  at (out|-aux)
  (outi)
  {};

\foreach \Valor in {i,ii,iii,iv}
{
  \draw[arro] (input\Valor) -- (projei);
}  
\draw[arro] (projei) -- (outi);
\end{tikzpicture}

\end{document}

내가 얻는 것은 다음과 같습니다. 여기에 이미지 설명을 입력하세요

다음 코드를 추가하려고 합니다.\begin{tikzpicture}[every node/.style={draw=black,circle}]

그리고 이것을 얻으십시오 : 여기에 이미지 설명을 입력하세요

누군가 나를 도와줄 수 있나요? 감사합니다!

답변1

당신은 질문에 거의 대답했지만 모든 노드의 윤곽선을 그리는 것을 원하지 않습니다. 단지 하나만 그리는 것입니다. 따라서 draw해당 노드에만 옵션을 추가해야 합니다 . 크기를 늘리려면 추가할 수도 minimum size=1cm있고, 색상을 변경하려면 색상 이름을 추가할 수도 있습니다.

아래 코드에서는 주석으로 표시된 한 줄을 추가했습니다.

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

  \documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta,calc}

\tikzset{
  arro/.style={
    ->,
    >=latex
  },
  bloque/.style={
    draw,
    minimum height=1cm,
    minimum width=0.5cm
  }  
}

\begin{document}

\begin{tikzpicture}[]
\node[]
  (input)
  {Input};
\node[below=of input,label={left:$x_{1}$}]
  (inputi)
  {};
\node[below=of inputi,label={left:$x_{2}$}]
  (inputii)
  {};
\coordinate[below=of inputii] (aux);  
\node[below=of aux,label={left:$x_{3}$}]
  (inputiii)
  {};
\node[below=of inputiii,label={left:$+1$}]
  (inputiv)
  {};

\node[right=of input]
  (proje)
  {Projection};
\node[circle,
   draw,minimum size=1cm,orange, %% <-- these are added
   label={above:\textsc{sum}}]
  at (proje|-aux)
  (projei)
  {};

\node[right=of proje]
  (out)
  {Output};
\node[label={right:$h_{w,b}(x)$}]
  at (out|-aux)
  (outi)
  {};

\foreach \Valor in {i,ii,iii,iv}
{
  \draw[arro] (input\Valor) -- (projei);
}  
\draw[arro] (projei) -- (outi);
\end{tikzpicture}

\end{document}

label또한 왼쪽의 입력 노드와 출력 노드에는 사용하지 않는 것이 좋습니다 . 몇 가지 다른 사소한 변경 사항은 다음과 같습니다.

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

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta,calc}

\tikzset{
  arro/.style={
    ->,
    >=latex
  },
  bloque/.style={
    draw,
    minimum height=1cm,
    minimum width=0.5cm
  }  
}

\begin{document}

\begin{tikzpicture}[node distance=0.5cm and 1cm] % first value vertical distance, second horizontal
\node
  (input)
  {Input};
\node[below=of input]
  (inputi)
  {$x_{1}$};
\node[below=of inputi]
  (inputii)
  {$x_{2}$};
\coordinate[below=of inputii] (aux);  
\node[below=of aux]
  (inputiii)
  {$x_{3}$};
\node[below=of inputiii]
  (inputiv)
  {$+1$};

\node[right=of input]
  (proje)
  {Projection};
\node[circle,
   draw,minimum size=1cm,orange, 
   label={above:\textsc{sum}}]
  at (proje|-aux)
  (projei)
  {};

\node[right=of proje]
  (out)
  {Output};
\node
  at (out|-aux)
  (outi)
  {$h_{w,b}(x)$};

\foreach \Valor in {i,ii,iii,iv}
{
  \draw[arro] (input\Valor) -- (projei);
}  
\draw[arro] (projei) -- (outi);
\end{tikzpicture}
\end{document}

답변2

약간 더 복잡하고 간결한 대안 :-) :

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

\begin{document}
    \begin{tikzpicture}[
node distance = 4mm and 16mm,
  start chain = going below,
  arro/.style = {-Latex},
bloque/.style = {text width=4ex, inner sep=1pt, align=right, on chain},
                        ]
% inputs
\foreach \i [count=\j] in {1, 2, 3, +1}
    \node[bloque] (in-\j) {$x_{\i}$};
% output
\node (out) [circle, draw=orange, minimum size=6mm,
      label=\textsc{sum},
      right=of $(in-2)!0.5!(in-3)$]  {};
% conections
\foreach \i in {1,...,4}
    \draw[arro] (in-\i) -- (out);
% output
\coordinate[right=of out] (output);
\draw[arro] (out) -- (output) node[right]   {$h_{w,b}(x)$};
% layer labels
\node[above=of in-1.center]     {Input};
\node[above=of in-1 -| out]     {Projection};
\node[above=of in-1 -| output]  {Ouput};
    \end{tikzpicture}
\end{document}

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

관련 정보