latex 画神经网络DNN图 和复杂的DNN网络图

\begin{figure}%[H]
	\centering
	\begin{tikzpicture}[scale=0.75]
	\node[circle] (x0) at (0, 2) {};
	\node[circle] (x1) at (0, 1) {};
	\node[circle] (x2) at (0, 0) {};
	\node[circle] (x3) at (0, -1) {};
	\node[circle] (x4) at (0, -2) {};
	
	\node[] (input) at (1.5, -3.75) {Input layer};
	
	\node[circle, fill=green!60,inner sep=4pt] (i0) at (2, 2) {};
	\node[circle, fill=green!60,inner sep=4pt] (i1) at (2, 1) {};	
	\node[circle, fill=green!60,inner sep=4pt] (i2) at (2, 0) {};	
	\node[circle, fill=green!60,inner sep=4pt] (i3) at (2, -1) {};	
	\node[circle, fill=green!60,inner sep=4pt] (i4) at (2, -2) {};	
	
	\draw[line width=1.0pt,->] (x0) -- node[above]{$x_0$} (i0);
	\draw[line width=1.0pt,->] (x1) -- node[above]{$x_1$} (i1);
	\draw[line width=1.0pt,->] (x2) -- node[above]{$x_2$} (i2);
	\draw[line width=1.0pt,->] (x3) -- node[above]{$x_3$} (i3);
	\draw[line width=1.0pt,->] (x4) -- node[above]{$x_4$} (i4);
	
	\node[circle, fill=cyan!70,inner sep=4pt] (h10) at (6, 3) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h11) at (6, 2) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h12) at (6, 1) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h13) at (6, 0) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h14) at (6, -1) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h15) at (6, -2) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h16) at (6, -3) {};	
	\node[] (input) at (6, -3.75) {Hidden layer1};
	
	\draw[line width=1.0pt,->] (i0) -- (h10);
	\draw[line width=1.0pt,->] (i0) -- (h11);
	\draw[line width=1.0pt,->] (i0) -- (h12);
	\draw[line width=1.0pt,->] (i0) -- (h13);
	\draw[line width=1.0pt,->] (i0) -- (h14);
	\draw[line width=1.0pt,->] (i0) -- (h15);
	\draw[line width=1.0pt,->] (i0) -- (h16);
	
	\draw[line width=1.0pt,->] (i1) -- (h10);
	\draw[line width=1.0pt,->] (i1) -- (h11);
	\draw[line width=1.0pt,->] (i1) -- (h12);
	\draw[line width=1.0pt,->] (i1) -- (h13);
	\draw[line width=1.0pt,->] (i1) -- (h14);
	\draw[line width=1.0pt,->] (i1) -- (h15);
	\draw[line width=1.0pt,->] (i1) -- (h16);
	
	\draw[line width=1.0pt,->] (i2) -- (h10);
	\draw[line width=1.0pt,->] (i2) -- (h11);
	\draw[line width=1.0pt,->] (i2) -- (h12);
	\draw[line width=1.0pt,->] (i2) -- (h13);
	\draw[line width=1.0pt,->] (i2) -- (h14);
	\draw[line width=1.0pt,->] (i2) -- (h15);
	\draw[line width=1.0pt,->] (i2) -- (h16);
	
	\draw[line width=1.0pt,->] (i3) -- (h10);
	\draw[line width=1.0pt,->] (i3) -- (h11);
	\draw[line width=1.0pt,->] (i3) -- (h12);
	\draw[line width=1.0pt,->] (i3) -- (h13);
	\draw[line width=1.0pt,->] (i3) -- (h14);
	\draw[line width=1.0pt,->] (i3) -- (h15);
	\draw[line width=1.0pt,->] (i3) -- (h16);;
	
	\draw[line width=1.0pt,->] (i4) -- (h10);
	\draw[line width=1.0pt,->] (i4) -- (h11);
	\draw[line width=1.0pt,->] (i4) -- (h12);
	\draw[line width=1.0pt,->] (i4) -- (h13);
	\draw[line width=1.0pt,->] (i4) -- (h14);
	\draw[line width=1.0pt,->] (i4) -- (h15);
	\draw[line width=1.0pt,->] (i4) -- (h16);
	
	\node[circle, fill=cyan!70,inner sep=4pt] (h30) at (10, 2) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h31) at (10, 1) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h32) at (10, 0) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h33) at (10, -1) {};
	\node[circle, fill=cyan!70,inner sep=4pt] (h34) at (10, -2) {};
	\node[] (input) at (10, -3.75) {Hidden layer2};
	
	\draw[line width=1.0pt,->] (h10) -- (h30);
	\draw[line width=1.0pt,->] (h10) -- (h31);
	\draw[line width=1.0pt,->] (h10) -- (h32);
	\draw[line width=1.0pt,->] (h10) -- (h33);
	\draw[line width=1.0pt,->] (h10) -- (h34);
	
	\draw[line width=1.0pt,->] (h11) -- (h30);
	\draw[line width=1.0pt,->] (h11) -- (h31);
	\draw[line width=1.0pt,->] (h11) -- (h32);
	\draw[line width=1.0pt,->] (h11) -- (h33);
	\draw[line width=1.0pt,->] (h11) -- (h34);
	
	\draw[line width=1.0pt,->] (h12) -- (h30);
	\draw[line width=1.0pt,->] (h12) -- (h31);
	\draw[line width=1.0pt,->] (h12) -- (h32);
	\draw[line width=1.0pt,->] (h12) -- (h33);
	\draw[line width=1.0pt,->] (h12) -- (h34);
	
	\draw[line width=1.0pt,->] (h13) -- (h30);
	\draw[line width=1.0pt,->] (h13) -- (h31);
	\draw[line width=1.0pt,->] (h13) -- (h32);
	\draw[line width=1.0pt,->] (h13) -- (h33);
	\draw[line width=1.0pt,->] (h13) -- (h34);;
	
	\draw[line width=1.0pt,->] (h14) -- (h30);
	\draw[line width=1.0pt,->] (h14) -- (h31);
	\draw[line width=1.0pt,->] (h14) -- (h32);
	\draw[line width=1.0pt,->] (h14) -- (h33);
	\draw[line width=1.0pt,->] (h14) -- (h34);
	
	\draw[line width=1.0pt,->] (h15) -- (h30);
	\draw[line width=1.0pt,->] (h15) -- (h31);
	\draw[line width=1.0pt,->] (h15) -- (h32);
	\draw[line width=1.0pt,->] (h15) -- (h33);
	\draw[line width=1.0pt,->] (h15) -- (h34);
	
	\draw[line width=1.0pt,->] (h16) -- (h30);
	\draw[line width=1.0pt,->] (h16) -- (h31);
	\draw[line width=1.0pt,->] (h16) -- (h32);
	\draw[line width=1.0pt,->] (h16) -- (h33);
	\draw[line width=1.0pt,->] (h16) -- (h34);
	
	\node[circle, fill=yellow!100,inner sep=4pt] (o0) at (14, 1) {};	
	\node[circle, fill=yellow!100,inner sep=4pt] (o1) at (14, 0) {};	
	\node[circle, fill=yellow!100,inner sep=4pt] (o2) at (14, -1) {};		
	
	\draw[line width=1.0pt,->] (h30) -- (o0);
	\draw[line width=1.0pt,->] (h30) -- (o1);
	\draw[line width=1.0pt,->] (h30) -- (o2);
	
	\draw[line width=1.0pt,->] (h31) -- (o0);
	\draw[line width=1.0pt,->] (h31) -- (o1);
	\draw[line width=1.0pt,->] (h31) -- (o2);
	
	\draw[line width=1.0pt,->] (h32) -- (o0);
	\draw[line width=1.0pt,->] (h32) -- (o1);
	\draw[line width=1.0pt,->] (h32) -- (o2);
	
	\draw[line width=1.0pt,->] (h33) -- (o0);
	\draw[line width=1.0pt,->] (h33) -- (o1);
	\draw[line width=1.0pt,->] (h33) -- (o2);
	
	\draw[line width=1.0pt,->] (h34) -- (o0);
	\draw[line width=1.0pt,->] (h34) -- (o1);
	\draw[line width=1.0pt,->] (h34) -- (o2);
	
	\node[circle] (y0) at (16, 1) {};
	\node[circle] (y1) at (16, 0) {};
	\node[circle] (y2) at (16, -1) {};
	\node[] (input) at (14.5, -3.75) {Out layer};
	
	\draw[line width=1.0pt,->] (o0) -- node[above]{$y_0$}(y0);
	\draw[line width=1.0pt,->] (o1) -- node[above]{$y_1$}(y1);
	\draw[line width=1.0pt,->] (o2) -- node[above]{$y_2$}(y2);	
	\end{tikzpicture}
	\caption{ \small Fully connected DNN}
	\label{fig03}
\end{figure}

inner sep 代表内部元素距离边界的距离 

\node[circle, fill=green!60,inner sep=4pt]---圆形,填充色彩为绿色,填充度60%

\draw[line width=1.0pt,->] --------画线,线宽1.0pt,箭头向有

结果如下:

上面画DNN有些麻烦,可参照这个链接精简代码 https://www.cnblogs.com/lqc-nogi/p/10483267.html (使用latex绘制多层神经网络结构图) 或者 LaTex中使用循环连续绘图的例子 https://blog.csdn.net/rumswell/article/details/37962003

\begin{figure}%[H]
	\begin{center}
		\begin{tikzpicture}[scale=0.7]			
		\node[circle, fill=red!50,inner sep=2.25pt] (x) at  (-1,3){\huge$\bm{x}$};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h01) at (1.5,-1){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h02) at (1.5,1){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h03) at (1.5,3){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h04) at (1.5,5){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h05) at (1.5,7){};
		
		\draw[line width=0.8pt,color=magenta,->] (x) --node[below, rotate=-60,yshift=0.5mm,color=black]{\small$a_{1}x$} (h01);
		\draw[line width=0.8pt,color=magenta,->] (x) --node[above,rotate=-40,yshift=-0.5mm,color=black]{\small$a_{2}x$} (h02);
		\draw[line width=0.8pt,color=magenta,->] (x) --node[above,yshift=-1mm,color=black]{$\cdots$} (h03);
		\draw[line width=0.8pt,color=magenta,->] (x) --node[below,rotate=35,yshift=0.5mm,color=black]{$\cdots$} (h04);
		\draw[line width=0.8pt,color=magenta,->] (x) --node[above, yshift=-0.5mm,rotate=60,color=black]{\small $a_{N}x$} (h05);
		
		
		\node[circle, fill=blue!50,inner sep=3.5pt] (h11) at (3.5,-1.0){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h12) at (3.5,1){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h13) at (3.5,3){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h14) at (3.5,5){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h15) at (3.5,7){};
		\node[circle, fill=blue!0,inner sep=1.5pt] (DNN) at (3.5,-2){DNN};
		
		\draw[line width=0.8pt,color=magenta,->] (h01) -- (h11);
		\draw[line width=0.8pt,color=magenta,->] (h01) -- (h12);
		\draw[line width=0.8pt,color=magenta,->] (h01) -- (h13);
		\draw[line width=0.8pt,color=magenta,->] (h01) -- (h14);
		\draw[line width=0.8pt,color=magenta,->] (h01) -- (h15);
		
		\draw[line width=0.8pt,color=magenta,->] (h02) -- (h11);
		\draw[line width=0.8pt,color=magenta,->] (h02) -- (h12);
		\draw[line width=0.8pt,color=magenta,->] (h02) -- (h13);
		\draw[line width=0.8pt,color=magenta,->] (h02) -- (h14);
		\draw[line width=0.8pt,color=magenta,->] (h02) -- (h15);
		
		\draw[line width=0.8pt,color=magenta,->] (h03) -- (h11);
		\draw[line width=0.8pt,color=magenta,->] (h03) -- (h12);
		\draw[line width=0.8pt,color=magenta,->] (h03) -- (h13);
		\draw[line width=0.8pt,color=magenta,->] (h03) -- (h14);
		\draw[line width=0.8pt,color=magenta,->] (h03) -- (h15);
		
		\draw[line width=0.8pt,color=magenta,->] (h04) -- (h11);
		\draw[line width=0.8pt,color=magenta,->] (h04) -- (h12);
		\draw[line width=0.8pt,color=magenta,->] (h04) -- (h13);
		\draw[line width=0.8pt,color=magenta,->] (h04) -- (h14);
		\draw[line width=0.8pt,color=magenta,->] (h04) -- (h15);
		
		\draw[line width=0.8pt,color=magenta,->] (h05) -- (h11);
		\draw[line width=0.8pt,color=magenta,->] (h05) -- (h12);
		\draw[line width=0.8pt,color=magenta,->] (h05) -- (h13);
		\draw[line width=0.8pt,color=magenta,->] (h05) -- (h14);
		\draw[line width=0.8pt,color=magenta,->] (h05) -- (h15);
		
		\node[circle, fill=blue!50,inner sep=3.5pt] (h21) at (5.5,-1.0){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h22) at (5.5,1){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h23) at (5.5,3){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h24) at (5.5,5){};
		\node[circle, fill=blue!50,inner sep=3.5pt] (h25) at (5.5,7){};
		\node[circle, fill=green!50,inner sep=0.5pt,text width=1.1cm] (u) at (7.5,3){$y(\bm{x};\bm{\theta})$};
		
		\draw[line width=0.8pt,color=magenta,->] (h11) -- (h21);
		\draw[line width=0.8pt,color=magenta,->] (h11) -- (h22);
		\draw[line width=0.8pt,color=magenta,->] (h11) -- (h23);
		\draw[line width=0.8pt,color=magenta,->] (h11) -- (h24);
		\draw[line width=0.8pt,color=magenta,->] (h11) -- (h25);
		
		\draw[line width=0.8pt,color=magenta,->] (h12) -- (h21);
		\draw[line width=0.8pt,color=magenta,->] (h12) -- (h22);
		\draw[line width=0.8pt,color=magenta,->] (h12) -- (h23);
		\draw[line width=0.8pt,color=magenta,->] (h12) -- (h24);
		\draw[line width=0.8pt,color=magenta,->] (h12) -- (h25);
		
		\draw[line width=0.8pt,color=magenta,->] (h13) -- (h21);
		\draw[line width=0.8pt,color=magenta,->] (h13) -- (h22);
		\draw[line width=0.8pt,color=magenta,->] (h13) -- (h23);
		\draw[line width=0.8pt,color=magenta,->] (h13) -- (h24);
		\draw[line width=0.8pt,color=magenta,->] (h13) -- (h25);
		
		\draw[line width=0.8pt,color=magenta,->] (h14) -- (h21);
		\draw[line width=0.8pt,color=magenta,->] (h14) -- (h22);
		\draw[line width=0.8pt,color=magenta,->] (h14) -- (h23);
		\draw[line width=0.8pt,color=magenta,->] (h14) -- (h24);
		\draw[line width=0.8pt,color=magenta,->] (h14) -- (h25);
		
		\draw[line width=0.8pt,color=magenta,->] (h15) -- (h21);
		\draw[line width=0.8pt,color=magenta,->] (h15) -- (h22);
		\draw[line width=0.8pt,color=magenta,->] (h15) -- (h23);
		\draw[line width=0.8pt,color=magenta,->] (h15) -- (h24);
		\draw[line width=0.8pt,color=magenta,->] (h15) -- (h25);
		
		\draw[line width=0.8pt,color=magenta,->] (h21) -- (u);
		\draw[line width=0.8pt,color=magenta,->] (h22) -- (u);
		\draw[line width=0.8pt,color=magenta,->] (h23) -- (u);
		\draw[line width=0.8pt,color=magenta,->] (h24) -- (u);
		\draw[line width=0.8pt,color=magenta,->] (h25) -- (u);
		
		
		\node[circle, fill=green!60,inner sep=0.1pt] (gradU) at (8.75, 5) {\small$\nabla y(\bm{x};\bm{\theta})$};					
		
		\node[circle, fill=green!60,inner sep=1.0pt] (Ax) at (7.5, 7.5) {$\kappa(\bm{x})$};
		\node[circle, fill=green!60,inner sep=1.25pt] (fx) at (10, 8) {$f(\bm{x})$};
		\draw[line width=0.8pt,,color=black, ->] (x)..controls(0,9) and (4,8.25)..(Ax);
		\draw[line width=0.8pt,,color=black, ->] (x)..controls(0,9) and (4,8.5)..(fx);	
		
		\node[rectangle, fill=yellow!60, inner sep=3pt](loss-bd) at (12,1.25) {$|y(\bm{x};\bm{\theta})-g(\bm{x})|^2~$ on $\bm{x}\in\partial \Omega$};
		\node[rectangle, fill=yellow!0, inner sep=2pt](loss-bd11) at (12.25,0.3) {$loss\_{bd}$};		
		\node[rectangle, fill=yellow!60, inner sep=2.5pt](loss-it1) at (15.85,5.0) {$\displaystyle \frac{1}{p}\int \kappa(\bm{x})|\nabla y(\bm{x};\bm{\theta})|^p-f(\bm{x})y(\bm{x};\bm{\theta})d\bm{x}$};
		\node[rectangle, fill=yellow!0, inner sep=2pt](loss-it11) at (15.5,6.25) {$loss\_{it}$};	
		
		
		\draw[line width=0.8pt,color=black, ->] (u) -- (gradU);
		\draw[line width=0.8pt,color=black, ->] (u) -- (loss-bd);		
		
		\draw[line width=0.8pt,color=black, ->] (Ax)..controls(8,7.25) and (10,5)..(loss-it1);
		\draw[line width=0.8pt,color=black, ->] (fx)..controls(10,6.5) and (10.5,5)..(loss-it1);
		\draw[line width=0.8pt,color=black,->] (gradU) -- (loss-it1);
		\draw[line width=0.8pt,color=black, ->] (u) ..controls(9,3.5) and (10,5).. (loss-it1);	
		
		\node[rectangle, fill=yellow!0, inner sep=0pt](loss-it-out) at (15.15,4.35) {};
		\node[rectangle, fill=yellow!0, inner sep=1pt](loss-bd-out) at (15.25,1.25){};
		\node[circle, fill=cyan!60, inner sep=2pt](loss) at (17.5,2.25){loss};
		\node[circle, fill=cyan!60, inner sep=2pt](theta) at (17.5,-0.5){$\bm{\theta}^*$};	
		
		\draw[line width=0.8pt,,color=black, ->] (loss-it-out) ..controls(15.65,3) and (16.25,2.5).. (loss);
		\draw[line width=0.8pt,,color=black, ->] (loss-bd-out) ..controls(15.5,2.25) and (16.25,2.5).. (loss);
		
		\draw[line width=0.8pt,color=black,->] (loss) -- node[right]{minimize} (theta);		
		\end{tikzpicture}
	\end{center}
	\caption{Schematic of a DNN for solving the $p$-Laplacian equation}
\end{figure}

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值