diff --git a/week6/solution/exercise1-2.py b/week6/solution/exercise1-2.py index bff4f79db614953c9ce636a95b2d261a9bd8dfbc..f18dfc601e8e6252c7887fdf6c6bf5610c340ed8 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 a1a0ec82613a09aed1f9d01eea1a2f7b173d3cd3..70a9a7e17540dc7f48f95747bb5ab063ff61fec8 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 0c3038d73a16da6b30b453b3f8f6c76dd3eb40c7..dce083f72707a115103f1790d1e005f0b897e700 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