comparison toolboxes/FullBNT-1.0.7/bnt/general/mk_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 bnet = mk_limid(dag, node_sizes, varargin)
2 % MK_LIMID Make a limited information influence diagram
3 %
4 % BNET = MK_LIMID(DAG, NODE_SIZES, ...)
5 % DAG is the adjacency matrix for a directed acyclic graph.
6 % The nodes are assumed to be in topological order. Use TOPOLOGICAL_SORT if necessary.
7 % For decision nodes, the parents must explicitely include all nodes
8 % on which it can depends, in contrast to the implicit no-forgetting assumption of influence diagrams.
9 % (For details, see "Representing and solving decision problems with limited information",
10 % Lauritzen and Nilsson, Management Science, 2001.)
11 %
12 % node_sizes(i) is the number of values node i can take on,
13 % or the length of node i if i is a continuous-valued vector.
14 % node_sizes(i) = 1 if i is a utility node.
15 %
16 % The list below gives optional arguments [default value in brackets].
17 %
18 % chance - the list of nodes which are random variables [1:N]
19 % decision - the list of nodes which are decision nodes [ [] ]
20 % utility - the list of nodes which are utility nodes [ [] ]
21 % equiv_class - equiv_class(i)=j means node i gets its params from CPD{j} [1:N]
22 %
23 % e.g., limid = mk_limid(dag, ns, 'chance', [1 3], 'utility', [2])
24
25 n = length(dag);
26
27 % default values for parameters
28 bnet.chance_nodes = 1:n;
29 bnet.equiv_class = 1:n;
30 bnet.utility_nodes = [];
31 bnet.decision_nodes = [];
32 bnet.dnodes = 1:n; % discrete
33
34 if nargin >= 3
35 args = varargin;
36 nargs = length(args);
37 if ~isstr(args{1})
38 if nargs >= 1, bnet.dnodes = args{1}; end
39 if nargs >= 2, bnet.equiv_class = args{2}; end
40 else
41 for i=1:2:nargs
42 switch args{i},
43 case 'equiv_class', bnet.equiv_class = args{i+1};
44 case 'chance', bnet.chance_nodes = args{i+1};
45 case 'utility', bnet.utility_nodes = args{i+1};
46 case 'decision', bnet.decision_nodes = args{i+1};
47 case 'discrete', bnet.dnodes = args{i+1};
48 otherwise,
49 error(['invalid argument name ' args{i}]);
50 end
51 end
52 end
53 end
54
55 bnet.limid = 1;
56
57 bnet.dag = dag;
58 bnet.node_sizes = node_sizes(:)';
59
60 bnet.cnodes = mysetdiff(1:n, bnet.dnodes);
61 % too many functions refer to cnodes to rename it to cts_nodes -
62 % We hope it won't be confused with chance nodes!
63
64 bnet.parents = cell(1,n);
65 for i=1:n
66 bnet.parents{i} = parents(dag, i);
67 end
68
69 E = max(bnet.equiv_class);
70 mem = cell(1,E);
71 for i=1:n
72 e = bnet.equiv_class(i);
73 mem{e} = [mem{e} i];
74 end
75 bnet.members_of_equiv_class = mem;
76
77 bnet.CPD = cell(1, E);
78
79 % for e=1:E
80 % i = bnet.members_of_equiv_class{e}(1); % pick arbitrary member
81 % switch type{e}
82 % case 'tabular', bnet.CPD{e} = tabular_CPD(bnet, i);
83 % case 'gaussian', bnet.CPD{e} = gaussian_CPD(bnet, i);
84 % otherwise, error(['unrecognized CPD type ' type{e}]);
85 % end
86 % end
87
88 directed = 1;
89 if ~acyclic(dag,directed)
90 error('graph must be acyclic')
91 end
92
93 bnet.order = topological_sort(bnet.dag);