次の確率ツリーを LaTeX で作成するにはどうすればよいですか?
助けてくれてありがとう!!
確率ツリー1:
確率木2:
\forestset{my label/.style={if n=1{edge label={node [midway, above left, font=\tiny] {$#1$}},}{edge label={node [midway, below left, font=\tiny] {$#1$}},
}
}
}
\begin{forest}
for tree={
grow'=0,
math content,
parent anchor=east,
child anchor=west,
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) node
[circle, fill, minimum size=2.5pt, inner sep=0pt,
anchor=center]
{} -- (.child anchor)\forestoption{edge label};
},
edge={->},
anchor=west,
l sep+=15mm,
s sep+=10mm,
}
%Left figure
[
[\textbf{\textit{p}}^{good}, my label={P(good\rvert club_1)},
tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}]
[\textbf{\textit{p}}_{rough}^{bad}, my label={P(bad\rvert club_1)}]
]
[, phantom, l sep-=25mm
%Right figure
[
[\textbf{\textit{p}}^{good}, my label={P(good\rvert club_2)},
tikz={\node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
\draw [thick] (!r |- sa.south) -- (.east |- sa.south);}]
[\textbf{\textit{p}}^{bad}_{rough}, my label={P(bad\rvert club_2)}]
]
]
\end{forest}
確率木3:
答え1
最も複雑なツリーはここにあります。これを変更して、より単純なツリーを作成することができます。行き詰まった場合は、コードを投稿して、遭遇した問題の解決方法を尋ねてください。
forest
これは、ツリーの描画に標準の括弧表記を使用できる強力なパッケージを使用します。以前の質問に対する私の答えforest
ツリーをブラケット仕様に変換する方法を紹介し、説明します。
\documentclass[tikz, border=10pt]{standalone}
\usepackage{forest,mathtools}
\usetikzlibrary{arrows.meta,positioning}% requires TikZ/PGF 3 - comment if you don't have arrows.meta
%\usetikzlibrary{positioning}% uncomment if you don't have arrows.meta
\begin{document}
\forestset{
my label/.style={
if n=1{
edge label={node [midway, above left, font=\tiny] {$#1$}},
}{
edge label={node [midway, below left, font=\tiny] {$#1$}},
}
}
}
\begin{forest}
for tree={
grow'=0,
math content,
parent anchor=east,
child anchor=west,
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
},
edge={-{Stealth[]}},% requires TikZ/PGF version 3 - comment if you don't have arrows.meta
%edge={->},% uncomment this line if you don't have arrows.meta
anchor=west,
l sep+=15mm,
s sep+=5mm,
}
[
[p^{good}, my label={P[good\rvert club_1]}, tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}
]
[p^{bad}, my label={P[bad\rvert club_1]}
[p^{bad}_{rough}, my label={\delta\cdot P[bad\rvert club_1]}
[, phantom, l sep-=25mm
[
[p^{good}, my label={P[good\rvert club_2]},
tikz={
\node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
\draw [thick] (!r |- sa.south) -- (.east |- sa.south);
}
]
[p^{bad}_{rough}, my label={P[bad\rvert club_2]}
]
]
]
]
[p^{bad}_{sand}, my label={(1-\delta)\cdot P[bad\rvert club_1]}
]
]
]
\end{forest}
\end{document}
編集
3 つのツリーすべてに関するヘルプは次のとおりです。
\documentclass[tikz, border=10pt, multi]{standalone}
\usepackage{forest,mathtools}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\forestset{
my label/.style={
if n=1{
edge label={node [midway, above left, font=\tiny] {$#1$}},
}{
edge label={node [midway, below left, font=\tiny] {$#1$}},
}
}
}
\begin{forest}
for tree={
grow'=0,
math content,
parent anchor=east,
child anchor=west,
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
},
edge={-{Stealth[]}},
anchor=west,
l sep+=15mm,
s sep+=5mm,
if level=1{tier=t}{}
}
[
[p^{bad}_{O.B.}, tikz={\node (sa) [above=10mm of .north, anchor=base east] {$unplayable$};}
]
[, phantom
[,
[p^{bad}_{rough},
tikz={
\node (sb) [anchor=base east] at (.center |- sa.base) {$playable$};
\draw [thick] (!r |- sa.south) -- (.east |- sa.south);
}
]
[p^{bad}_{trees}]
[p^{bad}_{sand}
]
]
]
[p^{bad}_{water}
]
]
\end{forest}
\begin{forest}
for tree={
grow'=0,
math content,
parent anchor=east,
child anchor=west,
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
},
edge={-{Stealth[]}},
anchor=west,
l sep+=15mm,
s sep+=5mm,
if level=1{tier=t}{}
}
[
[p^{good}, my label={P[good\rvert club_1]}, tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}
]
[, phantom
[,
[p^{good}, my label={P[good\rvert club_2]},
tikz={
\node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
\draw [thick] (!r |- sa.south) -- (.east |- sa.south);
}
]
[,phantom]
[p^{bad}_{rough}, my label={P[bad\rvert club_2]}
]
]
]
[p^{bad}_{rough}, my label={P[bad\rvert club_1]}
]
]
\end{forest}
\begin{forest}
for tree={
grow'=0,
math content,
parent anchor=east,
child anchor=west,
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) node [circle, fill, minimum size=2.5pt, inner sep=0pt, anchor=center] {} -- (.child anchor)\forestoption{edge label};
},
edge={-{Stealth[]}},
anchor=west,
l sep+=15mm,
s sep+=5mm,
}
[
[p^{good}, my label={P[good\rvert club_1]}, tikz={\node (sa) [above=10mm of .north, anchor=base] {$S_A$};}
]
[p^{bad}, my label={P[bad\rvert club_1]}
[p^{bad}_{rough}, my label={\delta\cdot P[bad\rvert club_1]}
[, phantom, l sep-=25mm
[
[p^{good}, my label={P[good\rvert club_2]},
tikz={
\node (sb) [anchor=base east] at (.west |- sa.base) {$S_B$};
\draw [thick] (!r |- sa.south) -- (.east |- sa.south);
}
]
[p^{bad}_{rough}, my label={P[bad\rvert club_2]}
]
]
]
]
[p^{bad}_{sand}, my label={(1-\delta)\cdot P[bad\rvert club_1]}
]
]
]
\end{forest}
\end{document}
括弧表記を理解するには、上にリンクした回答を参照してください。そうしないと、これは単なる魔法のトリックのように見え、適応することは不可能になります ;)。