### COSC-570: Artificial Intelligence

Project 3
Fall 2022

Due: F 11/4 @ 5:00 PM
9 points

For this project, you will implement routines for exact inference for Bayesian networks. Begin by implementing routines for efficiently manipulating factors based on Koller and Friedman's product-factor algorithm. You will then use these routines to implement Russell and Norvig's variable elimination algorithm.

You must implement the following classes and methods:

• public Variable( String label, int cardinality ), which constructs a variable with the specified label and cardinality.
• public Variable( String label, int cardinality, ArrayList<Variable> parents ), which creates a variable with the specified label, cardinality, and parents.
• public void Variable.instantiate( int value ), which instantiates the variable to the specified value.
• public void Variable.set( int[] assignments, double probability ), which sets the position in the dope vector specified by the assignments to the probability.
• public Network(), which constructs a Bayesian network.
• public void Network.add( Variable variable ), which adds the specified variable to the Bayesian network.
• public Factor Network.elimination( Variable query, ArrayList<Variable> evidence ), which uses the variable-elimination algorithm to compute the probability distribution of the query given the evidence.
• public double Factor.getProbability( int[] assignments ), which returns the probability specified by the assignments.
• public String Factor.toString(), which returns a string representation of the factor.
Note that you will need to implement additional classes and methods, which you can infer from Russell and Norvig's and from Koller and Friedman's algorithms.

On Canvas, in p3.zip, you can find a class implementation for the drug-study problem we discussed in lecture. You can also find this file on cs-class.

Evaluate your implementation three problems:

1. Russell and Norvig's burglary network,
2. Russell and Norvig's sprinkler network (Figure 14.12a),
3. one problem of your choosing from a reputable source with three or more nodes
Implement these three problems as three separate executables: Example1, Example2, and Example3, respectively. The main method for these classes can construct the network through direct assignment. For the burglary network, the main method should instantiate that Mary called and that John called, compute the probability of the alarm sounding, and print its distribution to the console. For the sprinkler network, the main method should instantiate that the sprinkler is on and there is water on the street, compute the probability of rain, and print its distribution to the console. For the example that you choose, you are free to select the query and evidence variables. In comments, describe the reasoning problem, the network, its source, and the query and evidence variables. For output, it is sufficient to print the probability distribution of the query variable. Include with your submission a transcript of your program's output on the three problems.

#### Instructions for Electronic Submission

In a file named HONOR, provide the following information:
In accordance with the class policies and Georgetown's Honor Code,
I certify that, with the exceptions of the course materials and those
items noted below, I have neither given nor received any assistance
on this project.

Name
NetID


When you are ready to submit your program for grading, create a zip file named submit.zip containing your source files, honor statement, and transcript by typing

\$ zip submit.zip *.java transcript HONOR

Do not include these files in a subdirectory. Upload submit.zip to Autolab. You can submit your assignment to the compile check p3c five times. You can submit your assignment p3 two times, and you will see the autograder's output for the drug-study problem that we discussed in class. After the deadline, I will use a different autograder to conduct a comprehensive evaluation.

#### Plan B

If Autolab is down, upload your zip file to Canvas.

Copyright © 2022 Mark Maloof. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed.