annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@root_CPD/root_CPD.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function CPD = root_CPD(bnet, self, val)
wolffd@0 2 % ROOT_CPD Make a conditional prob. distrib. which has no parameters.
wolffd@0 3 % CPD = ROOT_CPD(BNET, NODE_NUM, VAL)
wolffd@0 4 %
wolffd@0 5 % The node must not have any parents and is assumed to always be observed.
wolffd@0 6 % It is a way of modelling exogenous inputs to a model.
wolffd@0 7 % VAL is the value to which the root is clamped (default: [])
wolffd@0 8
wolffd@0 9
wolffd@0 10 if nargin==0
wolffd@0 11 % This occurs if we are trying to load an object from a file.
wolffd@0 12 CPD = init_fields;
wolffd@0 13 CPD = class(CPD, 'root_CPD', generic_CPD(1));
wolffd@0 14 return;
wolffd@0 15 elseif isa(bnet, 'root_CPD')
wolffd@0 16 % This might occur if we are copying an object.
wolffd@0 17 CPD = bnet;
wolffd@0 18 return;
wolffd@0 19 end
wolffd@0 20 CPD = init_fields;
wolffd@0 21
wolffd@0 22
wolffd@0 23 if nargin < 3, val = []; end
wolffd@0 24
wolffd@0 25 ns = bnet.node_sizes;
wolffd@0 26 ps = parents(bnet.dag, self);
wolffd@0 27 if ~isempty(ps)
wolffd@0 28 error('root CPDs should have no parents')
wolffd@0 29 end
wolffd@0 30
wolffd@0 31 CPD.self = self;
wolffd@0 32 CPD.val = val;
wolffd@0 33 CPD.sizes = ns(self);
wolffd@0 34
wolffd@0 35 clamped = 1;
wolffd@0 36 CPD = class(CPD, 'root_CPD', generic_CPD(clamped));
wolffd@0 37
wolffd@0 38
wolffd@0 39 %%%%%%%%%%%
wolffd@0 40
wolffd@0 41 function CPD = init_fields()
wolffd@0 42 % This ensures we define the fields in the same order
wolffd@0 43 % no matter whether we load an object from a file,
wolffd@0 44 % or create it from scratch. (Matlab requires this.)
wolffd@0 45
wolffd@0 46 CPD.self = [];
wolffd@0 47 CPD.val = [];
wolffd@0 48 CPD.sizes = [];