Assignment 3: Bayes Nets CSC 384H


Category: You will Instantly receive a download link for .zip solution file upon Payment


5/5 - (4 votes)

In this assignment you will implement variable elimination on Bayes Nets.
What is supplied. You will be supplied with python code implementing Variable, Factor, and BN objects. The file contains the class definitions for these objects. The code supports representing
factors as tables of values indexed by various settings of the variables in the factor’s scope.
The template file also contains function prototypes for the functions you must implement.
Question 1. Implement Variable Elimination
Implement a collection of functions that operate on Factor objects and then use these functions to implement VE (variable elimination).
multiply factors Take as input a list of Factor objects; create and return a new factor that is equal
to the product of the factors in the list. Do not modify any of the input factors.
restrict factor Take as input a single factor, a variable V and a value d from the domain of that
variable; create and return a new factor that is the restriction of the input factor to the assignment
V = d. Do not modify the input factor.
sum out variable Take as input a single factor, and a variable V ; create and return a new factor that is
the result of summing V out of the input factor. Do not modify the input factor.
VE Take as input a Bayes Net object (object of class BN), a variable that is the query variable Q, and a list
of variables E that are the evidence variables (all of which have had some value set as evidence using
the variable’s set evidence interface). Compute the probability of every possible assignment
to Q given the evidence specified by the evidence settings of the evidence variables. Return these
probabilities as a list where every number corresponds the probability of one of Q’s possible values.
Do not modify any factor of the input bayes net.