I need to draw the following diagram using TikZ package in LaTeX
I wrote the following code so far but the result is really bad.
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{decorations.pathmorphing} % noisy shapes
\usetikzlibrary{fit} % fitting shapes to coordinates
\usetikzlibrary{backgrounds} % drawing the background after the foreground
\begin{document}
\begin{figure}[htbp]
\centering
\tikzstyle{measurement}=[circle, thick, minimum size=1.2cm, draw=orange!50, fill=orange!20]
\tikzstyle{input}=[circle, thick, minimum size=1.2cm, draw=purple!50, fill=purple!20]
\tikzstyle{noise}=[circle, thick, minimum size=1.2cm, draw=yellow!50, fill=yellow!20]
\tikzstyle{matrx}=[circle, thick, minimum size=1.2cm, draw=violet!50, fill=violet!20]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{tikzpicture}[>=latex,text height=1.5ex,text depth=0.25ex]
\matrix[row sep=0.5cm,column sep=0.75cm] {
% First line
&
\node (a_1) {$\theta_1$}; &
\node (b_1) {$\mu_1$}; &
&
\node (c_1) {$\mu_1$}; &
&
\node (d_1) {$\mu_1$}; &
\node (e_1) {}; \\
% Second line
&
\node (p_1) {$\Lambda_1$}; &
\node (S_1) [input]{$\mathbf{S}_{1}$}; &
&
\node (I_1) [input]{$\mathbf{I}_{1}$}; &
&
\node (A_1) [input]{$\mathbf{A}_{1}$}; &
\node (q_1) {$\delta_1$}; \\
% Third line
&
\node (a_2) {$\theta_2$}; &
\node (b_2) {$\mu_2$}; &
&
\node (c_2) {$\mu_2$}; &
&
\node (d_2) {$\mu_2$}; &
\node (e_2) {}; \\
% Fourth line
&
\node (p_2) {$\Lambda_2$}; &
\node (S_2) [measurement] {$\mathbf{S}_{2}$}; &
&
\node (I_2) [measurement] {$\mathbf{I}_{2}$}; &
&
\node (A_2) [measurement] {$\mathbf{A}_{2}$}; &
\node (q_2) {$\delta_2$}; \\
% Fifth line
&
\node (a_3) {$\theta_3$}; &
\node (b_3) {$\mu_3$}; &
&
\node (c_3) {$\mu_3$}; &
&
\node (d_3) {$\mu_3$}; &
\node (e_3) {}; \\
% Sixth line
&
\node (p_3) {$\Lambda_3$}; &
\node (S_3) [matrx] {$\mathbf{S}_{3}$}; &
&
\node (I_3) [matrx] {$\mathbf{I}_{3}$}; &
&
\node (A_3) [matrx] {$\mathbf{A}_{3}$}; &
\node (q_3) {$\delta_3$}; \\
% Seventh line
&
\node (a_4) {$\theta_4$}; &
\node (b_4) {$\mu_4$}; &
&
\node (c_4) {$\mu_4$}; &
&
\node (d_4) {$\mu_4$}; &
\node (e_4) {}; \\
% Eigth line
&
\node (p_4) {$\Lambda_4$}; &
\node (S_4) [noise] {$\mathbf{S}_{4}$}; &
&
\node (I_4) [noise] {$\mathbf{I}_{4}$}; &
&
\node (A_4) [noise] {$\mathbf{A}_{4}$}; &
\node (q_4) {$\delta_4$}; \\
};
\draw [arrow] (S_1) -- node[anchor=south] {$\lambda_1(t)$} (I_1);
\draw [arrow] (I_1) -- node[anchor=south] {$\gamma_1$} (A_1);
\draw [arrow] (S_2) -- node[anchor=south] {$\lambda_2(t)$} (I_2);
\draw [arrow] (I_2) -- node[anchor=south] {$\gamma_2$} (A_2);
\draw [arrow] (S_4) -- node[anchor=south] {$\lambda_4(t)$} (I_4);
\draw [arrow] (I_4) -- node[anchor=south] {$\gamma_4$} (A_4);
\draw [arrow] (S_3) -- node[anchor=south] {$\lambda_3(t)$} (I_3);
\draw [arrow] (I_3) -- node[anchor=south] {$\gamma_3$} (A_3);
\draw [->]
% edge 1
(p_1) edge[thick] (S_1)
(S_1) edge[thick] (I_1)
(I_1) edge[thick] (A_1)
(A_1) edge[thick] (q_1)
(S_1) edge[thick] (a_1)
(S_1) edge[thick] (b_1)
(I_1) edge[thick] (c_1)
(A_1) edge[thick] (d_1)
% edge 2
(p_2) edge[thick] (S_2)
(S_2) edge[thick] (I_2)
(I_2) edge[thick] (A_2)
(A_2) edge[thick] (q_2)
(S_2) edge[thick] (a_2)
(S_2) edge[thick] (b_2)
(I_2) edge[thick] (c_2)
(A_2) edge[thick] (d_2)
% edge 3
(p_3) edge[thick] (S_3)
(S_3) edge[thick] (I_3)
(I_3) edge[thick] (A_3)
(A_3) edge[thick] (q_3)
(S_3) edge[thick] (a_3)
(S_3) edge[thick] (b_3)
(I_3) edge[thick] (c_3)
(A_3) edge[thick] (d_3)
% edge 4
(p_4) edge[thick] (S_4)
(S_4) edge[thick] (I_4)
(I_4) edge[thick] (A_4)
(A_4) edge[thick] (q_4)
(S_4) edge[thick] (a_4)
(S_4) edge[thick] (b_4)
(I_4) edge[thick] (c_4)
(A_4) edge[thick] (d_4)
% edge connecting S_2 and S_3
(S_2) edge[thick] (S_3)
(S_3) edge[thick] (S_2);
\draw[bend right=160, ->]
(S_1) edge[thick] (S_4)
(S_4) edge[thick] (S_1);
\draw[dashed]
(I_1) edge[thick] (S_2)
(I_2) edge[thick] (S_1)
(I_4) edge[thick] (S_3)
(I_3) edge[thick] (S_4);
\end{tikzpicture}
\end{figure}
\end{document}
Can anyone help to draw such block diagram?
Thank you!
Best Answer
Something like this?
As you see, I have
\tikzstyle
by the corresponding\tikzset
syntax, as the former is deprecated;The code can be condensed a bit more with
chains
.