PartialOrder#
- class pymc_extras.distributions.transforms.PartialOrder(adj_mat)[source]#
Create a PartialOrder transform
A more flexible version of the pymc ordered transform that allows specifying a (strict) partial order on the elements.
Examples
import numpy as np import pymc as pm import pymc_extras as pmx # Define two partial orders on 4 elements # am[i,j] = 1 means i < j adj_mats = np.array([ # 0 < {1, 2} < 3 [[0, 1, 1, 0], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 0]], # 1 < 0 < 3 < 2 [[0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0]], ]) # Create the partial order from the adjacency matrices po = pmx.PartialOrder(adj_mats) with pm.Model() as model: # Generate 3 samples from both partial orders pm.Normal("po_vals", shape=(3,2,4), transform=po, initval=po.initvals((3,2,4))) idata = pm.sample() # Verify that for first po, the zeroth element is always the smallest assert (idata.posterior['po_vals'][:,:,:,0,0] < idata.posterior['po_vals'][:,:,:,0,1:]).all() # Verify that for second po, the second element is always the largest assert (idata.posterior['po_vals'][:,:,:,1,2] >= idata.posterior['po_vals'][:,:,:,1,:]).all()
Technical notes#
Partial order needs to be strict, i.e. without equalities. A DAG defining the partial order is sufficient, as transitive closure is automatically computed. Code works in O(N*D) in runtime, but takes O(N^3) in initialization, where N is the number of nodes in the dag and D is the maximum in-degree of a node in the transitive reduction.
- __init__(adj_mat)[source]#
Initialize the PartialOrder transform
- Parameters:
adj_mat (ndarray) – adjacency matrix for the DAG that generates the partial order, where
adj_mat[i][j] = 1denotesi < j. Note this also accepts multiple DAGs if RV is multidimensional
Methods
__init__(adj_mat)Initialize the PartialOrder transform
backward(value, *inputs)Invert the transformation.
forward(value, *inputs)Apply the transformation.
initvals([shape, lower, upper])Create a set of appropriate initial values for the variable.
log_jac_det(value, *inputs)Construct the log of the absolute value of the Jacobian determinant.
Attributes
namendim_supp