神经网络图标记问题

神经网络图标记问题

我有一个使用包绘制的神经网络图neuralnetwork。我在标记方面有问题。从输入到隐藏层的标签应该是,1,2,3,4,5,6但代码给了我1,2,3,1,2,3。我该如何纠正它?

代码

\documentclass{standalone}
\usepackage{neuralnetwork}
\usetikzlibrary{positioning}
\usepackage{lmodern}

\begin{document}
\newcommand{\biasx}[2]{\ifnum0=#2 1 \else $x_#2$ \fi}
\newcommand{\ys}[2]{$y$}
\newcommand{\linki}[4]{\ifcase#2 $1$ \or $2$ \or $3$ \or $4$ \or $5$ \or $6$ \fi}
\newcommand{\hid}[2]{\ifcase#2 $1$ \or $a_1^{(2)}$ \or $a_2^{(2)}$ \fi}
\newcommand{\linkii}[4]{\ifcase#2 $7$ \or $8$ \or $9$ \fi}

\tikzset{weight/.style = {above,sloped,font=\scriptsize,outer sep=0.7} }

\setdefaultnodetext{\boslar}
    \begin{neuralnetwork} [nodespacing=20mm, layerspacing=25mm, maintitleheight=2.5em, layertitleheight=2.5em,
    height=4, toprow=false, nodesize=17pt, style={}, title={}, titlestyle={}]
% 
    \inputlayer[count=2, bias=true, text=\biasx]
    \hiddenlayer[count=2,bias=true,text=\hid]
            \linklayers[title={},style={weight},labels={\linki},not from={},not to={}]
    \outputlayer[count=1,bias=false,text=\ys]
            \linklayers[title={},style={weight},labels={\linkii},not from={},not to={}]
    \node[right= 0.5cm of L2-1] (y) {$h_\theta\left(\mathbf{x}\right)$};
    \draw[->, thin, draw=black!45](L2-1) edge (y);
%   
    \end{neuralnetwork}    
\end{document}

输出

在此处输入图片描述

答案1

该包neuralnetwork没有实际的文档,我不知道它是错误还是功能。

但是,您可以轻松解决您的问题,删除错误\linklayers并添加一些标准 TiZ\draw命令(为了方便起见,我把它们放在两个嵌套的命令中\foreach)。

\documentclass{standalone}
\usepackage{neuralnetwork}
\usetikzlibrary{positioning}
\usepackage{lmodern}

\newcommand{\biasx}[2]{\ifnum0=#2 1 \else $x_#2$ \fi}
\newcommand{\ys}[2]{$y$}
\newcommand{\hid}[2]{\ifcase#2 $1$ \or $a_1^{(2)}$ \or $a_2^{(2)}$ \fi}
\newcommand{\linkii}[4]{\ifcase#2 $7$ \or $8$ \or $9$ \fi}

\tikzset{
    weight/.style ={above,sloped,font=\scriptsize,outer sep=0.7},
    myar/.style ={->, thin, draw=black!45},
    }

\setdefaultnodetext{\boslar}
\begin{document}
    \begin{neuralnetwork}[nodespacing=20mm, 
        layerspacing=25mm, 
        maintitleheight=2.5em, 
        layertitleheight=2.5em,
        height=4, 
        toprow=false, 
        nodesize=17pt, 
        style={}, 
        title={}, 
        titlestyle={}
        ]
        \inputlayer[count=2, bias=true, text=\biasx]
        \hiddenlayer[count=2,bias=true,text=\hid]
        \outputlayer[count=1,bias=false,text=\ys]
            \linklayers[title={},style={weight},labels={\linkii},not from={},not to={}]
        \node[right= 0.5cm of L2-1] (y) {$h_\theta\left(\mathbf{x}\right)$};
        \draw[myar](L2-1) edge (y);
        \foreach \i in {0,1,2}{%
            \foreach[evaluate=\i as \num using int(2*(\i)+\j)] \j in {1,2}{%
                \draw[myar, shorten > =1pt](L0-\i) edge node[weight, near start, inner sep=0pt]{$\num$} (L1-\j);
                }
            }
    \end{neuralnetwork}    
\end{document}

在此处输入图片描述

相关内容