博客语言结果有一小部分
BLOG Language results off by a small fraction
我正在试用 Bayesian-Logic language using the following example。
- 1% 的女性患有乳腺癌(因此 99% 的女性没有)。
- 80% 的乳房 X 线照片会在乳腺癌存在时检测到它(因此 20% 会漏诊)。
- 9.6% 的乳房 X 线照片检测出不存在的乳腺癌(因此 90.4% 正确 return 为阴性结果)。
我创建了以下代码:
random Boolean Has_Cancer ~ BooleanDistrib(0.01);
random Boolean Detect_Cancer ~
if Has_Cancer then BooleanDistrib(0.8)
else BooleanDistrib(0.096);
obs Detect_Cancer = true;
query Has_Cancer;
当我 运行 它时,我得到以下结果:
======== Query Results =========
Number of samples: 10000
Distribution of values for Has_Cancer
false 0.9245347606896278
true 0.07546523931038764
======== Done ========
根据博客 true
应该是 0.0776
。
当我 运行 有 100 个样本时,我得到这个:
======== Query Results =========
Number of samples: 100
Distribution of values for Has_Cancer
false 0.9223602484472041
true 0.077639751552795
======== Done ========
我只是想了解原因。
BLOG 生成的值是使用似然加权算法 (LWA) 从条件概率图形模型生成随机样本后的点估计。与示例中分析值的差异 post 可能是由于随机抽样过程中的噪音。
但令人困惑的是,BLOG 默认使用相同的固定种子初始化随机数生成器,因此结果误导性地看起来像是确定性的。如果将 --randomize
标志添加到 运行 调用,您将看到使用其他随机种子的结果。
我不知道 LWA 的理论属性(例如,它与 post之前均值的界限有多紧密),但至少对于一个朴素的生成采样方案,你生成的均值完全在95% CI。这是一个 Python 示例,模拟 10K 个样本的 1000 运行 个。
import numpy as np
from scipy.stats import binom
np.random.seed(2019)
N, K = 10000, 1000
tp = np.empty(K)
for i in range(K):
t = binom(n=N, p=0.01).rvs()
f = N - t
detect_t = binom(n=t, p=0.800).rvs()
detect_f = binom(n=f, p=0.096).rvs()
tp[i] = detect_t / (detect_f + detect_t)
np.quantile(tp, [0.025, 0.5, 0.975])
# array([0.06177242, 0.07714902, 0.09462359])
我正在试用 Bayesian-Logic language using the following example。
- 1% 的女性患有乳腺癌(因此 99% 的女性没有)。
- 80% 的乳房 X 线照片会在乳腺癌存在时检测到它(因此 20% 会漏诊)。
- 9.6% 的乳房 X 线照片检测出不存在的乳腺癌(因此 90.4% 正确 return 为阴性结果)。
我创建了以下代码:
random Boolean Has_Cancer ~ BooleanDistrib(0.01);
random Boolean Detect_Cancer ~
if Has_Cancer then BooleanDistrib(0.8)
else BooleanDistrib(0.096);
obs Detect_Cancer = true;
query Has_Cancer;
当我 运行 它时,我得到以下结果:
======== Query Results =========
Number of samples: 10000
Distribution of values for Has_Cancer
false 0.9245347606896278
true 0.07546523931038764
======== Done ========
根据博客 true
应该是 0.0776
。
当我 运行 有 100 个样本时,我得到这个:
======== Query Results =========
Number of samples: 100
Distribution of values for Has_Cancer
false 0.9223602484472041
true 0.077639751552795
======== Done ========
我只是想了解原因。
BLOG 生成的值是使用似然加权算法 (LWA) 从条件概率图形模型生成随机样本后的点估计。与示例中分析值的差异 post 可能是由于随机抽样过程中的噪音。
但令人困惑的是,BLOG 默认使用相同的固定种子初始化随机数生成器,因此结果误导性地看起来像是确定性的。如果将 --randomize
标志添加到 运行 调用,您将看到使用其他随机种子的结果。
我不知道 LWA 的理论属性(例如,它与 post之前均值的界限有多紧密),但至少对于一个朴素的生成采样方案,你生成的均值完全在95% CI。这是一个 Python 示例,模拟 10K 个样本的 1000 运行 个。
import numpy as np
from scipy.stats import binom
np.random.seed(2019)
N, K = 10000, 1000
tp = np.empty(K)
for i in range(K):
t = binom(n=N, p=0.01).rvs()
f = N - t
detect_t = binom(n=t, p=0.800).rvs()
detect_f = binom(n=f, p=0.096).rvs()
tp[i] = detect_t / (detect_f + detect_t)
np.quantile(tp, [0.025, 0.5, 0.975])
# array([0.06177242, 0.07714902, 0.09462359])