Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/limids/id1.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 % influence diagram with no loops | |
2 % | |
3 % rv dec | |
4 % \ / | |
5 % utility | |
6 | |
7 N = 3; | |
8 dag = zeros(N); | |
9 X = 1; D = 2; U = 3; | |
10 dag([X D], U)=1; | |
11 | |
12 ns = zeros(1,N); | |
13 ns(X) = 2; ns(D) = 2; ns(U) = 1; | |
14 | |
15 limid = mk_limid(dag, ns, 'chance', X, 'decision', D, 'utility', U); | |
16 | |
17 % use random params | |
18 limid.CPD{X} = tabular_CPD(limid, X); | |
19 limid.CPD{D} = tabular_decision_node(limid, D); | |
20 limid.CPD{U} = tabular_utility_node(limid, U); | |
21 | |
22 %fname = '/home/cs/murphyk/matlab/Misc/loopybel.txt'; | |
23 global BNT_HOME | |
24 fname = sprintf('%s/loopybel.txt', BNT_HOME); | |
25 | |
26 engines = {}; | |
27 engines{end+1} = global_joint_inf_engine(limid); | |
28 engines{end+1} = jtree_limid_inf_engine(limid); | |
29 %engines{end+1} = belprop_inf_engine(limid, 'max_iter', 2*N, 'filename', fname); | |
30 engines{end+1} = belprop_inf_engine(limid, 'max_iter', 2*N); | |
31 | |
32 exact = [1 2]; | |
33 approx = 3; | |
34 | |
35 E = length(engines); | |
36 strategy = cell(1, E); | |
37 MEU = zeros(1, E); | |
38 for e=1:E | |
39 [strategy{e}, MEU(e)] = solve_limid(engines{e}); | |
40 MEU | |
41 end | |
42 MEU | |
43 | |
44 for e=exact(:)' | |
45 assert(approxeq(strategy{exact(1)}{D}, strategy{e}{D})) | |
46 end | |
47 | |
48 for e=approx(:)' | |
49 approxeq(strategy{exact(1)}{D}, strategy{e}{D}) | |
50 end |