Hide menu

TDDC17 Artificial Intelligence

Lab 4: Bayesian Networks

Aim

The purpose of this lab is to provide you with a software platform that will enable you to construct Bayesian Networks and perform inference on them. In doing this, you will acquire hands-on experience in using Bayesian Networks as a tool for constructing probabilistic models and using them for probabilistic inference in application domains. In addition you will be provided with a few theory questions to guide you in understanding what is going on in the applet.

Preparation

Read chapter 13.1-5 and 14.1-4 (3rd edition, 12.1-6 and 13.1-3 in 4th edition and Global Edition) in the course book before doing this lab. It is important that you do this. You should have an understanding what Bayesian Networks are, how they are constructed and their theoretical underpinnings before doing this lab. Note, that to run the Java Applet used in this lab on your own computer, the Java Runtime Environment (JRE) is required. The JRE can be downloaded here.

Part I: Tutorial

The purpose of the first part of this lab is to introduce you to the Java Applet that will be used to construct Bayesian Networks. There are a number of tutorials which walk you through the process of this construction and explain different ways to query Bayesian Networks.

The software that you will use during the lab is called "Bayes Applet" and can be found at http://aispace.org/bayes/.To start the applet, just click on the "Start Applet" button. Note: in case you have trouble accessing http://aispace.org/bayes/, check the General channel in your Teams group for more information.

The tutorials you will go through can be found at http://aispace.org/bayes/. It is strongly recommended that you read at least the first and the third tutorial. Tutorials 4 - 6 cover variable elimination algorithms and how to build decision networks with the tool. More on this may also be found in the course book. The topics in tutorials 4-6 are not covered in this lab so you can safely skip reading those tutorials unless you are interested.

Due to the nature of applets, you can not save your networks directly to your account. Instead you'll have to click on the "Edit/ViewEdit Text representation (.xml format)" in the applet and copy and paste the contents to a local file.

There is no examination on this part of the lab but you are encouraged to model the earthquake example on page 512 (3rd edition, page 414 in 4th edition) in the course book.

Part II: Inference in an existing Bayesian network

In this part of the lab, you will be provided with an existing Bayesian Network. The purpose is to provide you with a chance to query the network and investigate probabilisitic inference on such networks. Then this network is used to answer a few theory questions which will aid you in understanding the fundamentals of probabilistic inference in Bayesian networks.

Scenario

The local nuclear power plant has been running for a long time and now the owner wants to know whether there has been any degradation in the safety of the plant. He therefore hires safety experts who use Bayesian Networks as a modeling tool for prediction and explanation. After spending a number of weeks gathering empirical data they create the network in figure 1 and save the data in this file.


Figure 1: The Bayesian Network for the nuclear plant

Tasks for part II

The owner asks you to start experimenting with the network and find out how safe the plant is.
  1. Start the applet and choose "Edit/ViewEdit Text representation (.xml format)". A window with the XML representation of the current (empty) network will pop up. This window can be used to edit or save the current network.
  2. Copy and paste the network part of the file bayesian_net/nuclear_power_station.xml into the corresponding network tag in the empty network.
  3. Press the "Update" button. You should now see that a network has been created in the original applet window.
  4. Set the "Network Options / Decimal Places for Monitoring" to 5. This means that you will be able to see small changes in probabilities.
  5. Use the applet and the loaded Bayesian Network to answer the following questions:
    • a) What is the risk of melt-down in the power plant during a day if no observations have been made? What if there is icy weather?
    • b) Suppose that both warning sensors indicate failure. What is the risk of a meltdown in that case? Compare this result with the risk of a melt-down when there is an actual pump failure and water leak. What is the difference? The answers must be expressed as conditional probabilities of the observed variables, P(Meltdown|...).
    • c) The conditional probabilities for the stochastic variables are often estimated by repeated experiments or observations. Why is it sometimes very difficult to get accurate numbers for these? What conditional probabilites in the model of the plant do you think are difficult or impossible to estimate?
    • d) Assume that the "IcyWeather" variable is changed to a more accurate "Temperature" variable instead (don't change your model). What are the different alternatives for the domain of this variable? What will happen with the probability distribution of P(WaterLeak | Temperature) in each alternative?
  6. To guide your understanding of how Bayesian networks work we provide a few theory questions below that should be answered using the lecture slides and/or book. When asked to calculate something manually show your calculations.
    Clarification: You can read relevant conditional probabilities out of the tables in the applet ("View Probability Table"). This is just from the domain XML file you loaded above and not something the applet has calculated.
    • a) What does a probability table in a Bayesian network represent?
    • b) What is a joint probability distribution? Using the chain rule on the structure of the Bayesian network to rewrite the joint distribution as a product of P(child|parent) expressions, calculate manually the particular entry in the joint distribution of P(Meltdown=F, PumpFailureWarning=F, PumpFailure=F, WaterLeakWaring=F, WaterLeak=F, IcyWeather=F). Is this a common state for the nuclear plant to be in?
    • c) What is the probability of a meltdown if you know that there is both a water leak and a pump failure? Would knowing the state of any other variable matter? Explain your reasoning!
    • d) Calculate manually the probability of a meltdown when you happen to know that PumpFailureWarning=F, WaterLeak=F, WaterLeakWarning=F and IcyWeather=F but you are not really sure about a pump failure.
      Hint: Use the Exact Inference formula near the end of the slides, or in sec. 14.4.1 (3rd edition, sec. 13.3.1 p. 427 in 4th edition) in the book. This formula includes both conditioning on the variables you know (evidence) and marginalizing (summing) over the variable(s) you do not know (often called unobserved or hidden). You need to calculate this both for P(Meltdown=T|...) and P(Meltdown=F|..) and normalize them so that they sum to 1. This normalization factor is the alpha symbol in the equation. With this formula you could answer any query in the network, though it will be impractical for cases with many unobserved variables. A suggestion is to move the terms that do not involve the pump failure variable out of the sum over the two states pump failure can be in (T/F). You may use inference in the applet for verification purposes, but small differences is expected due to rounding errors.

Part III: Extending a network

Scenario

The owner of the nuclear plant is quite selfish and wants to optimize profit of the plant at the expense of safety, yet he is very worried about his future survival in case a problem with the plant arises. Instead of increasing the safety of the plant which is costly, he decides to analyse his chances of escaping from the plant in case of a melt-down. As an apprentice to the owner, the owner wants you to investigate the properties of his escape vehicle (his car). Your model of the car is the same as in exercise 14.7, figure 14.21 (p. 560) in the course book (or figure 2 below) with the extension of the "IcyWeather" variable, which of course is the same as we already have in our model of the plant.


Figure 2: A Bayesian network describing some features of a car's electrical system and engine. Each variable is Boolean, and the true value indicates that the corresponding aspect of the vehicle is in working order.

After a year of observations and subjective assumptions you come up with the following conditional and prior probabilities:
  • P(battery | icyWeather) = 0.8
  • P(battery | ¬icyWeather) = 0.95
  • P(radio | battery) = 0.95
  • P(ignition | battery) = 0.95
  • P(gas) = 0.95
  • P(starts | gas ∧ ignition) = 0.95
  • P(moves | starts) = 0.95
  • P(survives | moves ∧ melt-down) = 0.8
  • P(survives | moves ∧ ¬melt-down) = P(survives | ¬moves ∧ ¬melt-down) = 1.0
  • P(survives | ¬moves ∧ melt-down) = 0.0
Fill in the rest of the probabilities by using common sense reasoning about the domain.

Task for part III

  1. Model the car with the applet tool and integrate it with the model of the plant.
  2. Answer the following questions:
    • During the lunch break, the owner tries to show off for his employees by demonstrating the many features of his car stereo. To everyone's disappointment, it doesn't work. How did the owner's chances of surviving the day change after this observation?
    • The owner buys a new bicycle that he brings to work every day. The bicycle has the following properties:
      • P(bicycle_works) = 0.9
      • P(survives | ¬moves ∧ melt-down ∧ bicycle_works) = 0.6
      • P(survives | moves ∧ melt-down ∧ bicycle_works) = 0.9
      How does the bicycle change the owner's chances of survival?
    • It is possible to model any function in propositional logic with Bayesian Networks. What does this fact say about the complexity of exact inference in Bayesian Networks? What alternatives are there to exact inference?

Part IV: More extensions

Scenario

After your excellent analysis of the plant's Bayesian Network and the creation of the model of the owner's car, he realizes that he is still in great danger. He comes to the conclusion that he needs to hire someone who is in charge of the plant's safety. After some job interviews he decides that a Mr H.S. is the most suitable person for the job because he practically works for free. But Mr H.S. has some less appealing properties:
  • He sleeps a lot during work which means that he can not react that rapidly to warning signals and so on.
  • He is very incompetent. Even if he is awake it doesn't mean that he knows what to do in case of an emergency.
You volunteer for the task of modeling Mr H.S.'s behavior with the help of the "Bayes Applet" tool.

Task for part IV

  1. Using your own modeling creativity, create a model of Mr H.S. with the Applet tool. The requirements of the model are the following:
    • It must be integrated with the model of the nuclear plant and must depend on the "WaterLeakWarning" and "PumpFailureWarning" stochastic variables.
    • It must contain at least four stochastic variables.
    • It should match fairly well with the informal description of Mr H.S.'s properties given in the scenario description.
  2. Answer the following questions using your model:
    • The owner had an idea that instead of employing a safety person, to replace the pump with a better one. Is it possible, in your model, to compensate for the lack of Mr H.S.'s expertise with a better pump?
    • Mr H.S. fell asleep on one of the plant's couches. When he wakes up he hears someone scream: "There is one or more warning signals beeping in your control room!". Mr H.S. realizes that he does not have time to fix the error before it is to late (we can assume that he wasn't in the control room at all). What is the chance of survival for Mr H.S. if he has a car with the same properties as the owner? Hint: This question involves a disjunction (A or B) which can not be answered by querying the network as is. How could you answer such questions? Maybe something could be added or modified in the network.
    • What unrealistic assumptions do you make when creating a Bayesian Network model of a person?
    • Describe how you would model a more dynamic world where for example the "IcyWeather" is more likely to be true the next day if it was true the day before. You only have to consider a limited sequence of days.

How to report

The examination for this lab will consist of the following:
  1. Demonstrate your networks to the lab assistant. The lab assistants may have some extra questions for you that you have to answer correctly during the demonstration.
  2. Write a report where you answer all the questions in part II-IV. In those answers where the applet is used for obtaining the result, you must clearly describe what variables you choose to observe and why. The theory questions in part II should likewise be accompanied by reasoning and the steps of any calculations. Submission instructions.

Acknowledgements

This lab has been developed by Per Nyblom.



Page responsible: Fredrik Heintz
Last updated: 2023-08-18