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