我想使用这个神经网络图并将其扩展到循环神经网络。为此,我想安排隐节点组成一个环,并将每个隐藏节点与其他隐藏节点连接起来。这是我从这里。有人能告诉我如何才能完成我需要做的事情吗?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\def\layersep{2.5cm}
\begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=\layersep]
\tikzstyle{every pin edge}=[<-,shorten <=1pt]
\tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
\tikzstyle{input neuron}=[neuron, fill=green!50];
\tikzstyle{output neuron}=[neuron, fill=red!50];
\tikzstyle{hidden neuron}=[neuron, fill=blue!50];
\tikzstyle{annot} = [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:Input \#\y] (I-\name) at (0,-\y) {};
% Draw the hidden layer nodes
\foreach \name / \y in {1,...,5}
\path[yshift=0.5cm]
node[hidden neuron] (H-\name) at (\layersep,-\y cm) {};
% Draw the output layer node
\node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-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 (H-\dest);
% Connect every node in the hidden layer with the output layer
\foreach \source in {1,...,5}
\path (H-\source) edge (O);
% Annotate the layers
\node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
\node[annot,left of=hl] {Input layer};
\node[annot,right of=hl] {Output layer};
\end{tikzpicture}
% End of code
\end{document}
此致。
答案1
不知为何,你问的是什么不太清楚。你想有多个隐藏层吗?那么输出层连接怎么样?我根据我对你问题的理解做了一些事情。如果这不是你想要的,请评论。我的答案是基于你自己的代码和这例子。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary[topaths]
\newcount\mycount
\begin{document}
\begin{tikzpicture}[transform shape]
\tikzstyle{every pin edge}=[<-,shorten <=1pt]
\tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
\tikzstyle{input neuron}=[neuron, fill=green!50];
\tikzstyle{output neuron}=[neuron, fill=red!50];
\tikzstyle{hidden neuron}=[neuron, fill=blue!50];
\tikzstyle{annot} = [text width=4em, text centered]
% input layer
\foreach \name / \y in {1,...,4}
\node[input neuron, pin=left:Input \#\y] (I-\name) at (0,-\y) {};
% hidden layer nodes
\foreach \number in {1,...,6}{
\mycount=\number
\advance\mycount by -1
\multiply\mycount by 60
\advance\mycount by 0
\node[xshift=5cm, yshift=-2.5cm, hidden neuron] (N-\number) at (\the\mycount:3cm) {};
}
% hidden layer interconnections
\foreach \number in {1,...,5}{
\mycount=\number
\advance\mycount by 1
\foreach \numbera in {\the\mycount,...,6}{
\path (N-\number) edge[<->] (N-\numbera);
}
}
% output layer
\node[xshift=10cm, yshift=-2.5cm,output neuron,pin={[pin edge={->}]right:Output}] (O) {};
% input-hidden-output connections
\foreach \source in {1,...,4}
\foreach \dest in {3,4,5}
\path (I-\source) edge[->] (N-\dest);
\foreach \source in {1,2,6}
\path (N-\source) edge[->] (O);
\end{tikzpicture}
\end{document}