定义

全概率公式用于计算一个事件的总概率,通过一组互斥且完备的子事件来表示。
如果将样本空间 划分为一组互斥且完备的事件 ,那么任意一个子事件 的总概率,可以通过计算 在每一个 上的条件概率并加权求和得到。

如图所示, 定义红色区域为A, 样本空间 , 蓝色区域B为A的子集, 整个大圆被红色的扇区 完全分割, 这种拆分保证它们之间天然互斥。为了求得蓝色小圆 的总面积(概率),可将 在每个 中的那一部分(即交集 )的面积加起来。

\usepackage{tikz}
\usepackage{pgfplots} % 确保 pgfmathsetmacro 可用
 
\begin{document}
\begin{tikzpicture}
% ----------- 1. 图形与布局参数 -----------
\def\R{1.3} \def\r{0.7} \def\dx{-2.2} \def\dy{-2.2}
\def\aOne{90} \def\aTwo{210} \def\bOne{210} \def\bTwo{330} \def\cOne{330} \def\cTwo{90}
\pgfmathsetmacro{\cTwoEnd}{\cTwo+360}
% --- 布局参数 ---
\def\scl{0.55}     % 图形整体缩放
\def\vgap{1}     % 分数线上下间距
\def\fracWidth{0.5} % 分数线半宽
\def\multgap{0.8} % 乘法间隔
\def\plusgap{1.8} % 加法间隔
\def\plussta{0} %加法初始位置
 
% ----------- 2. 图形模块定义 (遵照您最新要求) -----------
% A_i 是纯红色扇形, B_i 是纯蓝色扇形
\def\drawRedSectorAone{\begin{scope}\clip (0,0)--({\R*cos(\aOne)},{\R*sin(\aOne)}) arc(\aOne:\aTwo:\R)--cycle;\foreach \y in {-2.2,-2.0,...,2.2}{\draw[red,thin](\dx,\y)--(-\dx,\y);}\end{scope}\draw[thick](0,0)--({\R*cos(\aOne)},{\R*sin(\aOne)}) arc(\aOne:\aTwo:\R)--cycle;}
\def\drawRedSectorAtwo{\begin{scope}\clip (0,0)--({\R*cos(\bOne)},{\R*sin(\bOne)}) arc(\bOne:\bTwo:\R)--cycle;\foreach \y in {-2.2,-2.0,...,2.2}{\draw[red,thin](\dx,\y)--(-\dx,\y);}\end{scope}\draw[thick](0,0)--({\R*cos(\bOne)},{\R*sin(\bOne)}) arc(\bOne:\bTwo:\R)--cycle;}
\def\drawRedSectorAthree{\begin{scope}\clip (0,0)--({\R*cos(\cOne)},{\R*sin(\cOne)}) arc(\cOne:\cTwoEnd:\R)--cycle;\foreach \y in {-2.2,-2.0,...,2.2}{\draw[red,thin](\dx,\y)--(-\dx,\y);}\end{scope}\draw[thick](0,0)--({\R*cos(\cOne)},{\R*sin(\cOne)}) arc(\cOne:\cTwoEnd:\R)--cycle;}
\def\drawBlueSectorBone{\begin{scope}\clip (0,0)--({\r*cos(\aOne)},{\r*sin(\aOne)}) arc(\aOne:\aTwo:\r)--cycle;\foreach \x in {-2.2,-2.0,...,2.2}{\draw[blue,thin](\x,\dy)--(\x,-\dy);}\end{scope}\draw[thick](0,0)--({\r*cos(\aOne)},{\r*sin(\aOne)}) arc(\aOne:\aTwo:\r)--cycle;}
\def\drawBlueSectorBtwo{\begin{scope}\clip (0,0)--({\r*cos(\bOne)},{\r*sin(\bOne)}) arc(\bOne:\bTwo:\r)--cycle;\foreach \x in {-2.2,-2.0,...,2.2}{\draw[blue,thin](\x,\dy)--(\x,-\dy);}\end{scope}\draw[thick](0,0)--({\r*cos(\bOne)},{\r*sin(\bOne)}) arc(\bOne:\bTwo:\r)--cycle;}
\def\drawBlueSectorBthree{\begin{scope}\clip (0,0)--({\r*cos(\cOne)},{\r*sin(\cOne)}) arc(\cOne:\cTwoEnd:\r)--cycle;\foreach \x in {-2.2,-2.0,...,2.2}{\draw[blue,thin](\x,\dy)--(\x,-\dy);}\end{scope}\draw[thick](0,0)--({\r*cos(\cOne)},{\r*sin(\cOne)}) arc(\cOne:\cTwoEnd:\r)--cycle;}
\def\drawRedCircleOmega{\begin{scope}\clip(0,0)circle(\R);\foreach \y in {-2.2,-2.0,...,2.2}{\draw[red,thin](\dx,\y)--(-\dx,\y);}\end{scope}\draw[thick](0,0)circle(\R);}
\def\drawBlueCircleB{\begin{scope}\clip(0,0)circle(\r);\foreach \x in {-2.2,-2.0,...,2.2}{\draw[blue,thin](\x,\dy)--(\x,-\dy);}\end{scope}\draw[thick](0,0)circle(\r);}
 
% ----------- 3. 精确手动布局 -----------
% --- LHS ---
\node at (-5, 0) [scale=1] {$P(B)$};
\node at (-4, 0) [scale=1] {$=$};
\begin{scope}[shift={(-3, 0)}] % P(B) = B / Ω
    \begin{scope}[shift={(0, \vgap)}, scale=\scl]\drawBlueCircleB\end{scope}
    \begin{scope}[shift={(0, -\vgap)}, scale=\scl]\drawRedCircleOmega\end{scope}
    \draw[thick] (-\fracWidth, 0) -- (\fracWidth, 0);
\end{scope}
 
% --- RHS ---
\node at (-2, 0) [scale=1] {$=$};
 
% Term 1
\begin{scope}[shift={(\plussta, 0)}]
    \node at (0, 0) {$\cdot$};
    \begin{scope}[shift={(-\multgap, 0)}] % P(A1)
        \begin{scope}[shift={(0, \vgap)}, scale=\scl]\drawRedSectorAone\end{scope}
        \begin{scope}[shift={(0, -\vgap)}, scale=\scl]\drawRedCircleOmega\end{scope}
        \draw[thick] (-\fracWidth, 0) -- (\fracWidth, 0);
    \end{scope}
    \begin{scope}[shift={(\multgap, 0)}] % P(B|A1)
        \begin{scope}[shift={(0, \vgap)}, scale=\scl]\drawBlueSectorBone\end{scope}
        \begin{scope}[shift={(0, -\vgap)}, scale=\scl]\drawRedSectorAone\end{scope}
        \draw[thick] (-\fracWidth, 0) -- (\fracWidth, 0);
    \end{scope}
\end{scope}
 
% Plus 1
\node at (\plussta+\plusgap, 0) [scale=1.5] {$+$};
 
% Term 2
\begin{scope}[shift={(\plussta+\plusgap*2, 0)}]
    \node at (0, 0) {$\cdot$};
    \begin{scope}[shift={(-\multgap, 0)}] % P(A2)
        \begin{scope}[shift={(0, \vgap)}, scale=\scl]\drawRedSectorAtwo\end{scope}
        \begin{scope}[shift={(0, -\vgap)}, scale=\scl]\drawRedCircleOmega\end{scope}
        \draw[thick] (-\fracWidth, 0) -- (\fracWidth, 0);
    \end{scope}
    \begin{scope}[shift={(\multgap, 0)}] % P(B|A2)
        \begin{scope}[shift={(0, \vgap)}, scale=\scl]\drawBlueSectorBtwo\end{scope}
        \begin{scope}[shift={(0, -\vgap)}, scale=\scl]\drawRedSectorAtwo\end{scope}
        \draw[thick] (-\fracWidth, 0) -- (\fracWidth, 0);
    \end{scope}
\end{scope}
 
% Plus 2
\node at (\plussta+\plusgap*3, 0) [scale=1.5] {$+$};
 
% Term 3
\begin{scope}[shift={(\plussta+\plusgap*4, 0)}]
    \node at (0, 0) {$\cdot$};
    \begin{scope}[shift={(-\multgap, 0)}] % P(A3)
        \begin{scope}[shift={(0, \vgap)}, scale=\scl]\drawRedSectorAthree\end{scope}
        \begin{scope}[shift={(0, -\vgap)}, scale=\scl]\drawRedCircleOmega\end{scope}
        \draw[thick] (-\fracWidth, 0) -- (\fracWidth, 0);
    \end{scope}
    \begin{scope}[shift={(\multgap, 0)}] % P(B|A3)
        \begin{scope}[shift={(0, \vgap)}, scale=\scl]\drawBlueSectorBthree\end{scope}
        \begin{scope}[shift={(0, -\vgap)}, scale=\scl]\drawRedSectorAthree\end{scope}
        \draw[thick] (-\fracWidth, 0) -- (\fracWidth, 0);
    \end{scope}
\end{scope}
 
\end{tikzpicture}
\end{document}

NOTE

贝叶斯定理比较

推导

假设事件 构成一个完备事件组(即对样本空间 Ω 的一个划分):

对于任意事件 ,它都可以被表示为与这个划分中每一部分的交集的并集:

由于 之间是互斥的,因此 这些交集之间也必然是互斥的。所以,可以将并集的概率直接写为概率的和:

根据条件概率的乘法公式 ,将其代入上式,即可得到全概率公式:

示例

假设乘坐公交(事件 )或乘坐地铁(事件 )选择的概率分别为

如果选择公交,能准时到达(事件 )的概率为
如果选择地铁,能准时到达(事件 )的概率为

那么,无论选择何种方式,能准时到达的总概率 为: