1

How one can draw a diagram like this in Latex:

enter image description here

I already know how to draw transition states and things like this using \usetikzlibrary{automata, arrows.meta, positioning} but I don't know how to draw a diagram like this that has two kinds of arrows and different shapes. Thank you in advance for your help.

For the moment I have this:

\begin{tikzpicture}[every text node part/.style={align=center},shorten >=1pt,node distance=4cm,on grid,auto,squarednode/.style={rectangle, draw=black!60, fill=white!5, very thick, minimum size=5mm}]
    \node[state] (cold1) {COLD$_1$};
    \node[state] (hot1) [right=of cold1] {HOT$_1$};
    \node[squarednode] (b2) [below right=of hot1] {\textbf{B2} \\ \\ $\begin{bmatrix} P(1 | HOT) \\ P(2 | HOT) \\ P(3 | HOT) \end{bmatrix} = \begin{bmatrix} 0.2 \\ 0.4 \\ 0.4 \end{bmatrix}$};
    \node[squarednode] (b1) [below left=of cold1] {\textbf{B1} \\ \\ $\begin{bmatrix} P(1 | COLD) \\ P(2 | COLD) \\ P(3 | COLD) \end{bmatrix} = \begin{bmatrix} 0.5 \\ 0.4 \\ 0.1 \end{bmatrix}$};
    \path[-stealth, thick]
    (cold1) edge [bend left]  node {$0.5$} (hot1)
    (cold1) edge [left]  node {} (b1)
    (cold1) edge [loop above]  node {$0.5$} ()
    (hot1) edge [bend left]  node {$0.4$} (cold1)
    (hot1) edge [left]  node {} (b2)
    edge [loop above] node {$0.6$} ();
  \end{tikzpicture}
4
  • Why don't you share a minimal working example (MWE) with us and ask about specific issue? About the shapes, you could search for the shapes.geometric library, to begin with.
    – SebGlav
    Apr 18, 2022 at 14:04
  • @SebGlav You are right. I just added the code that I have done so far. In particular I don't know how to change line style that goes from circle nodes to rectangle nodes
    – mrjamaisvu
    Apr 18, 2022 at 14:07
  • Thanks for adding code. Please share a complete minimal working example (MWE) starting by \documentclass and ending with \end{document} in order to avoid users to do it before testing your code. Thanks in advance for reading the link I provided to help you understand this community standards.
    – SebGlav
    Apr 18, 2022 at 14:13
  • TikZ picture shapes migth help. Apr 18, 2022 at 14:18

2 Answers 2

3

Something to start with.

different shapes and arrows

\documentclass[tikz, border=3.14mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{positioning, automata, arrows.meta, shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
        state/.append style={minimum size=15mm},
        arr/.style={dashed,-{Latex[scale=1.5]}},
        every text node part/.style={align=center},
        shorten >=1pt,node distance=4cm,on grid,auto,
        squarednode/.style={rectangle, draw=black!60, fill=white!5, very thick, minimum size=5mm}]
        \node[state] (cold1) {$\mathrm{COLD}_1$};
        \node[state] (hot1) [right=of cold1] {$\mathrm{HOT}_2$};
        \node[squarednode] (b2) [below right=of hot1] {\textbf{B2} \\ \\ $\begin{bmatrix} P(1 \mid HOT) \\ P(2 \mid HOT) \\ P(3 \mid HOT) \end{bmatrix} = \begin{bmatrix} 0.2 \\ 0.4 \\ 0.4 \end{bmatrix}$};
        \node[squarednode] (b1) [below left=of cold1] {\textbf{B1} \\ \\ $\begin{bmatrix} P(1 \mid COLD) \\ P(2 \mid COLD) \\ P(3 \mid COLD) \end{bmatrix} = \begin{bmatrix} 0.5 \\ 0.4 \\ 0.1 \end{bmatrix}$};
        
        \path (b1) -- (b2) node[pos=0.5,below,inner sep=-5pt,draw,regular polygon,regular polygon sides=8] (s) {$\pi=[.2\,, .8]$};
        
        \path[-stealth, thick]
        (cold1) edge [bend left]  node {$0.5$} (hot1)
        (cold1) edge [arr, left]  node {} (b1)
        (cold1) edge [loop above]  node {$0.5$} ()
        (hot1) edge [bend left]  node {$0.4$} (cold1)
        (hot1) edge [arr, left]  node {} (b2)
        edge [loop above] node {$0.6$} ();
      \end{tikzpicture}
\end{document}
4
  • I'd use \mathrm{COLD}_1 instead of text with subscript. Also, I'd add some spare around vertical bar, eg. with \mid.
    – Sigur
    Apr 18, 2022 at 14:44
  • I didn't want to correct every bits in the content, just answer the main issues, but you're right.
    – SebGlav
    Apr 18, 2022 at 14:56
  • Yes, I know. But since some user could copy your code fully... it would be good.
    – Sigur
    Apr 18, 2022 at 16:05
  • This is done now, thanks again.
    – SebGlav
    Apr 18, 2022 at 21:10
2

Based on @SebGlav answer (all credits to him), I added the blue fill in case it was needed as well :

\documentclass[tikz, border=3.14mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{positioning, automata, arrows.meta, shapes.geometric}

\begin{document}
    \begin{tikzpicture}[
        state/.append style={minimum size=15mm},
        arr/.style={dashed,-{Latex[scale=1.5]}},
        every text node part/.style={align=center},
        shorten >=1pt,node distance=4cm,on grid,auto,
        squarednode/.style={rectangle, draw=black!60, fill=blue!7, very thick, minimum size=5mm}]
        \node[state] (cold1) [fill=blue!7] {COLD$_1$};
        \node[state] (hot1) [fill=blue!7, right=of cold1] {HOT$_1$};
        \node[squarednode] (b2) [below right=of hot1] {\textbf{B2} \\ \\ $\begin{bmatrix} P(1 | HOT) \\ P(2 | HOT) \\ P(3 | HOT) \end{bmatrix} = \begin{bmatrix} 0.2 \\ 0.4 \\ 0.4 \end{bmatrix}$};
        \node[squarednode] (b1) [below left=of cold1] {\textbf{B1} \\ \\ $\begin{bmatrix} P(1 | COLD) \\ P(2 | COLD) \\ P(3 | COLD) \end{bmatrix} = \begin{bmatrix} 0.5 \\ 0.4 \\ 0.1 \end{bmatrix}$};
        
        \path (b1) -- (b2) node[pos=0.5,below,inner sep=-5pt,draw, fill=blue!7, regular polygon,regular polygon sides=8] (s) {$\pi=[.2\,, .8]$};
        
        \path[-stealth, thick]
        (cold1) edge [bend left]  node {$0.5$} (hot1)
        (cold1) edge [arr, left]  node {} (b1)
        (cold1) edge [loop above]  node {$0.5$} ()
        (hot1) edge [bend left]  node {$0.4$} (cold1)
        (hot1) edge [arr, left]  node {} (b2)
        edge [loop above] node {$0.6$} ();
      \end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .