To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _FullBNT / BNT / CPDs / @root_CPD / root_CPD.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.12 KB)

1
function CPD = root_CPD(bnet, self, val)
2
% ROOT_CPD Make a conditional prob. distrib. which has no parameters.
3
% CPD = ROOT_CPD(BNET, NODE_NUM, VAL)
4
%
5
% The node must not have any parents and is assumed to always be observed.
6
% It is a way of modelling exogenous inputs to a model.
7
% VAL is the value to which the root is clamped (default: [])
8

    
9

    
10
if nargin==0
11
  % This occurs if we are trying to load an object from a file.
12
  CPD = init_fields;
13
  CPD = class(CPD, 'root_CPD', generic_CPD(1));
14
  return;
15
elseif isa(bnet, 'root_CPD')
16
  % This might occur if we are copying an object.
17
  CPD = bnet;
18
  return;
19
end
20
CPD = init_fields;
21

    
22

    
23
if nargin < 3, val = []; end
24

    
25
ns = bnet.node_sizes;
26
ps = parents(bnet.dag, self);
27
if ~isempty(ps)
28
  error('root CPDs should have no parents')
29
end
30

    
31
CPD.self = self;
32
CPD.val = val;
33
CPD.sizes = ns(self);
34

    
35
clamped = 1;
36
CPD = class(CPD, 'root_CPD', generic_CPD(clamped));
37

    
38

    
39
%%%%%%%%%%%
40

    
41
function CPD = init_fields()
42
% This ensures we define the fields in the same order 
43
% no matter whether we load an object from a file,
44
% or create it from scratch. (Matlab requires this.)
45

    
46
CPD.self = [];
47
CPD.val = [];
48
CPD.sizes = [];