wolffd@0: % Example of explaining away from wolffd@0: % http://www.ai.mit.edu/~murphyk/Bayes/bnintro.html#explainaway wolffd@0: % wolffd@0: % Suppose you have to be brainy or smart to get into college. wolffd@0: % B S P(C=1) P(C=2) 1=false 2=true wolffd@0: % 1 1 1.0 0.0 wolffd@0: % 2 1 0.0 1.0 wolffd@0: % 1 2 0.0 1.0 wolffd@0: % 2 2 0.0 1.0 wolffd@0: % wolffd@0: % wolffd@0: % If we observe that you are in college, you must be either brainy or sporty or both. wolffd@0: % If we observre you are in college and sporty, it is less likely you are brainy, wolffd@0: % since brainy-ness and sporty-ness compete as causal explanations of the effect. wolffd@0: wolffd@0: % B S wolffd@0: % \/ wolffd@0: % C wolffd@0: wolffd@0: B = 1; S = 2; C = 3; wolffd@0: dag = zeros(3,3); wolffd@0: dag([B S], C)=1; wolffd@0: ns = 2*ones(1,3); wolffd@0: bnet = mk_bnet(dag, ns); wolffd@0: bnet.CPD{B} = tabular_CPD(bnet, B, 'CPT', [0.5 0.5]'); wolffd@0: bnet.CPD{S} = tabular_CPD(bnet, S, 'CPT', [0.5 0.5]'); wolffd@0: CPT = zeros(2,2,2); wolffd@0: CPT(1,1,:) = [1 0]; wolffd@0: CPT(2,1,:) = [0 1]; wolffd@0: CPT(1,2,:) = [0 1]; wolffd@0: CPT(2,2,:) = [0 1]; wolffd@0: bnet.CPD{C} = tabular_CPD(bnet, C, 'CPT', CPT); wolffd@0: wolffd@0: engine = jtree_inf_engine(bnet); wolffd@0: ev = cell(1,3); wolffd@0: ev{C} = 2; wolffd@0: engine = enter_evidence(engine, ev); wolffd@0: m = marginal_nodes(engine, B); wolffd@0: fprintf('P(B=true|C=true) = %5.3f\n', m.T(2)) % 0.67 wolffd@0: wolffd@0: ev{S} = 2; wolffd@0: engine = enter_evidence(engine, ev); wolffd@0: m = marginal_nodes(engine, B); wolffd@0: fprintf('P(B=true|C=true,S=true) = %5.3f\n', m.T(2)) % 0.5 = unconditional baseline P(B=true)