Representation of Probability
To represent and modifies probabilities such as
one can define an instance of Prob
and change its attributes.
Examples
The probabiity
is composed of two parts: \(P(v|y)\) and a product \(P(w|z)P(x|y)P(u)\) and then they are sumed on \(w\). We first define the first part:
from ylearn.causal_model.prob import Prob
var = {'v'}
conditional = {'y'} # the conditional set
marginal = {'w'} # sum on w
Now we continue to define the second part, the product,
p1 = Prob(variables={'w'}, conditional={'z'})
p2 = Prob(variables={'x'}, conditional={'y'})
p3 = Prob(variables={'u'})
product = {p1, p2, p3}
The final result is
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)]`
An instance of Prob
can also output the latex code
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())
Probability distribution, e.g., the probability expression
\[\sum_{w}P(v|y)[P(w|z)P(x|y)P(u)].\]We will clarify below the meanings of our variables with this example.
- Parameters
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 probabiity 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()
Return the expression of the probability distribution.
- Returns
Expression of the encoded probabiity
- Return type
str
- show_latex_expression()
Show the latex expression.