首页 > 解决方案 > 概率编程:具体化分布和东西?

问题描述

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

标签: prologprobabilityproblogwebppl

解决方案


是的。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 模块),但对于此示例程序,不需要。


推荐阅读