forked from sa-and/KR21_project2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotes.py
More file actions
70 lines (48 loc) · 2.03 KB
/
notes.py
File metadata and controls
70 lines (48 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from BayesNet import BayesNet
from BNReasoner import BNReasoner
import pandas as pd
# def print(self):
# all_ctp = self.bn.get_all_cpts()
# for ctp in all_ctp:
# test_ctp = all_ctp[ctp]
# test_cpt2 = all_ctp["Rain?"]
# print(test_ctp)
# print(test_cpt2)
# combined_cpt = self.factor_multiplication(test_cpt2, test_ctp)
# print(combined_cpt)
# def print(self):
# all_ctp = self.bn.get_all_cpts()
# test_ctp = all_ctp["Wet Grass?"]
# cpt = self.marginalization("Rain?", test_ctp)
# print(cpt)
# def print(self):
# all_ctp = self.bn.get_all_cpts()
# test_ctp = all_ctp["Wet Grass?"]
# cpt, extended_factor = self.maxing_out("Rain?", test_ctp)
# print(cpt)
# print(extended_factor)
# # Get instantiation of X where variable X is maxed-out
# combined_cpt = pd.concat([cpt, new_cpt], axis=1)
# print(combined_cpt)
# reduced_cpt = combined_cpt.dropna(axis=0, how='any')
# reduced_cpt[X] = reduced_cpt[X].map({True: f'{X} = True', False: f'{X} = False'})
# reduced_cpt = reduced_cpt.iloc[:, :- (len(variables_left) + 1)]
# print(reduced_cpt)
# reduced_cpt["p"] = reduced_cpt["p"].astype(str)
# reduced_cpt['factor'] = reduced_cpt[["p", X]].agg(': '.join, axis=1)
# extended_factor = reduced_cpt.drop([X, "p"], axis=1)
# return new_cpt, extended_factor
bn = BayesNet()
bn.load_from_bifxml("./testing/stroke_network.BIFXML")
bayes = BNReasoner(bn)
#Q = set(["Smoking", "Obesity", "Diabetes Type II", "High Blood Pressure", "Stroke Symptoms", "Intracerebral Hemorrhage", "Acute Ischemic Stroke", "No Stroke" ])
Q = set(["Smoking", "Obesity", "Diabetes Type II", "High Blood Pressure"])
e = pd.Series({"Survival": False})
X = "I"
# cpts = bn.get_all_cpts()
# test_cpt = cpts["I"]
# print(test_cpt)
#outcome = bayes.maxing_out(X, test_cpt)
outcome = bayes.marginal_distribution(Q, e)
map = bayes.MAP(Q, e)
print(map)