liveBook · Manning

TabularCPD

As explained in Causal AI

TabularCPD is a pgmpy class for representing a conditional probability distribution in tabular form.

A TabularCPD represents a discrete variable’s probability distribution as a table, optionally conditioned on evidence variables. The values give outcome probabilities; cardinalities specify the number of states for the variable and its evidence. section 2.1.6 section 3.1.8

When constructing a CPD, specify:

  • The variable and its state count, using variable and variable_card. section 6.3.3
  • The probability values, evidence variables, their cardinalities, and optionally state names. section 6.3.3
  • For each combination of evidence states, the probabilities across the variable’s outcomes sum to one. section 3.1.8

Deterministic assignment function

In the Monty Hall model, a TabularCPD encodes the host’s door choice with probabilities of 0 or 1 for each combination of causes. Impossible cases in another CPD cannot be left blank, so arbitrary values are assigned to those cells. section 6.3.3 section 6.3.3

Listing 6.4 Implementation of Host Door Selection assignment function in pgmpy
from pgmpy.factors.discrete.CPD import TabularCPD
f_host_door_selection = TabularCPD(
    variable='Host Door Selection',    #1
    variable_card=3,     #2
    values=[    #3
        [0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,0,1,0],     #3
        [1,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1],     #3
        [0,1,0,1,0,0,0,0,0,1,1,0,1,1,0,0,0,0]     #3
    ],     #3
    evidence=[     #4
        'Host Inclination',     #4
        'Door with Car',     #4
        'Player First Choice'     #4
    ],   #4
    evidence_card=[2, 3, 3],    #5
    state_names={    #6
        'Host Door Selection':['1st', '2nd', '3rd'],    #6
        'Host Inclination': ['left', 'right'],   #6
        'Door with Car': ['1st', '2nd', '3rd'],  #6
        'Player First Choice': ['1st', '2nd', '3rd']    #6
    }    #6
)     #6

The listing shows a TabularCPD constructor with outcome values, evidence variables, cardinalities, and state names. section 6.3.3

How Causal AI covers it

How deep it goes
Specifies constructor arguments and table behavior, but does not detail parameter-learning alternatives.
Examples
Demonstrates learned transportation probabilities and deterministic Monty Hall assignment functions.
What it assumes
Assumes discrete variables with specified states and, for conditional tables, identified evidence variables.
What you can do after
Apply pgmpy’s TabularCPD constructor to encode discrete distributions and deterministic assignment functions.
How it connects
Connects conditional probability tables with Bayesian networks, causal Markov kernels, and structural causal models.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.