我想用 Latex 中的 Tikz 绘制如图所示的图表。我尝试自己做,但没有成功。我的 Tikz 代码附在此处
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows,calc}
\usepackage{pgfplots}
\usepackage{circuitikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
init/.style={
draw,
circle,
inner sep=8pt,
font=\Huge,
join = by -latex
},
squa/.style={
draw,
font=\Large,
join = by -latex
},
start chain=3,node distance=13mm
]
\node[on chain=3]
(x3) [label=below:$\vdots$]{$x_{3}$};
\node[on chain=3,join=by o-latex]
{$w_{k3}$};
\node[on chain=3,init,label=below:\parbox{2cm}{\centering Summing \\ junction}] (sigma)
{$\displaystyle\Sigma$};
\node[on chain=3,join=by -latex] {$u_{k}$};
\node[on chain=3,squa,label=above:{\parbox{2cm}{\centering Activate \\ function}}]
{$f_{k}(.)$};
\node[on chain=3,label=above:Output,join=by -latex]
{$y_{k}$};
\begin{scope}[start chain=2]
\node[on chain=2] at (0,0.7cm)
(x2) {$x_2$};
\node[on chain=2,join=by o-latex]
(w2) {$w_{k2}$};
\end{scope}
\begin{scope}[start chain=1]
\node[on chain=1] at (0,1.5cm)
(x1) {$x_1$};
\node[on chain=1]
(w1) {};
% \node[on chain =1] at (-1.5cm,1.1cm) (dots) {\vdots};
\end{scope}
\begin{scope}[start chain=4]
\node[on chain=4] at (0,-1.5cm)
(xn) {$x_n$};
\node[on chain=4,label=below:Weights,join=by o-latex]
(w3) {$w_{kn}$};
\end{scope}
\node[label=above:\parbox{2cm}{\centering Bias \\ $b_{k}$}] at (sigma|-w1) (b) {};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (x1) to [R=$w_{k1}$] (w1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw[-latex] (w1) -- (sigma);
\draw[-latex] (w2) -- (sigma);
\draw[-latex] (w3) -- (sigma);
\draw[o-latex] (b) -- (sigma);
\draw[decorate,decoration={brace,mirror}] (x1.north west) -- node[left=10pt] {Inputs} (xn.south west);
\end{tikzpicture}
\caption{}
\label{neuralnetwork}
\end{figure}
\end{document}
有人能帮我解决这个问题吗?
提前谢谢了。
答案1
只是为了好玩,一个具有相对坐标的选项,全部指向原点。这是一个品味问题,但我更喜欢编译我的所有 tikz 绘图,每个绘图都有自己的代码,放在一个文件夹中,并以 pdf 格式输出,然后以与图像相同的方式将它们导入到我的主文档中,这样做的好处是可以减少编译时间并保留矢量格式,能够将它们缩放到页面宽度,甚至可以在主文档的 tkz 代码内的节点内导入它……
梅威瑟:
\documentclass[tikz]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{decorations.pathreplacing,arrows.meta}
\begin{document}
\begin{tikzpicture}[
%Environment Config
>={Triangle[length=3pt,angle=60:4]}, % Style for Arrows from arrows.meta
%Styles
init/.style={
draw,
circle,
inner sep=8pt,
align=center,
scale=1
},
squa/.style={
draw,
align=center,
scale=1
},
Brace/.style={% To automate declaring decorations in draw optios for braces.
decorate,
decoration={
brace,
raise=-7pt
}
}
]
%Size adjust for circuitikz
\ctikzset{nodes width/.initial=0.1} % set the size for shorts.
\ctikzset{bipoles/length=0.75cm} % set the bilopes lenght like resistors, capacitors, etc...
%Start drawing the thing from 0,0 coordinate.
\foreach \k [count=\j from 1] in {1,2,3,dots,n}{% Counter is used to enable to put characters in each iteration.
\ifnum \j=4
\draw
(0,0-\j*1cm) % Starting from 0,0
node[anchor=0](X\j){\vdots}; % A node for the fourth iteration
\else
\draw
(0,0-\j*1cm)
node[anchor=0](X\k){$X_{\k}$} % generate nodes X1,X2,X3,Xn
to [short,o-] ++ (0.5cm,0)
to [R,l=$W_{k\k}$] ++ (1.5cm,0) coordinate (wk\k); %generates Wk1, wk2, wk3, wkn coordinates.
\fi
}
% Put some shaped nodes relative to new points generated by coordinate instructión.
\draw (wk3)++(3.5cm,0) node(CSJ)[init]{Current \\ Summing \\ Junction};
% Draw each nx to CSJ
\foreach \m in {1,2,3,n}{
\draw[>->]
(wk\m)--++(0.5cm,0)
-- (CSJ)
node[pos=0,sloped,anchor=south west,scale=0.8]{$W_{k\m} X_{\m}(t)$}; %node in a path. position 0.25
}
\draw[] % Circuitikz part
(CSJ.0)
node[anchor=south west]{$\displaystyle\Sigma W_{ki} X_{i}(t)$}
to [short,-*] ++(2cm,0) coordinate (BI1) % Bifurcation 1
(BI1)
to[C,l_=$C_k$] ++(0,-2cm) coordinate (BI2) % Bifurcation 2
(BI2)
-| ++ (-0.5cm,-0.25cm) node[tlground,scale=2]{}
(BI2)
to [short,*-*] ++(1.5cm,0)
to [R,l_=$R_k$] ++ (0,2cm) coordinate (BI3) % Bifurcation 3
to [short,*-] (BI1)
(BI3)++(0,2cm)
node[squa](CS){Current \\ Source}
(CS)
-- (BI3)
(BI3)++(2cm,0)
node[squa](FK){$F_{k}(.)$}
(FK)
-- (BI3)
(FK)
to [short,-o] ++(1.75cm,0)
node[anchor=180](NKT){$n_k(t)$};
%Currents
\draw
(BI1)++(-0.5cm,0) node[currarrow,scale=1.5]{}
(BI1)++(0,-0.5cm) node[currarrow,scale=1.5,rotate=-90]{}
(BI1)++(0.75cm,0) node[currarrow,scale=1.5]{}
(BI2)++(0.75cm,0) node[currarrow,scale=1.5]{}
(BI3)++(0,0.75cm) node[currarrow,scale=1.5,rotate=-90,label={0:jk}]{}
(BI3)++(0.75cm,0) node[currarrow,scale=1.5,label={90:$r_k(t)$}]{}
(BI3)++(0,-1.75cm) node[currarrow,scale=1.5,rotate=-90]{};
%Finishing
\draw[Brace]
(Xn.270)++(-0.5cm,0) coordinate (temp) -- (temp|-X1.90);
\draw
(X3.180) node[anchor=0,align=center]{Synaptic \\ inputs}
(NKT.-90)++(0,-0.25cm) node[align=center]{Output};
\end{tikzpicture}
\end{document}