Daniel@0: function bnet = mk_limid(dag, node_sizes, varargin) Daniel@0: % MK_LIMID Make a limited information influence diagram Daniel@0: % Daniel@0: % BNET = MK_LIMID(DAG, NODE_SIZES, ...) Daniel@0: % DAG is the adjacency matrix for a directed acyclic graph. Daniel@0: % The nodes are assumed to be in topological order. Use TOPOLOGICAL_SORT if necessary. Daniel@0: % For decision nodes, the parents must explicitely include all nodes Daniel@0: % on which it can depends, in contrast to the implicit no-forgetting assumption of influence diagrams. Daniel@0: % (For details, see "Representing and solving decision problems with limited information", Daniel@0: % Lauritzen and Nilsson, Management Science, 2001.) Daniel@0: % Daniel@0: % node_sizes(i) is the number of values node i can take on, Daniel@0: % or the length of node i if i is a continuous-valued vector. Daniel@0: % node_sizes(i) = 1 if i is a utility node. Daniel@0: % Daniel@0: % The list below gives optional arguments [default value in brackets]. Daniel@0: % Daniel@0: % chance - the list of nodes which are random variables [1:N] Daniel@0: % decision - the list of nodes which are decision nodes [ [] ] Daniel@0: % utility - the list of nodes which are utility nodes [ [] ] Daniel@0: % equiv_class - equiv_class(i)=j means node i gets its params from CPD{j} [1:N] Daniel@0: % Daniel@0: % e.g., limid = mk_limid(dag, ns, 'chance', [1 3], 'utility', [2]) Daniel@0: Daniel@0: n = length(dag); Daniel@0: Daniel@0: % default values for parameters Daniel@0: bnet.chance_nodes = 1:n; Daniel@0: bnet.equiv_class = 1:n; Daniel@0: bnet.utility_nodes = []; Daniel@0: bnet.decision_nodes = []; Daniel@0: bnet.dnodes = 1:n; % discrete Daniel@0: Daniel@0: if nargin >= 3 Daniel@0: args = varargin; Daniel@0: nargs = length(args); Daniel@0: if ~isstr(args{1}) Daniel@0: if nargs >= 1, bnet.dnodes = args{1}; end Daniel@0: if nargs >= 2, bnet.equiv_class = args{2}; end Daniel@0: else Daniel@0: for i=1:2:nargs Daniel@0: switch args{i}, Daniel@0: case 'equiv_class', bnet.equiv_class = args{i+1}; Daniel@0: case 'chance', bnet.chance_nodes = args{i+1}; Daniel@0: case 'utility', bnet.utility_nodes = args{i+1}; Daniel@0: case 'decision', bnet.decision_nodes = args{i+1}; Daniel@0: case 'discrete', bnet.dnodes = args{i+1}; Daniel@0: otherwise, Daniel@0: error(['invalid argument name ' args{i}]); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: bnet.limid = 1; Daniel@0: Daniel@0: bnet.dag = dag; Daniel@0: bnet.node_sizes = node_sizes(:)'; Daniel@0: Daniel@0: bnet.cnodes = mysetdiff(1:n, bnet.dnodes); Daniel@0: % too many functions refer to cnodes to rename it to cts_nodes - Daniel@0: % We hope it won't be confused with chance nodes! Daniel@0: Daniel@0: bnet.parents = cell(1,n); Daniel@0: for i=1:n Daniel@0: bnet.parents{i} = parents(dag, i); Daniel@0: end Daniel@0: Daniel@0: E = max(bnet.equiv_class); Daniel@0: mem = cell(1,E); Daniel@0: for i=1:n Daniel@0: e = bnet.equiv_class(i); Daniel@0: mem{e} = [mem{e} i]; Daniel@0: end Daniel@0: bnet.members_of_equiv_class = mem; Daniel@0: Daniel@0: bnet.CPD = cell(1, E); Daniel@0: Daniel@0: % for e=1:E Daniel@0: % i = bnet.members_of_equiv_class{e}(1); % pick arbitrary member Daniel@0: % switch type{e} Daniel@0: % case 'tabular', bnet.CPD{e} = tabular_CPD(bnet, i); Daniel@0: % case 'gaussian', bnet.CPD{e} = gaussian_CPD(bnet, i); Daniel@0: % otherwise, error(['unrecognized CPD type ' type{e}]); Daniel@0: % end Daniel@0: % end Daniel@0: Daniel@0: directed = 1; Daniel@0: if ~acyclic(dag,directed) Daniel@0: error('graph must be acyclic') Daniel@0: end Daniel@0: Daniel@0: bnet.order = topological_sort(bnet.dag);