Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/brainy.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 % Example of explaining away from |
wolffd@0 | 2 % http://www.ai.mit.edu/~murphyk/Bayes/bnintro.html#explainaway |
wolffd@0 | 3 % |
wolffd@0 | 4 % Suppose you have to be brainy or smart to get into college. |
wolffd@0 | 5 % B S P(C=1) P(C=2) 1=false 2=true |
wolffd@0 | 6 % 1 1 1.0 0.0 |
wolffd@0 | 7 % 2 1 0.0 1.0 |
wolffd@0 | 8 % 1 2 0.0 1.0 |
wolffd@0 | 9 % 2 2 0.0 1.0 |
wolffd@0 | 10 % |
wolffd@0 | 11 % |
wolffd@0 | 12 % If we observe that you are in college, you must be either brainy or sporty or both. |
wolffd@0 | 13 % If we observre you are in college and sporty, it is less likely you are brainy, |
wolffd@0 | 14 % since brainy-ness and sporty-ness compete as causal explanations of the effect. |
wolffd@0 | 15 |
wolffd@0 | 16 % B S |
wolffd@0 | 17 % \/ |
wolffd@0 | 18 % C |
wolffd@0 | 19 |
wolffd@0 | 20 B = 1; S = 2; C = 3; |
wolffd@0 | 21 dag = zeros(3,3); |
wolffd@0 | 22 dag([B S], C)=1; |
wolffd@0 | 23 ns = 2*ones(1,3); |
wolffd@0 | 24 bnet = mk_bnet(dag, ns); |
wolffd@0 | 25 bnet.CPD{B} = tabular_CPD(bnet, B, 'CPT', [0.5 0.5]'); |
wolffd@0 | 26 bnet.CPD{S} = tabular_CPD(bnet, S, 'CPT', [0.5 0.5]'); |
wolffd@0 | 27 CPT = zeros(2,2,2); |
wolffd@0 | 28 CPT(1,1,:) = [1 0]; |
wolffd@0 | 29 CPT(2,1,:) = [0 1]; |
wolffd@0 | 30 CPT(1,2,:) = [0 1]; |
wolffd@0 | 31 CPT(2,2,:) = [0 1]; |
wolffd@0 | 32 bnet.CPD{C} = tabular_CPD(bnet, C, 'CPT', CPT); |
wolffd@0 | 33 |
wolffd@0 | 34 engine = jtree_inf_engine(bnet); |
wolffd@0 | 35 ev = cell(1,3); |
wolffd@0 | 36 ev{C} = 2; |
wolffd@0 | 37 engine = enter_evidence(engine, ev); |
wolffd@0 | 38 m = marginal_nodes(engine, B); |
wolffd@0 | 39 fprintf('P(B=true|C=true) = %5.3f\n', m.T(2)) % 0.67 |
wolffd@0 | 40 |
wolffd@0 | 41 ev{S} = 2; |
wolffd@0 | 42 engine = enter_evidence(engine, ev); |
wolffd@0 | 43 m = marginal_nodes(engine, B); |
wolffd@0 | 44 fprintf('P(B=true|C=true,S=true) = %5.3f\n', m.T(2)) % 0.5 = unconditional baseline P(B=true) |