# Exercise - Causal Reasoning with (Conditional) Probability Tables

## Introduction

In this notebook you will find exercises about causal reasoning with given (conditional) probability tables.

In order to detect errors in your own code, execute the notebook cells containing assert or assert_almost_equal. These statements raise exceptions, as long as the calculated result is not yet correct.

## Requirements

### Knowledge

To complete this exercise notebook you should possess knowledge about the following topics.

• Bayes Theorem
• Bayes Rule / Chain Rule
• Sum Rule

### Python Modules

# External Modules
import daft
from matplotlib import rc

%matplotlib inline
def nodes_A_B_C(pgm):
pgm.add_node(daft.Node("A", r"$A$", 3, 5, observed=False, scale=2))
pgm.add_node(daft.Node("B", r"$B$", 3, 3, scale=2))
pgm.add_node(daft.Node("C", r"$C$", 3, 1, scale=2))

def nodes_D(pgm):
pgm.add_node(daft.Node("D", r"$D$", 1, 5, scale=2))

def plot_network_simple():
pgm = daft.PGM([6, 6], origin=[-2.0, 0.0], label_params={'fontsize':18})
nodes_A_B_C(pgm)
pgm.render()

def plot_network_extended():
pgm = daft.PGM([6, 6], origin=[-2.0, 0.0], label_params={'fontsize':18})
nodes_A_B_C(pgm)
nodes_D(pgm)
pgm.render() 

## Exercise

Secrets are meant to be secret, but they rarely stay secret for a long time. You are interested about how the secrets at your school spread so took some notes:

The first table you have made is about Alice. If you know about a secret, the chances Alice knows about it are 30% to 70%, short $P(A)$:

Bob and Alice are close friends. If Alice knows (or doesn't know) about a secret, chances that Bob knows about it are as follows ($P(B|A))$:

Lastly, you took notes about Crystal. If Bob (doesn't) know a secret, chances for Crystal knowing it are ($P(C|B)$):

plot_network_simple()

When you don't know if Bob knows about secret, but you know that Alice knows about it. What are the chances that Crystal knows about it ($P(C=1\mid A=1)$)?

Lately Bob also often hangs around with Dustin and you have extended your model. The new (or updated) tables are:

$P(D)$:

$P(B|A,D)$:

plot_network_extended()

How do these new circumstances change your probabability $P(C=1|A=1)$?

## Literature

The following license applies to the complete notebook, including code cells. It does however not apply to any referenced external media (e.g., images).

HTW Berlin - Angewandte Informatik - Advanced Topics - Exercise - Bayes Rule
by Christian Herta, Klaus Strohmenger