<gh_stars>100-1000
\documentclass[crop, tikz]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{amsbsy}

\usetikzlibrary{automata, chains, decorations.pathmorphing, positioning}

\definecolor{echodrk}{HTML}{0099cc}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}
\begin{tikzpicture} [scale=1.3, every node/.style={transform shape},start chain=1 going right, start chain=2 going right]

	\node[state, fill=red!20, on chain=1, very thick, text depth=0pt] (1) {$s_0$};
	\node[state, fill=red!20, on chain=1, very thick, text depth=0pt] (2) {$s_1$};
	\node[state, fill=red!20, on chain=1, very thick, text depth=0pt] (3) {$s_2$};
	\node[on chain=1] (md) {\dots};
	\node[state, fill=red!20, on chain=1, very thick, text depth=0pt] (n) {$s_n$};
	\draw[>=stealth, color=red, text=black, very thick, auto=right,loop above/.style={out=75,in=105,loop}, every loop]
		(1) edge node[above] {\footnotesize$\boldsymbol \omega_{11}$} (2)
		(2) edge node[above] {\footnotesize$\boldsymbol \omega_{11}$} (3)
		(3) edge node[above] {\footnotesize$\boldsymbol \omega_{11}$} (md)
		(md) edge node[above] {\footnotesize$\boldsymbol \omega_{11}$} (n);
					
	\node[rectangle, thick, fill=red!20, draw] at (-2, 1.7) (y1) {$id_0$};
	\node[rectangle, thick, fill=red!20, draw] at (0, 1.7) (y2) {$id_1$};
	\node[rectangle, thick, fill=red!20, draw] at (2, 1.7) (y3) {$id_2$};
	\node at (4, 1.7) (ymd) {\dots};
	\node[rectangle, thick, fill=red!20, draw] at (6, 1.7) (yn) {$id_n$};
				
	\draw[-stealth, color=red, text=black, very thick, dashed]
		(1) edge node[right] {${\bf O'}_{0,id_0}^1$} (y1)
		(2) edge node[right] {${\bf O'}_{1,id_1}^1$} (y2)
		(3) edge node[right] {${\bf O'}_{2,id_2}^1$} (y3)
		(n) edge node[right] {${\bf O'}_{n,id_n}^1$} (yn);
				
	\node[rectangle] at (-1, 4) (gauss1) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-2:2,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=red!10] {gauss(0,0.5)} \closedcycle;
					\draw[red!80,-stealth] (axis cs:0.5,0) -- (axis cs:0.5,0.47);
			\end{axis}
		\end{tikzpicture}
	};
				
	\node[rectangle] at (1, 4) (gauss2) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-5:5,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=red!10] {gauss(-1,0.8)} \closedcycle;
					\draw[red!80,-stealth] (axis cs:-2.3,0) -- (axis cs:-2.3,0.121);
			\end{axis}
		\end{tikzpicture}
	};

	\node[rectangle] at (3, 4) (gauss3) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-4:4,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=red!10] {gauss(2,0.5)} \closedcycle;
					\draw[red!80,-stealth] (axis cs:2.3,0) -- (axis cs:2.3,0.64);
			\end{axis}
		\end{tikzpicture}
	};
				
	\node at (5, 4) (gaussmd) {\dots};
				
	\node[rectangle] at (7, 4) (gaussn) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-1.5:1.5,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=red!10] {gauss(0.1,0.5)} \closedcycle;
					\draw[red!80,-stealth] (axis cs:0.1,0) -- (axis cs:0.1,0.795);
			\end{axis}
		\end{tikzpicture}
	};
				
	\draw[-stealth, color=red, text=black, very thick, dotted]
		(y1) edge node[left] {$\mu_{id_0}^1$} node[right] {$\sigma_{id_0}^1$} (gauss1)
		(y2) edge node[left] {$\mu_{id_1}^1$} node[right] {$\sigma_{id_1}^1$} (gauss2)
		(y3) edge node[left] {$\mu_{id_2}^1$} node[right] {$\sigma_{id_2}^1$} (gauss3)
		(yn) edge node[left] {$\mu_{id_n}^1$} node[right] {$\sigma_{id_n}^1$} (gaussn);
	%%%%%% BOUNDARY %%%%%%%
					
	%%%%%% BOUNDARY %%%%%%%
	\node[state, fill=echodrk!20, on chain=2, very thick, text depth=0pt] (21) at (0, -2) {$s_0$};
	\node[state, fill=echodrk!20, on chain=2, very thick, text depth=0pt] (22) {$s_1$};
	\node[state, fill=echodrk!20, on chain=2, very thick, text depth=0pt] (23) {$s_2$};
	\node[on chain=2] (2md) {\dots};
	\node[state, fill=echodrk!20, on chain=2, very thick, text depth=0pt] (2n) {$s_n$};
	\draw[>=stealth, color=blue, text=black, very thick, auto=right,loop above/.style={out=75,in=105,loop}, every loop]
		(21) edge node[below] {\footnotesize$\boldsymbol \omega_{22}$} (22)
		(22) edge node[below] {\footnotesize$\boldsymbol \omega_{22}$} (23)
		(23) edge node[below] {\footnotesize$\boldsymbol \omega_{22}$} (2md)
		(2md) edge node[below] {\footnotesize$\boldsymbol \omega_{22}$} (2n);
					
	\node[rectangle, thick, fill=echodrk!20, draw] at (-2, -3.7) (2y1) {$id_0$};
	\node[rectangle, thick, fill=echodrk!20, draw] at (0, -3.7) (2y2) {$id_1$};
	\node[rectangle, thick, fill=echodrk!20, draw] at (2, -3.7) (2y3) {$id_2$};
	\node at (4, -3.7) (2ymd) {\dots};
	\node[rectangle, thick, fill=echodrk!20, draw] at (6, -3.7) (2yn) {$id_n$};
				
	\draw[-stealth, color=blue, text=black, very thick, dashed]
		(21) edge node[right] {${\bf O'}_{0,id_0}^2$} (2y1)
		(22) edge node[right] {${\bf O'}_{1,id_1}^2$} (2y2)
		(23) edge node[right] {${\bf O'}_{2,id_2}^2$} (2y3)
		(2n) edge node[right] {${\bf O'}_{n,id_n}^2$} (2yn);
				
	\node[rectangle] at (-1, -6) (2gauss1) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-4:4,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=echodrk!10] {gauss(2,0.5)} \closedcycle;
					\draw[blue!80,-stealth] (axis cs:2.3,0) -- (axis cs:2.3,0.64);
			\end{axis}
		\end{tikzpicture}
	};
			
	\node[rectangle] at (1, -6) (2gauss2) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-1.5:1.5,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=echodrk!10] {gauss(0.1,0.5)} \closedcycle;
					\draw[blue!80,-stealth] (axis cs:0.1,0) -- (axis cs:0.1,0.795);
			\end{axis}
		\end{tikzpicture}
	};
				
	\node[rectangle] at (3, -6) (2gauss3) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-2:2,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=echodrk!10] {gauss(0,0.5)} \closedcycle;
					\draw[blue!80,-stealth] (axis cs:0.5,0) -- (axis cs:0.5,0.47);
			\end{axis}
		\end{tikzpicture}
	};
				
	\node at (5, -6) (2gaussmd) {\dots};
				
	\node[rectangle] at (7, -6) (2gaussn) {
		\begin{tikzpicture}	
			\begin{axis}[scale=0.25, axis on top, x tick label style={major tick length=0pt}, every axis plot post/.append style={mark=none,domain=-5:5,samples=50,smooth},
				axis x line=bottom,
				axis y line=left,
				yticklabels={,,},
				xticklabels={,,},
				xtick=\empty, ytick=\empty,
				enlargelimits=false, clip=false]
					\addplot[fill=echodrk!10] {gauss(-1,0.8)} \closedcycle;
					\draw[blue!80,-stealth] (axis cs:-2.3,0) -- (axis cs:-2.3,0.121);
			\end{axis}
		\end{tikzpicture}
	};
				
	\draw[-stealth, color=blue, text=black, very thick, dotted]
		(2y1) edge node[left] {$\mu_{id_0}^2$} node[right] {$\sigma_{id_0}^2$} (2gauss1)
		(2y2) edge node[left] {$\mu_{id_1}^2$} node[right] {$\sigma_{id_1}^2$} (2gauss2)
		(2y3) edge node[left] {$\mu_{id_2}^2$} node[right] {$\sigma_{id_2}^2$} (2gauss3)
		(2yn) edge node[left] {$\mu_{id_n}^2$} node[right] {$\sigma_{id_n}^2$} (2gaussn);	
					
	%%%% COMBO %%%%%
	\draw[-stealth, very thick, auto=right,decoration={snake, segment length=2mm, amplitude=0.5mm,post length=1.5mm}]
		(1) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{12}$} (22)
		(2) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{12}$} (23)
		(3) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{12}$} (2md)
		(md) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{12}$} (2n);
	
	\draw[-stealth, very thick, auto=right,decoration={snake, segment length=2mm, amplitude=0.5mm,post length=1.5mm}]
		(21) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{21}$} (2)
		(22) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{21}$} (3)
		(23) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{21}$} (md)
		(2md) edge[decorate] node[left, near start] {\footnotesize$\boldsymbol \omega_{21}$} (n);
				
	%%%% START STATES %%%%%
	\node[text depth=0pt] at (-2, -1) (S) {start};
	
	\draw[-stealth, very thick, auto=right,decoration={snake, segment length=2mm, amplitude=0.5mm,post length=1.5mm}]
		(S) edge[decorate] node[above] {\footnotesize$\pi_1$} (1)
		(S) edge[decorate] node[below] {\footnotesize$\pi_2$} (21);
\end{tikzpicture}
\end{document}
