Daniel@0: function CPD = root_CPD(bnet, self, val) Daniel@0: % ROOT_CPD Make a conditional prob. distrib. which has no parameters. Daniel@0: % CPD = ROOT_CPD(BNET, NODE_NUM, VAL) Daniel@0: % Daniel@0: % The node must not have any parents and is assumed to always be observed. Daniel@0: % It is a way of modelling exogenous inputs to a model. Daniel@0: % VAL is the value to which the root is clamped (default: []) Daniel@0: Daniel@0: Daniel@0: if nargin==0 Daniel@0: % This occurs if we are trying to load an object from a file. Daniel@0: CPD = init_fields; Daniel@0: CPD = class(CPD, 'root_CPD', generic_CPD(1)); Daniel@0: return; Daniel@0: elseif isa(bnet, 'root_CPD') Daniel@0: % This might occur if we are copying an object. Daniel@0: CPD = bnet; Daniel@0: return; Daniel@0: end Daniel@0: CPD = init_fields; Daniel@0: Daniel@0: Daniel@0: if nargin < 3, val = []; end Daniel@0: Daniel@0: ns = bnet.node_sizes; Daniel@0: ps = parents(bnet.dag, self); Daniel@0: if ~isempty(ps) Daniel@0: error('root CPDs should have no parents') Daniel@0: end Daniel@0: Daniel@0: CPD.self = self; Daniel@0: CPD.val = val; Daniel@0: CPD.sizes = ns(self); Daniel@0: Daniel@0: clamped = 1; Daniel@0: CPD = class(CPD, 'root_CPD', generic_CPD(clamped)); Daniel@0: Daniel@0: Daniel@0: %%%%%%%%%%% Daniel@0: Daniel@0: function CPD = init_fields() Daniel@0: % This ensures we define the fields in the same order Daniel@0: % no matter whether we load an object from a file, Daniel@0: % or create it from scratch. (Matlab requires this.) Daniel@0: Daniel@0: CPD.self = []; Daniel@0: CPD.val = []; Daniel@0: CPD.sizes = [];