概率表达式
YLearn能够输出和修改类似如下的概率表达式:
用户能够定义一个 Prob
的实例,以及改变它的属性.
举例
如一个概率表达式:
它由两个部分组成:一个条件概率:math:P(v|y) 和一个多概率的乘积 \(P(w|z)P(x|y)P(u)\) ,然后这两个部分的积在给定的:math:w 下求和。
首先定义第一个条件概率:math:P(v|y) :
from ylearn.causal_model.prob import Prob
var = {'v'}
conditional = {'y'} # the conditional set
marginal = {'w'} # sum on w
然后, 继续定义第二个多条件概率的乘积 \(P(w|z)P(x|y)P(u)\)
p1 = Prob(variables={'w'}, conditional={'z'})
p2 = Prob(variables={'x'}, conditional={'y'})
p3 = Prob(variables={'u'})
product = {p1, p2, p3}
最终的结果可以表示为:
P = Prob(variables=var, conditional=conditional, marginal=marginal, product=product)
P.show_latex_expression()
>>> :math:`\sum_w P(v|y)[P(u)][P(w|z)][P(x|y)]`
Prob
的实例还可以输出LaTex代码:
P.parse()
>>> '\\sum_{w}P(v|y)\\left[P(u)\\right]\\left[P(w|z)\\right]\\left[P(x|y)\\right]'
- class ylearn.causal_model.prob.Prob(variables=set(), conditional=set(), divisor=set(), marginal=set(), product=set())
一个概率分布表达式如下:
\[\sum_{w}P(v|y)[P(w|z)P(x|y)P(u)].\]用上述例子来阐明参数的含义:
- 参数
variables (set, default=set()) – The variables (\(v\) in the above example) of the probability.
conditional (set, default=set()) – The conditional set (\(y\) in the above example) of the probability.
marginal (set, default=set()) – The sum set (\(w\) in the above example) for marginalizing the probability.
product (set, default=set()) – If not set(), then the probability is composed of the first probability object \((P(v|y))\) and several other probability objects that are all saved in the set product, e.g., product = {P1, P2, P3} where P1 for \(P(w|z)\), P2 for \(P(x|y)\), and P3 for \(P(u)\) in the above example.
- parse()
返回概率分布的表达式
- 返回
Expression of the encoded probability
- 返回类型
str
- show_latex_expression()
显示latex表达式