我正在尝试修改答案中的代码这里满足我的需要。
这是我修改后的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\begin{document}
\pagestyle{empty}
\def\layersep{2.5cm}
\begin{tikzpicture}[
shorten >=1pt,->,
draw=black,
node distance=\layersep,
every pin edge/.style={<-,shorten <=1pt},
input neuron/.style={rectangle,minimum size=17pt,inner sep=0pt,fill=green!50},
output neuron/.style={circle,minimum size=17pt,inner sep=0pt, fill=red!50},
hidden neuron/.style={circle,minimum size=17pt,inner sep=0pt, fill=purple!50},
annot/.style={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:$x_{\y}$] (I-\name) at (0,-\y) {};
% set number of hidden layers
\newcommand\Nhidden{3}
% Draw the hidden layer nodes
\foreach \N in {1,...,\Nhidden} {
\foreach \y in {1,...,5} {
\path[yshift=0.5cm]
node[hidden neuron] (H\N-\y) at (\N*\layersep,-\y cm) {};
}
\node[annot,above of=H\N-1, node distance=1cm] (hl\N) {};
}
% % Draw the output layer node
%
\node[output neuron,pin={[pin edge={->}]right:$y$}, right of=H\Nhidden-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 (H1-\dest);
% connect all hidden stuff
\foreach [remember=\N as \lastN (initially 1)] \N in {2,...,\Nhidden}
\foreach \source in {1,...,5}
\foreach \dest in {1,...,5}
\path (H\lastN-\source) edge (H\N-\dest);
% Connect every node in the hidden layer with the output layer
\foreach \source in {1,...,5}
\path (H\Nhidden-\source) edge (O);
% Annotate the layers
\draw [very thick,decorate,decoration={brace,amplitude=10pt}] (2,0) -- (8,0);
\node[annot,left of=hl1] {Input layer};
\node[annot,right of=hl\Nhidden] {Output layer};
\end{tikzpicture}
\end{document}
以下是我目前得到的信息:
因此,我需要以下方面的帮助:
1-固定括号(括号末端有一个箭头),并Hidden layers
在其上方书写;
2——在$x_{3}$
矩形下方,我想添加\vdots
并更改$x_{4}$
为$x_{m}$
;
3-使输出层看起来像输入,IE、四个圆圈$y_{1}$
、、后跟和。$y_{2}$
$y_{3}$
\vdots
$y_{k}$
答案1
这是针对您原始代码的解决方案。只需进行一些调整。
\documentclass{article}
% https://tex.stackexchange.com/q/629645/204164
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\begin{document}
\pagestyle{empty}
\def\layersep{2.5cm}
\begin{tikzpicture}[
shorten >=1pt,%->,
draw=black,
node distance=\layersep,
every pin edge/.style={<-,shorten <=1pt},
input neuron/.style={rectangle,minimum size=17pt,inner sep=0pt,fill=green!50},
output neuron/.style={circle,minimum size=17pt,inner sep=0pt, fill=red!50},
hidden neuron/.style={circle,minimum size=17pt,inner sep=0pt, fill=purple!50},
annot/.style={text width=4em, text centered}
]
\begin{scope}[->]
% Draw the input layer nodes
\foreach \y in {1,...,4}
{
\if\y4
\node[input neuron, pin=left:$x_{m}$] (I-\y) at (0,-\y) {};
\else
\node[input neuron, pin=left:$x_{\y}$] (I-\y) at (0,-\y) {};
\fi
}
\path (I-3) --++ (-1,0) |- (I-4) node[pos=0.2] {\vdots}; %Vdots beteween x_3 and x_m
% set number of hidden layers
\newcommand\Nhidden{3}
% Draw the hidden layer nodes
\foreach \N in {1,...,\Nhidden} {
\foreach \y in {1,...,5} {
\path[yshift=0.5cm]
node[hidden neuron] (H\N-\y) at (\N*\layersep,-\y cm) {};
}
\node[annot,above of=H\N-1, node distance=1cm] (hl\N) {};
}
% Draw the output layer nodes
\foreach \t in {1,...,4}
{
\if\t4
\node[output neuron,pin={[pin edge={->}]right:$y_k$}] (O-\t) at (\Nhidden*\layersep+\layersep,-\t) {};
\else
\node[output neuron,pin={[pin edge={->}]right:$y_\t$}] (O-\t) at (\Nhidden*\layersep+\layersep,-\t) {};
\fi
}
\path (O-3) --++ (1,0) |- (O-4) node[pos=0.2] {\vdots}; %Vdots beteween y_3 and y_k
% 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 (H1-\dest);
% connect all hidden stuff
\foreach [remember=\N as \lastN (initially 1)] \N in {2,...,\Nhidden}
\foreach \source in {1,...,5}
\foreach \dest in {1,...,5}
\path (H\lastN-\source) edge (H\N-\dest);
% Connect every node in the last hidden layer with the output layer
\foreach \source in {1,...,5}
\foreach \dest in {1,...,4}
\path (H3-\source) edge (O-\dest);
% Annotate the layers
\node[annot,left of=hl1] {Input layer};
\node[annot,right of=hl\Nhidden] {Output layer};
\end{scope}
\draw [very thick,decorate,decoration={brace,amplitude=10pt}] (2,0) -- (8,0) node [midway,above=10pt] {Hidden layers};
\end{tikzpicture}
\end{document}