# Exercise - Causal Reasoning with (Conditional) Probability Tables

## Table of Contents

## 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

The following literature can help you to acquire this knowledge:

- Read Chapter 3 "Probability and Information Theory" of the Deep Learning Book
- Christian Herta's Website about Bayesian Networks (German)
- (Optional) Notebook bayes-theorem.ipynb

### 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))
pgm.add_edge("A", "B")
pgm.add_edge("B", "C")
def nodes_D(pgm):
pgm.add_node(daft.Node("D", r"$D$", 1, 5, scale=2))
pgm.add_edge("D", "B")
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()`

**Task:**

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) $:

`plot_network_extended()`

**Task:**

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

## Literature

## Licenses

### Notebook License (CC-BY-SA 4.0)

*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

is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Based on a work at https://gitlab.com/deep.TEACHING.

### Code License (MIT)

*The following license only applies to code cells of the notebook.*

Copyright 2018 Christian Herta, Klaus Strohmenger

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.