我的神经网络:

我的神经网络:

我正在尝试绘制如下所示的神经网络,但我想在一开始就画一个正方形,具体来说:

我的神经网络:

\documentclass[12pt, oneside, letterpaper]{book}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{graphicx}
\usepackage{neuralnetwork}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\linklayers}{\nn@lastnode}{\lastnode}{}{}
\xpatchcmd{\linklayers}{\nn@thisnode}{\thisnode}{}{}
\begin{document}
\begin{figure}[h]
\centering
 \label{fig:arquitectura_autoencoder}
\begin{neuralnetwork}[height=9.5,nodespacing=1cm,nodesize=20pt,  layerspacing=3.6cm][h]

    %comandos previos
    \newcommand{\x}[2]{\ifthenelse{\equal{#2}{0}}{$b_0$}{\ifnum #2=8 $x_n$ \else $x_#2$ \fi}} %si es el índice cero, entonces le asignas b0, sino si es la neurona 8, lo cambias por el índice n
    \newcommand{\ffirst}[2]{\ifthenelse{\equal{#2}{0}}{$b_1$}
    {\ifnum #2=4 $a_{\frac{n}{2}}^{(2)}$ \else $a_{#2}^{(2)}$ \fi}}
    \newcommand{\fsecond}[2]{\ifthenelse{\equal{#2}{0}}{$b_2$}
    {\ifnum #2=3 $a_{\frac{n}{4}}^{(3)}$ \else $a_{#2}^{(3)}$ \fi}}
    \newcommand{\fthird}[2]{\ifthenelse{\equal{#2}{0}}{$b_3$}
    {\ifnum #2=4 $a_{\frac{n}{2}}^{(4)}$ \else$a_{#2}^{(4)}$ \fi}}
    \newcommand{\xhat}[2]{\ifthenelse{\equal{#2}{0}}{$b_0$}{\ifnum #2=8 $\hat{x}_n$ \else $\hat{x}_#2$ \fi}}

    %red neuronal
    \inputlayer[count=8, bias=true,exclude={7},title=Input\\layer, text=\x]
    \hiddenlayer[count=4, bias=true,exclude={3},title={$L_2$\\$f_{\cdot 2} = \tanh(x)$}, text=\ffirst] 
    \linklayers[not from={7},not to={3}] %para que no dibuje la flecha desde la neurona 7
    \hiddenlayer[count=3, bias=true,exclude={2}, title={$L_3$\\$f_{\cdot 3} = ReLU(x) $}, text=\fsecond]
    \linklayers[not from={3},not to={2}]
    \hiddenlayer[count=4, bias=true,exclude={3}, title={$L_4$\\$f_{\cdot 4} = \tanh(x)$}, text=\fthird]
    \linklayers[not from={2},not to={3}]
    \outputlayer[count=8, exclude={7},title={Output layer\\$\hat{x}_i=a_{i}^{(5)}$}, text=\xhat]
    \linklayers[not to={7},not from={3}]


     % draw dots
    \path (L0-6) -- node{$\vdots$} (L0-8);
    \path (L1-2) -- node{$\vdots$} (L1-4);
    \path (L2-1) -- node{$\vdots$} (L2-3);
    \path (L3-2) -- node{$\vdots$} (L3-4);
    \path (L4-6) -- node{$\vdots$} (L4-8);

\end{neuralnetwork}
\end{figure}
\end{document}

生成:

在此处输入图片描述

我想要的是类似的东西,但我想要在输入层和输出层之前放一个小方块,因为我想添加更多信息。我附上了一个我想要的类似图像。

我想要的是:

在此处输入图片描述

这可能做到吗?我认为这很难。

答案1

没有这个neuralnetwork包,绘制出你想要的截图之类的东西还是相当容易的。

\documentclass[12pt, oneside, letterpaper]{book}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,shapes.geometric}
\begin{document}
\begin{figure}[h]
\centering
 \begin{tikzpicture}[neuron/.style={ellipse,minimum width=1.2em,minimum
    height=1.6em,draw,thick},
    box/.style={draw,minimum height=3.4em+#1,text width=2em,align=center},
    font=\sffamily\tiny,yscale=1.25,node distance=1cm,
    every label/.append style={node font=\tiny},
    Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    dash pattern=on 0.1\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=2mm,shorten <=2mm,line width=2pt},
    Dotted/.default=4,thick]
  \begin{scope}[local bounding box=neurons]
   \path foreach \X in {1,...,4}
   {(-2,{-\X-(\X==4)*1.5}) node[neuron](x\X){} 
    \ifnum\X=4
      edge[Dotted,line width=2pt] (x3)
    \fi
    (2,{-\X-(\X==4)*1.5}) node[neuron](y\X){}
    \ifnum\X=4
      edge[Dotted] (y3)
    \fi};
   \path foreach \Y in {1,2,3} 
   {([yshift=2cm-\Y cm]neurons.center) 
    node[neuron,label=above:N\Y] (N\Y){}
    foreach \X in {1,...,4} { edge (x\X) edge (y\X)}};
  \end{scope}
  \node[above=6mm of N1,align=center]{Hidden\\ Nodes};
  \path let \p1=($(neurons.north)-(neurons.south)$) in
   node[box=\y1,left=of neurons] (PCAC) {PCA Compression}
   node[box=\y1+2cm,left=of PCAC] (Ori) {Original HIV Data}
   node[box=\y1,right=of neurons] (PCAD) {PCA Deompression}
   node[box=\y1+2cm,right=of PCAD] (Pre) {Predicted HIV Data};
  \draw foreach \X in {1,...,4}
  { (x\X) -- node[near start,above]{x\X} (PCAC.east|-x\X)
  (y\X) -- node[near start,above]{y\X} (PCAD.west|-y\X)};
  \draw foreach \X [count=\Y] in {0.1,0.2,0.3,0.4,0.9}
  { ($(PCAC.north west)!\X!(PCAC.south west)$)
    -- coordinate (w\Y) ($(Ori.north east)!\X!(Ori.south east)$)
    ($(PCAD.north east)!\X!(PCAD.south east)$)
    -- coordinate (e\Y) ($(Pre.north west)!\X!(Pre.south west)$)}
   (w4) edge[Dotted] (w5) (e4) edge[Dotted] (e5);
 \end{tikzpicture}
\caption{A neuronal network.}
\label{fig:arquitectura_autoencoder}
\end{figure}
\end{document}

在此处输入图片描述

相关内容