P¶
- class pqp.symbols.P(vars, given=None)¶
Bases:
AbstractExpression
Expression representing a probability or conditional probability
- Parameters:
- Raises:
ValueError – if a variable is repeated in vars or given
TypeError – if vars or given are not a list of Variable or Event
Attributes Summary
Methods Summary
copy
()Returns a copy of the expression (variables are not copied).
Get the set of variables which are conditioned on in this P
Get the set of variables which are intervened on in this P
get_vars
()Get the set of variables to the left of the conditioning bar in this P
r_adapt_map
(func)Recursive map where the func decides callables used to transform children
r_map
(func)Recursively maps a function over the expression tree
sorted
()Returns a sorted copy of an expression for structural comparison.
syntactic_eq
(other)Test whether two Expressions are syntactically identical (structural compare without sorting first)
to_latex
()Attributes Documentation
- unassigned = <object object>¶
Methods Documentation
- copy()¶
Returns a copy of the expression (variables are not copied).
- get_conditioned_vars()¶
Get the set of variables which are conditioned on in this P
- Raises:
TypeError – if self.given contains an element which is not Variable, EqualityEvent or InterventionEvent
- Returns:
dict of Variable -> value
- get_intervened_vars()¶
Get the set of variables which are intervened on in this P
- Returns:
dict of Variable -> value
- Raises:
TypeError – if self.given contains an InterventionEvent which contains neither Variable nor EqualityEvent
- get_vars()¶
Get the set of variables to the left of the conditioning bar in this P
- Returns:
set of Variable
- Raises:
TypeError – if self.vars contains an element which is neither Variable nor EqualityEvent
- r_adapt_map(func)¶
Recursive map where the func decides callables used to transform children
DO NOT USE! This is a powerful and necessary method but it results in almost unreadable code.
So, func takes an AbstractExpression and needs to return a tuple of two things. First, a function A which maps from AbstractExpression to AbstractExpression. Second, a function B of the same time as func.
At each level of recursion, func will be called on an expression E to get A and B. This method, r_adapt_map will then be called on the children of E with B as input (if B is None, recursion terminates). An expression of the same type as E is then constructed with the results of the recursive calls using B, and A is applied to the result.
- Parameters:
func (function) – A function that takes an AbstractExpression and returns two functions (see desc)
- r_map(func)¶
Recursively maps a function over the expression tree
- sorted()¶
Returns a sorted copy of an expression for structural comparison.
- syntactic_eq(other)¶
Test whether two Expressions are syntactically identical (structural compare without sorting first)
- to_latex()¶