prolog - 概率编程:具体化分布和东西?
问题描述
ProbLog 和/或 prolog/cplint 是否支持使用分布和具体化分布、条件/观察等,例如下面 WebPPL 中的示例。
如果是,你是怎么做到的?
/我知道 cplint 支持可能是发行版,但是具体化?/
// sampling function, condition() acts
// like filter i.e. the match is excluded from sampling result
var test = function() {
var a = flip() //Bernoulli
var b = flip()
condition(a||b)
return {a:a,b:b}
}
//reifying a distribution
var abc = Infer({method: 'rejection', samples:1000}, test)
abc
$ webppl test2.wppl
Marginal:
{"a":false,"b":true} : 0.337
{"a":true,"b":false} : 0.332
{"a":true,"b":true} : 0.331
解决方案
是的。ProbLog 和 cplint 都支持条件分布(观察)。考虑以下程序:
0.5::a.
0.5::b.
q_a_and_b:- a,b.
q_or:- a.
q_or:- b.
在 cplint 中,您可以查询给定的证据:
?- prob(q_a_and_b,q_or,Prob).
Prob = 0.33.
ProbLog 也是如此(您需要直接在程序中添加查询和证据)。前面的查询可以读作:“q_a_and_b
给定q_or
已观察到的真实概率是多少?”。该解决方案采用精确推理。在 cplint 中,您还可以使用近似推理(使用 MCINTYRE 模块),但对于此示例程序,不需要。
推荐阅读
- javascript - 网站上的 Facebook Messenger,每个页面都有不同的问候信息
- javafx - 将 STL 文件转换为 TriangleMesh 对象
- php - 如何使用 PHP 从上传到 localhost 的一个 html 文件重定向到磁盘上的另一个 html 文件?
- mercurial - Mercurial:文件拆分为两个文件,如何跟踪更改?
- java - 这是一个关于反转字符串的问题
- mysql - MySQL 将 2 列与同一个表连接起来
- android - APK 包中 .properties 文件的用途是什么?
- r - 遍历列并计算满足R中条件的行
- python - 从文本中提取标题
- java - 如何使用 AsyncTask、RecyclerView 和 RecyclerView.Adapter 将手机中的图像获取到 RecyclerView?