使用此代码,输出如下。为什么我的输入层中会出现多余的空心圆圈?我该如何去除它们?
加分点:我该如何在层之间叠加权重和偏差矩阵?
\begin{figure}
\begin{tikzpicture}[
% define styles
clear/.style={
draw=none,
fill=none
},
net/.style={
matrix of nodes,
nodes={ draw, circle, inner sep=10pt },
%nodes in empty cells,
column sep=2cm,
row sep=-9pt
},
>=latex
]
\matrix[net] (mat)
{
|[clear]| \parbox{1.3cm}{\centering Input\\layer}
& |[clear]| \parbox{1.3cm}{\centering Hidden\\layer 1}
& |[clear]| \parbox{1.3cm}{\centering Hidden\\layer 2}
& |[clear]| \parbox{1.3cm}{\centering Output\\layer} \\
& 10 (on) \\
2 & & 13 (on) \\
& 0 (off) & & 1 \\
1 & & 0 (off) \\
& 1 (on) \\
}
;
\foreach \ai in {3, 5} {
\foreach \aii in {2,4,6}
\draw[->] (mat-\ai-1) -- (mat-\aii-2);
}
\foreach \ai in {2, 4, 6} {
\foreach \aii in {3, 5}
\draw[->] (mat-\ai-2) -- (mat-\aii-3);
}
\foreach \ai in {3, 5} {
\foreach \aii in {4}
\draw[->] (mat-\ai-3) -- (mat-\aii-4);
}
\end{tikzpicture}
\end{figure}
答案1
罪魁祸首是你的 中的空行matrix
。删除它们。题外话,你可以写更简洁的代码,例如如下:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[
% define styles
net/.style={matrix of nodes,
nodes = {circle, draw, text width=2.4em, align=center,
inner sep=0pt, anchor=center},
row 1/.style = {nodes={rectangle, draw=none,
text width=4em, align=center,
inner sep=0pt, anchor=center}},
column sep=12mm,
row sep=6pt
},
>=latex
]
\matrix[net] (mat)
{
Input layer
& Hidden layer 1
& Hidden layer 2
& Output layer \\
& 10 (on) & & \\
2 & & 13 (on) & \\
& 0 (off) & & 1 \\
1 & & 0 (off) & \\
& 1 (on) & & \\
};
\foreach \ai in {3, 5} {
\foreach \aii in {2,4,6}
\draw[->] (mat-\ai-1) -- (mat-\aii-2);
}
\foreach \ai in {2, 4, 6} {
\foreach \aii in {3, 5}
\draw[->] (mat-\ai-2) -- (mat-\aii-3);
}
\foreach \ai in {3, 5} {
\foreach \aii in {4}
\draw[->] (mat-\ai-3) -- (mat-\aii-4);
}
\end{tikzpicture}
\end{document}
生产