在 Tikz 中添加马尔可夫模型并在节点旁列出字母

在 Tikz 中添加马尔可夫模型并在节点旁列出字母

我已经画了一个框图,但我想添加一些特殊的符号/图形,比如马尔可夫模型、一些虚线、特定位置的字符列表以及下图所示的波形。

在此处输入图片描述

这也是我灵感来源的原始图片。我希望新元素的尺寸与原始元素成比例(它们没有缩放,因为我不知道如何缩放)如能提供任何帮助,在此先行致谢! 在此处输入图片描述

我迄今为止的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,arrows,calc,positioning,shapes, shadows}
\usetikzlibrary{tikzmark,calc,decorations.pathreplacing}

\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance=1.5cm]

\node (speech) {Speech};
\node [block, right of=speech, xshift=1.2cm] (feat) {Feature extraction}; 
\node [block, right of=feat,  xshift=3cm] (dec) {Decoder};
\node [block, below of=dec, xshift=2.2cm, yshift=-0.5cm] (LM) {Language model}; 
\node at (LM.north) [above, text width=3cm, align=center] {Sentence level matcher};
\node [block, left of=LM, xshift=-2.2cm] (lex) {Lexicon}; 
\node at (lex.north) [above, text width=3cm, align=center] {Word-level matcher};
\coordinate (RSmid) at ($(LM.north east)!0.5!(lex.north west)$);
\coordinate (RSmid2) at ($(LM.south east)!0.5!(lex.south west)$);
\node [block, above of=dec, yshift=0.5cm] (acous) {Acoustic Model};
\node [right of= dec, xshift=3.1cm](txt) {Text};

\path [l] (feat) -- (dec);
\path [l] (lex) -| ([xshift=-1cm]dec);
\draw (acous) edge [auto=left] node {Phone-matcher level} (dec);
\path [l] (LM) -| ([xshift=1cm]dec);
\path [l] (dec) -- (txt);
\path [l] (speech.east) -- (feat);
\end{tikzpicture}
\end{figure}

\end{document}

答案1

block不幸的是,您原本不错的 MWE 中缺少和的定义l,所以我不得不猜测。接下来,我将介绍两种放置这些内容的方法:范围和多部分节点。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,arrows,calc,positioning,shapes, shadows}
\usetikzlibrary{tikzmark,calc,decorations.pathreplacing,shapes.multipart}
\tikzset{block/.style={draw},
l/.style={draw,-}} % <- I made this up
\tikzset{boxed/.style={path picture={
\coordinate (ll) at (path picture bounding box.south west);
\coordinate (ur) at (path picture bounding box.north east);
},% inspired by https://tex.stackexchange.com/a/423952/121799
}}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance=1.5cm,font=\sffamily]
\node (speech) {Speech};
\node [block, right of=speech, xshift=1.2cm] (feat) {Feature extraction}; 
\node [block, right of=feat,  xshift=3cm] (dec) {Decoder};
\node [block, below of=dec, xshift=2.2cm, yshift=-0.5cm] (LM) {Language model}; 
\node at (LM.north) [above, text width=3cm, align=center] {Sentence level matcher};
\node [block, left of=LM, xshift=-2.2cm] (lex) {Lexicon}; 
\node at (lex.north) [above, text width=3cm, align=center] {Word-level\\ matcher};
\coordinate (RSmid) at ($(LM.north east)!0.5!(lex.north west)$);
\coordinate (RSmid2) at ($(LM.south east)!0.5!(lex.south west)$);
\node [block, above of=dec, yshift=0.5cm] (acous) {Acoustic Model};
\node [right of= dec, xshift=3.1cm](txt) {Text};
\path [l] (feat) -- (dec);
\path [l] (lex) -| ([xshift=-1cm]dec);
\draw (acous) edge [auto=left] node {Phone-matcher level} (dec);
\path [l] (LM) -| ([xshift=1cm]dec);
\path [l] (dec) -- (txt);
\path [l] (speech.east) -- (feat);
% first example: move a scope to a node
\begin{scope}[shift=(acous)]
\foreach \X [count=\Y] in {-1,0,1}
{
\node[circle,draw,minimum width=0.6cm] (c\Y) at (\X,1){};
\draw[-latex] (c\Y.north west) to[out=120,in=60,looseness=3]  (c\Y.north east);
}
\draw (1.5,0.5)-- ++(0.2,0) -- ++(0,1.1) coordinate[midway,right]
(x1) -- ++(-0.2,0) ;
\draw[-latex] (x1) -- ++(0.2,0) node[right] {/b/};
\end{scope}
% second example: use multipart nodes
\node[left=0.5cm of lex,rectangle split,rectangle split parts=6,rectangle split
part align=left] (lexr) 
{/b/
\nodepart{two}
/d/
\nodepart{three}
.
\nodepart{four}
.
\nodepart{five}
.
\nodepart{six}
/ch/
};
\draw (lexr.north east) -- +(-0.2,0)  (lexr.south east) -- +(-0.2,0)
(lexr.north east) -- (lexr.south east) coordinate[midway] (x2);
\draw[-latex] (x2) -- ++(0.2,0);
%
\node[right=0.5cm of LM,rectangle split,rectangle split parts=6,rectangle split
part align=left] (LMr) 
{/m o/
\nodepart{two}
/t o/
\nodepart{three}
.
\nodepart{four}
.
\nodepart{five}
.
\nodepart{six}
/ch/
};
\draw (LMr.north west) -- +(0.2,0)  (LMr.south west) -- +(0.2,0)
(LMr.north west) -- (LMr.south west) coordinate[midway] (x3);
\draw[-latex] (x3) -- ++(-0.2,0);
%
\begin{scope}[shift=(speech)]
\draw[boxed] plot[variable=\x,samples=100,domain=-1:1]
({\x},{1.3+sin(deg(\x)*(\x-2)*5)*cos(deg(2*\x))}); 
\end{scope}
\draw (ur|-speech.south) -- ++(0,0.2) (ll|-speech.south) -- ++(0,0.2)
(ur|-speech.south) -- (ll|-speech.south) coordinate[midway] (x4);
\draw[-latex] (x4) -- ++(0,-0.2);
%
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

我标记了修改或添加的内容。如果您有疑问,请告诉我。

相关内容