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

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