Skip to content

Files

Latest commit

 

History

History
58 lines (46 loc) · 1.48 KB

12-Variable_Elimination.md

File metadata and controls

58 lines (46 loc) · 1.48 KB
tags comments dg-publish
notes
cs188
true
true

note

variable elimination

An alternate approach is to eliminate hidden variables one by one. To eliminate a variable X, we:

  1. Join (multiply together) all factors1 involving X.
  2. Sum out X.
def elimination_ask(X, e, bn):
    """
    Returns a distribution over X given evidence e using variable elimination.
    
    Parameters:
    X: Query variable
    e: Observed values for evidence variables
    bn: Bayesian network specifying joint distribution P(X1, ..., Xn)
    
    Returns:
    Normalized distribution over X
    """
    factors = []  # Initialize an empty list for factors
    for var in order(bn.VARS):  # Iterate over variables in a specified order
        factors = make_factor(var, e, factors)  # Create a factor for the current variable
        if var is a hidden variable:  # Check if the variable is hidden
            factors = sum_out(var, factors)  # Sum out the hidden variable from factors
    return normalize(pointwise_product(factors))  # Normalize the final distribution

[!EXAMPLE]

graph LR
   T ---> A
   T ---> B
   A ---> C
   B ---> C
Loading

IBE vs. VE

link

Footnotes

  1. A factor is defined simply as an unnormalized probability