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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
| import pomegranate
PatientAge = pomegranate.DiscreteDistribution(
{'0-30': 0.10, '31-65': 0.30, '65+': 0.60})
CTScanResult = pomegranate.DiscreteDistribution(
{'Ischemic Stroke': 0.7, 'Hemmorraghic Stroke': 0.3})
MRIScanResult = pomegranate.DiscreteDistribution(
{'Ischemic Stroke': 0.7, 'Hemmorraghic Stroke': 0.3})
Anticoagulants = pomegranate.DiscreteDistribution(
{'Used': 0.5, 'Not used': 0.5})
StrokeType = pomegranate.ConditionalProbabilityTable([
['Ischemic Stroke', 'Ischemic Stroke', 'Ischemic Stroke', 0.8],
['Ischemic Stroke', 'Hemmorraghic Stroke', 'Ischemic Stroke', 0.5],
['Hemmorraghic Stroke', 'Ischemic Stroke', 'Ischemic Stroke', 0.5],
['Hemmorraghic Stroke', 'Hemmorraghic Stroke', 'Ischemic Stroke', 0],
['Ischemic Stroke', 'Ischemic Stroke', 'Hemmorraghic Stroke', 0],
['Ischemic Stroke', 'Hemmorraghic Stroke', 'Hemmorraghic Stroke', 0.4],
['Hemmorraghic Stroke', 'Ischemic Stroke', 'Hemmorraghic Stroke', 0.4],
['Hemmorraghic Stroke', 'Hemmorraghic Stroke', 'Hemmorraghic Stroke', 0.9],
['Ischemic Stroke', 'Ischemic Stroke', 'Stroke Mimic', 0.2],
['Ischemic Stroke', 'Hemmorraghic Stroke', 'Stroke Mimic', 0.1],
['Hemmorraghic Stroke', 'Ischemic Stroke', 'Stroke Mimic', 0.1],
['Hemmorraghic Stroke', 'Hemmorraghic Stroke', 'Stroke Mimic', 0.1]], [CTScanResult, MRIScanResult])
Mortality = pomegranate.ConditionalProbabilityTable([
['Ischemic Stroke', 'Used', 'False', 0.28],
['Hemmorraghic Stroke', 'Used', 'False', 0.99],
['Stroke Mimic', 'Used', 'False', 0.1],
['Ischemic Stroke', 'Not used', 'False', 0.56],
['Hemmorraghic Stroke', 'Not used', 'False', 0.58],
['Stroke Mimic', 'Not used', 'False', 0.05],
['Ischemic Stroke', 'Used', 'True', 0.72],
['Hemmorraghic Stroke', 'Used', 'True', 0.01],
['Stroke Mimic', 'Used', 'True', 0.9],
['Ischemic Stroke', 'Not used', 'True', 0.44],
['Hemmorraghic Stroke', 'Not used', 'True', 0.42],
['Stroke Mimic', 'Not used', 'True', 0.95]],
[StrokeType, Anticoagulants])
Disability = pomegranate.ConditionalProbabilityTable([
['Ischemic Stroke', '0-30', 'Negligible', 0.80],
['Hemmorraghic Stroke', '0-30', 'Negligible', 0.70],
['Stroke Mimic', '0-30', 'Negligible', 0.9],
['Ischemic Stroke', '31-65', 'Negligible', 0.60],
['Hemmorraghic Stroke', '31-65', 'Negligible', 0.50],
['Stroke Mimic', '31-65', 'Negligible', 0.4],
['Ischemic Stroke', '65+', 'Negligible', 0.30],
['Hemmorraghic Stroke', '65+', 'Negligible', 0.20],
['Stroke Mimic', '65+', 'Negligible', 0.1],
['Ischemic Stroke', '0-30', 'Moderate', 0.1],
['Hemmorraghic Stroke', '0-30', 'Moderate', 0.2],
['Stroke Mimic', '0-30', 'Moderate', 0.05],
['Ischemic Stroke', '31-65', 'Moderate', 0.3],
['Hemmorraghic Stroke', '31-65', 'Moderate', 0.4],
['Stroke Mimic', '31-65', 'Moderate', 0.3],
['Ischemic Stroke', '65+', 'Moderate', 0.4],
['Hemmorraghic Stroke', '65+', 'Moderate', 0.2],
['Stroke Mimic', '65+', 'Moderate', 0.1],
['Ischemic Stroke', '0-30', 'Severe', 0.1],
['Hemmorraghic Stroke', '0-30', 'Severe', 0.1],
['Stroke Mimic', '0-30', 'Severe', 0.05],
['Ischemic Stroke', '31-65', 'Severe', 0.1],
['Hemmorraghic Stroke', '31-65', 'Severe', 0.1],
['Stroke Mimic', '31-65', 'Severe', 0.3],
['Ischemic Stroke', '65+', 'Severe', 0.3],
['Hemmorraghic Stroke', '65+', 'Severe', 0.6],
['Stroke Mimic', '65+', 'Severe', 0.8]],
[StrokeType, PatientAge])
S1 = pomegranate.Node(PatientAge, name='PatientAge')
S2 = pomegranate.Node(CTScanResult, name='CTScanResult')
S3 = pomegranate.Node(MRIScanResult, name='MRIScanResult')
S4 = pomegranate.Node(StrokeType, name='StrokeType')
S5 = pomegranate.Node(Anticoagulants, name='Anticoagulants')
S6 = pomegranate.Node(Mortality, name='Mortality')
S7 = pomegranate.Node(Disability, name='Disability')
model = pomegranate.BayesianNetwork("Diagnosing")
model.add_states(S1, S2, S3, S4, S5, S6, S7)
model.add_edge(S2, S4)
model.add_edge(S3, S4)
model.add_edge(S4, S6)
model.add_edge(S5, S6)
model.add_edge(S1, S7)
model.add_edge(S4, S7)
model.bake()
print("p1 =",
model.predict_proba({'PatientAge': '31-65',
'CTScanResult': 'Ischemic Stroke'})[5].parameters[0]['True'])
print("p2 =",
model.predict_proba({'PatientAge': '65+',
'MRIScanResult': 'Hemmorraghic Stroke'})[6].parameters[0]['Moderate'])
print("p3 =",
model.predict_proba({'PatientAge': '65+',
'CTScanResult': 'Hemmorraghic Stroke',
'MRIScanResult': 'Ischemic Stroke'})[3].parameters[0]['Stroke Mimic'])
print("p4 =",
model.predict_proba({'PatientAge': '0-30'})[4].parameters[0]['Not used'])
|