From 914b0dedbf47a74880d4559913a5fb6901217468 Mon Sep 17 00:00:00 2001 From: Jon <vitale.jonathan@ymail.com> Date: Thu, 10 Aug 2023 16:34:17 +0200 Subject: [PATCH] Fix incorrect probabilities and typos --- week6/solution/exercise1-2.py | 2 +- week6/solution/exercise3.py | 4 ++-- week6/solution/exercise5.py | 9 ++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/week6/solution/exercise1-2.py b/week6/solution/exercise1-2.py index bff4f79..f18dfc6 100644 --- a/week6/solution/exercise1-2.py +++ b/week6/solution/exercise1-2.py @@ -45,7 +45,7 @@ houses = ['gryffindor', 'ravenclaw', 'slytherin', 'hufflepuff'] for i, prob in enumerate([0.002, 0.002, 0.0001, 0.01]): pd['PureHeart=true|House={0}'.format(houses[i])] = prob pd['PureHeart=false|House={0}'.format(houses[i])] = 1 - prob -for i, prob in enumerate([0.05, 0.02, 0.02, 0.001]): +for i, prob in enumerate([0.05, 0.02, 0.02, 0.01]): pd['Brave=true|House={0}'.format(houses[i])] = prob pd['Brave=false|House={0}'.format(houses[i])] = 1 - prob for house in houses: diff --git a/week6/solution/exercise3.py b/week6/solution/exercise3.py index a1a0ec8..70a9a7e 100644 --- a/week6/solution/exercise3.py +++ b/week6/solution/exercise3.py @@ -61,8 +61,8 @@ brave_cpd = TabularCPD( evidence=['House'], evidence_card=[4], values=[ - [0.05, 0.02, 0.02, 0.001], # Brave true - [1 - 0.05, 1 - 0.02, 1 - 0.02, 1 - 0.001] # Brave false + [0.05, 0.02, 0.02, 0.01], # Brave true + [1 - 0.05, 1 - 0.02, 1 - 0.02, 1 - 0.01] # Brave false ] ) hogwarts_bn.add_cpds(brave_cpd) diff --git a/week6/solution/exercise5.py b/week6/solution/exercise5.py index 0c3038d..dce083f 100644 --- a/week6/solution/exercise5.py +++ b/week6/solution/exercise5.py @@ -12,10 +12,10 @@ hogwarts_hmm = DenseHMM() states = ['gryffindor', 'ravenclaw', 'slytherin', 'hufflepuff'] # Possible observations: -# 0. AcromantulaSighting=true, UnicornSighting=true (AU) -# 1. AcromantulaSighting=true, UnicornSighting=false (AX) -# 2. AcromantulaSighting=false, UnicornSighting=true (XU) -# 4. AcromantulaSighting=false, UnicornSighting=false (XX) +# 0. AcromantulaSighting=true, UnicornSighting=true (XX) +# 1. AcromantulaSighting=true, UnicornSighting=false (XO) +# 2. AcromantulaSighting=false, UnicornSighting=true (OX) +# 4. AcromantulaSighting=false, UnicornSighting=false (OO) # emission probability distributions for the two hidden states state_dists = [None, None, None, None] @@ -24,7 +24,6 @@ for i, house in enumerate(states): query = inference.query(variables=['AcromantulaSighting','UnicornSighting'], evidence={'House': i, 'TimeOfDay': 1} ) val = query.values probabilities = [val[0,0], val[0,1], val[1,0], val[1,1]] - print(np.array(probabilities).sum()) cur_state_dist = Categorical([probabilities]) state_dists[i] = cur_state_dist -- GitLab