('+', 'fail'):[.05, .95], ('-', 'pass'):[.7, .3], ('-', 'fail'):[0, 1] })) academe_graph = DiscreteBayesNet([theory, practice, extra, others, markTP, others, globalMark, finalMark]) # This is designed to reproduce the results of Flores' paper print "Testing Explanation Tree:" test_tree = generate_explanation_tree(academe_graph, ['Theory', 'Practice', 'Extra', 'Others'], {'finalMark':'fail'}, [], 0.0001, 0.0002) print test_tree print "=========================" print "Testing MRE:" MRE = generate_MRE(academe_graph, ['Theory', 'Practice', 'Extra', 'Others'], {'finalMark':'fail'}) for n in MRE: print n print "=========================" print "Testing K-MRE:" K_MRE = generate_K_MRE(MRE) print K_MRE print "=========================" print "Testing MAP:" MRE = generate_MAP_Ind_Simplification(academe_graph, ['Theory', 'Practice', 'Extra', 'Others'], {'finalMark':'fail'}, 0.1) for x in MRE: print x print "========================="
lake_graph.prob({'Bird':'T','Island':'F' }) #test running explanation tree algorithm on the above graph print "Testing Explanation Tree:" test_tree = generate_explanation_tree(lake_graph, ['Bird', 'Island'], {'Pox':'T'}, [], 0.0001, 0.0002) print test_tree print "=========================" print "Testing Explanation Forest:" forest = generate_ET_forest(lake_graph, ['Bird', 'Island'], {'Pox':'T'}, []) for tree in forest: print tree print "=========================" print "Testing MRE:" MRE = generate_MRE(lake_graph, ['Bird', 'Island'], {'Pox':'T'}) for x in MRE: print x print "=========================" print "Testing K-MRE:" K_MRE = generate_K_MRE(MRE) for x in K_MRE: print x print "=========================" print "Testing Causal Intervention:" print "Intervene Bird to true" intervened = lake_graph.create_graph_with_intervention({'Bird' : 'T'}) print "post intervention probability of Bird being true", intervened.prob( {'Bird' : 'T'} ) print "post intervention prob of Pox being true", intervened.prob( {'Pox':'T'} )
('yes', 'no') : [.7, .3], ('no', 'yes') : [.8, .2], ('no', 'no') : [.1, .9] })) asia_graph = DiscreteBayesNet([ asia, tuberculosis, tborca, x_ray, dyspnea, bronchitis, smoking, lung_cancer ]) exp_var = [ 'Lung_Cancer', 'VisitToAsia', 'Tuberculosis', 'Smoking', 'Bronchitis' ] explanadum = {'X_ray': 'abnormal'} print "Testing MRE:" MRE = generate_MRE(asia_graph, exp_var, explanadum) print MRE print "=========================" print "Testing K-MRE:" K_MRE = generate_K_MRE(MRE) print K_MRE print "=========================" print "Testing Explanation Tree:" test_tree = generate_explanation_tree(asia_graph, exp_var, explanadum, [], 0.01, 0.2) print test_tree print "=========================" print "Testing Causal Explanation Tree:"
#test running explanation tree algorithm on the above graph print "Testing Explanation Tree:" test_tree = generate_explanation_tree(lake_graph, ['Bird', 'Island'], {'Pox': 'T'}, [], 0.0001, 0.0002) print test_tree print "=========================" print "Testing Explanation Forest:" forest = generate_ET_forest(lake_graph, ['Bird', 'Island'], {'Pox': 'T'}, []) for tree in forest: print tree print "=========================" print "Testing MRE:" MRE = generate_MRE(lake_graph, ['Bird', 'Island'], {'Pox': 'T'}) for x in MRE: print x print "=========================" print "Testing K-MRE:" K_MRE = generate_K_MRE(MRE) for x in K_MRE: print x print "=========================" print "Testing Causal Intervention:" print "Intervene Bird to true" intervened = lake_graph.create_graph_with_intervention({'Bird': 'T'}) print "post intervention probability of Bird being true", intervened.prob( {'Bird': 'T'})
dyspnea = DiscreteBayesNode( "Dyspnea", ["TborCa", "Bronchitis"], DiscreteCPT( ["yes", "no"], {("yes", "yes"): [0.9, 0.1], ("yes", "no"): [0.7, 0.3], ("no", "yes"): [0.8, 0.2], ("no", "no"): [0.1, 0.9]}, ), ) asia_graph = DiscreteBayesNet([asia, tuberculosis, tborca, x_ray, dyspnea, bronchitis, smoking, lung_cancer]) exp_var = ["Lung_Cancer", "VisitToAsia", "Tuberculosis", "Smoking", "Bronchitis"] explanadum = {"X_ray": "abnormal"} print "Testing MRE:" MRE = generate_MRE(asia_graph, exp_var, explanadum) print MRE print "=========================" print "Testing K-MRE:" K_MRE = generate_K_MRE(MRE) print K_MRE print "=========================" print "Testing Explanation Tree:" test_tree = generate_explanation_tree(asia_graph, exp_var, explanadum, [], 0.01, 0.2) print test_tree print "=========================" print "Testing Causal Explanation Tree:" test_tree = generate_causal_explanation_tree(asia_graph, asia_graph, exp_var, {}, explanadum, [], 0.001)
DiscreteCPT(['f', 'm'], [.5, .5])) drug = DiscreteBayesNode('Drug', ['Sex'], \ DiscreteCPT(['yes', 'no'], {('f', ):[.25, .75], ('m', ):[.75, .25]})) recovery = DiscreteBayesNode('Recovery', ['Sex', 'Drug'], \ DiscreteCPT(['recovery', 'death'], { ('f', 'yes'):[.2, .8], ('f', 'no'):[.3, .7], ('m', 'yes'):[.6, .4], ('m', 'no'):[.7, .3] })) drug_graph = DiscreteBayesNet( [sex, drug, recovery]) print "Testing Explanation Tree:" test_tree = generate_explanation_tree(drug_graph, ['Sex', 'Drug'], {'Recovery':'recovery'}, [], 0.01, 0.2) print test_tree print "=========================" print "Testing MRE:" MRE = generate_MRE(drug_graph, ['Sex', 'Drug'], {'Recovery':'recovery'}) print MRE print "=========================" print "Testing Causal Explanation Tree:" test_tree = generate_causal_explanation_tree(drug_graph, drug_graph, ['Sex', 'Drug'], {},{'Recovery':'recovery'}, [], 0.001) print test_tree print "========================="
})) academe_graph = DiscreteBayesNet( [theory, practice, extra, others, markTP, others, globalMark, finalMark]) # This is designed to reproduce the results of Flores' paper print "Testing Explanation Tree:" test_tree = generate_explanation_tree( academe_graph, ['Theory', 'Practice', 'Extra', 'Others'], {'finalMark': 'fail'}, [], 0.0001, 0.0002) print test_tree print "=========================" print "Testing MRE:" MRE = generate_MRE(academe_graph, ['Theory', 'Practice', 'Extra', 'Others'], {'finalMark': 'fail'}) for n in MRE: print n print "=========================" print "Testing K-MRE:" K_MRE = generate_K_MRE(MRE) print K_MRE print "=========================" print "Testing MAP:" MRE = generate_MAP_Ind_Simplification( academe_graph, ['Theory', 'Practice', 'Extra', 'Others'], {'finalMark': 'fail'}, 0.1) for x in MRE: