pqp package

Submodules

pqp.expression module

class pqp.expression.Expression

Bases: object

Base class for all expressions.

The primary use of Expression is to represent the results of identification. However, Expressions can be constructed from Variables and other Expressions. Using the infix / and * operators.

Examples

>>> from pqp.variable import make_vars
>>> x, y = make_vars("xy")
>>> x / y
Quotient(Variable(x), Variable(y))
>>> x * y
Product([Variable(x), Variable(y)])
Expressions can be represented in a number of different ways.
  • __repr__ returns an unambiguous representation of the expression

  • __str__ returns a human-readable (ascii, symbolic) representation

  • to_latex returns a Latex representation of the expression

display()

Renders an expression as Latex using IPython.display

to_latex()

Returns the Latex representation of an expression.

class pqp.expression.Hedge

Bases: Expression

Represents a failure to identify the query

to_latex()

Returns the Latex representation of an expression.

class pqp.expression.Marginal(sub, expr)

Bases: Expression

to_latex()

Returns the Latex representation of an expression.

class pqp.expression.P(vars, given)

Bases: Expression

to_latex()

Returns the Latex representation of an expression.

class pqp.expression.Product(expr)

Bases: Expression

to_latex()

Returns the Latex representation of an expression.

class pqp.expression.Quotient(numer, denom)

Bases: Expression

to_latex()

Returns the Latex representation of an expression.

pqp.expression.parse_json(exp)

Parses JSON returned from backend.id() into an Expression object.

Parameters:

exp (str or dict) – The JSON string or parsed JSON object.

Returns:

The parsed expression.

Return type:

Expression

pqp.graph module

class pqp.graph.BidirectedEdge(a, b)

Bases: object

A bidirected edge between two variables, represents confounding in the causal model

Parameters:
class pqp.graph.DirectedEdge(start, end)

Bases: object

A directed edge between two variables, represents a causal relationship

Parameters:
  • start (Variable) – the start of the edge

  • end (Variable) – the end of the edge

class pqp.graph.Graph(edges=[])

Bases: object

A causal graph

Example

>>> x = Variable("X")
>>> y = Variable("Y")
>>> g = Graph([
...     y <= x,
... ])
>>> g.idc([y], [x])
P(y | x)
Parameters:

edges (list of DirectedEdge or BidirectedEdge) – the edges in the graph

add_edge(edge)

Adds an edge to the graph

Parameters:

edge (DirectedEdge or BidirectedEdge) – the edge to add

bi_edge_tuples()
di_edge_tuples()
draw()

Draws the causal diagram using networkx

idc(y, x, z=[])

Identification of conditional interventional distribution.

Parameters:
  • x (list of Variable) – intervention variables

  • y (list of Variable) – outcome variables

  • z (list of Variable) – conditioning variables (optional)

Returns:

the expression for the interventional distribution

Return type:

Expression

pqp.utils module

pqp.utils.recursive_sort(d)

pqp.variable module

class pqp.variable.Variable(name)

Bases: Expression

A variable in the causal model

Dunder methods allow for convenient syntax for creating causal graphs.

Example

>>> x = Variable("x")
>>> y = Variable("y")
>>> x <= y
DirectedEdge(Variable("x"), Variable("y"))
>>> x & y
BidirectedEdge(Variable("x"), Variable("y"))
Parameters:

name (str) – the name of the variable

to_latex()

Returns the Latex representation of an expression.

pqp.variable.make_vars(names)

Creates a list of variables from a list of names

Example

>>> make_vars(["x", "y", "z"])
[Variable("x"), Variable("y"), Variable("z")]
>>> x, y, z = make_vars("xyz")
[Variable("x"), Variable("y"), Variable("z")]

Module contents