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