comparison toolboxes/FullBNT-1.0.7/bnt/general/solve_limid.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 function [strategy, MEU, niter] = solve_limid(engine, varargin)
2 % SOLVE_LIMID Find the (locally) optimal strategy for a LIMID
3 % [strategy, MEU, niter] = solve_limid(inf_engine, ...)
4 %
5 % strategy{d} = stochastic policy for node d (a decision node)
6 % MEU = maximum expected utility
7 % niter = num iterations used
8 %
9 % The following optional arguments can be specified in the form of name/value pairs:
10 % [default in brackets]
11 %
12 % max_iter - max. num. iterations [ 1 ]
13 % tol - tolerance required of consecutive MEU values, used to assess convergence [1e-3]
14 % order - order in which decision nodes are optimized [ reverse numerical order ]
15 %
16 % e.g., solve_limid(engine, 'tol', 1e-2, 'max_iter', 10)
17
18 bnet = bnet_from_engine(engine);
19
20 % default values
21 max_iter = 1;
22 tol = 1e-3;
23 D = bnet.decision_nodes;
24 order = D(end:-1:1);
25
26 args = varargin;
27 nargs = length(args);
28 for i=1:2:nargs
29 switch args{i},
30 case 'max_iter', max_iter = args{i+1};
31 case 'tol', tol = args{i+1};
32 case 'order', order = args{i+1};
33 otherwise,
34 error(['invalid argument name ' args{i}]);
35 end
36 end
37
38 CPDs = bnet.CPD;
39 ns = bnet.node_sizes;
40 N = length(ns);
41 evidence = cell(1,N);
42 strategy = cell(1, N);
43
44 iter = 1;
45 converged = 0;
46 oldMEU = 0;
47 while ~converged & (iter <= max_iter)
48 for d=order(:)'
49 engine = enter_evidence(engine, evidence, 'exclude', d);
50 [m, pot] = marginal_family(engine, d);
51 %pot = marginal_family_pot(engine, d);
52 [policy, score] = upot_to_opt_policy(pot);
53 e = bnet.equiv_class(d);
54 CPDs{e} = set_fields(CPDs{e}, 'policy', policy);
55 engine = update_engine(engine, CPDs);
56 strategy{d} = policy;
57 end
58 engine = enter_evidence(engine, evidence);
59 [m, pot] = marginal_nodes(engine, []);
60 %pot = marginal_family_pot(engine, []);
61 [dummy, MEU] = upot_to_opt_policy(pot);
62 if approxeq(MEU, oldMEU, tol)
63 converged = 1;
64 end
65 oldMEU = MEU;
66 iter = iter + 1;
67 end
68 niter = iter - 1;