CSCI 379 homework 5: probability, Bayes rule, nets

Like the previous assignment, there’s no code to write for this assignment. The same guidelines apply: for the sake of consistency, you’ll submit your response using CSgit.

Follow the usual file and directory naming conventions; include your responses in hw5/hw5-write-up.txt.

Label the sections and organize your text so it’s easy for us to read and see which problem you are answering. In addition, this is a writing assignment and your responses must use proper, college-level English style and clearly, effectively, and convincingly communicate your understanding. In particular, you must use complete sentences and correct grammar; you’re not commenting code, where brief sentence fragments are acceptable. This is part of the requirements for this and similar assignments, and your marks will reflect that.

If you’re using plain text, you may want to copy and paste the various logical and probability symbols to use them in your response. See List of logic symbols - Wikipedia if you’d like more. (Be warned, though, that some of the equations below are rendered with MathJax and aren’t easily copy-and-pastable, so just use the logical equivalences sheet on Moodle or the above URL. Do make sure your file uses UTF-8.)

If you want to do proper math typesetting and use LaTeX or Typst, go ahead. I recommend Typst, which is a much newer system whose syntax is far more sane and easy to use, though TeX and friends are still incredibly dominant across the quantitative sciences. For LaTeX, one simple way to get started is with the Overleaf online editor.

get your copy-and-pastable logic symbols here

Some of the symbols below may not be selectable because of the way they are rendered – it’s usiung MathJax which is a JavaScript library that renders traditional TeX math notation (a language for which mathematicians and computer scientists are “native speakers”) into HTML. So, here’s a copy of the logical equivalences cheat sheet on Moodle, where everything is just Unicode text characters and not MathJax-rendered.

operation name name for operands
¬ not; negation
∧ and; conjunction conjuncts
∨ or; disjunction disjuncts
⇒ implies premise and conclusion; or antecedent and consequent
⇔ if and only if; biconditional

Operator precedence, high to low: ¬, ∧, ∨, ⇒, ⇔

Those match Python’s precedence for not, and, and or.

The symbols α, β, and γ below are arbitrary propositional logic sentences.

¬(¬α) ≡ α double-negation elimination
(α ⇒ β) ≡ ¬β ⇒ ¬α contraposition
(α ⇒ β) ≡ ¬α ∨ β implication elimination
(α ⇔ β) ≡ (α ⇒ β) ∧ (β ⇒ α) biconditional elimination
¬(α ∧ β) ≡ (¬α ∨ ¬β) De Morgan’s law
¬(α ∨ β) ≡ (¬α ∧ ¬β) De Morgan’s law
α ∧ (β ∨ γ) ≡ (α ∧ β) ∨ (α ∧ γ) distributivity of ∧ over ∨
α ∨ (β ∧ γ) ≡ (α ∨ β) ∧ (α ∨ γ) distributivity of ∨ over ∧
(α ∨ β) ∧ β ≡ β absorption law
(α ∧ β) ∨ β ≡ β absorption law

There’s also ∈ for set membership.

For this assignment, use the following joint distribution. “Rain” is whether or not it rained, “Grass” is whether or not the grass is wet, and “Umbrella” is whether or not you took your umbrella today.

Rain (R) Grass (G) Umbrella (U) P(R, G, U)
True True True 0.288
True True False 0.072
True False True 0.032
True False False 0.008
False True True 0.012
False True False 0.108
False False True 0.048
False False False 0.432

Joint distributions

Answer the following questions about marginal and joint distributions, and conditional probability.

  1. Produce the marginal distributions for each variable.

  2. Produce the joint distributions for Rain and Grass, for Rain and Umbrella, and for Grass and Umbrella.

  3. Compute the probability of the following. Show your work:

    1. \(P(R | U)\)

    2. \(P(\lnot G\ |\ U)\)

    3. \(P(U\ |\ G)\)

    4. \(P(R\ |\ G, U)\)

    5. \(P(R\ |\ G)\)

Independence

Answer these questions on independence.

  1. Determine if any pair of variables is independent.

  2. Show that Grass is conditionally independent of Umbrella given Rain.

Bayes nets

Now you’ll represent the above probabilities as a Bayes net.

For actually drawing the net – if you like, just draw it on paper (neatly and legibly, please) and add a photo here. You can also use Google Drawings (click the link, or in Google Drive, select “+ New”, and look in the More menu) which is isn’t too hard to use for this simple example. There are lots of other online diagram editors, too.

You could also really go down a rabbit hole (probably not a great use of your time) and use Graphviz, which converts a text format into SVGs or Pangs.

  1. Given that both Grass and Umbrella are conditionally dependent on Rain and conditionally independent on each other, produce the Bayes net. Label each node with appropriate marginal and joint distributions from the above questions.

  2. Using the Bayes net, given that the grass is not wet and you have your umbrella, do the following:

    1. From the Bayes net, produce the equation for \(P(R, ¬G, U)\) using probability notation (e.g. \(P(A, B, C, D) = P(A | B) ⋅ P(C) ⋅ P(D | C, A)\)).

    2. From the Bayes net, produce the equation for \(P(¬R, ¬G, U)\) using probability notation.

    3. Given the evidence, which is more likely: it is raining or it is not? Why?

Implementing an inference algorithm

I said there’s no code for this assignment, and that’s true – but this is a CS class, not a math class. Let’s at least do something computer science-y.

Let’s start designing an algorithm for inference on a Bayes net. Answer the questions below. for simplicity, let’s start by assuming our variables are all boolean-valued. Our goal would be to implement an algorithm that would calculate \(P(x_1, x_2,...,x_n)\), where the \(x\)’s represent values for all the nodes/variables.

  1. We need to represent our net. What kind of data structure would you use? You’ll need to represent the DAG structure and associated CPTs. You needn’t write any code, just describe the data structure and how it would work.

  2. Our master inference equation, 13.2 (page 415 in the 4th edition) involves lots of factors of the form \(P(x_k\, |\, \mathrm{parents}(X_k))\). So you’ll need a function that calculates that. Its output would be a probability; what would its inputs be? What, at a high level, how would it work?