Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@tabular_utility_node/tabular_utility_node.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 = tabular_utility_node(bnet, node, T) |
wolffd@0 | 2 % TABULAR_UTILITY_NODE Represent a utility function as a table |
wolffd@0 | 3 % CPD = tabular_utility_node(bnet, node, T) |
wolffd@0 | 4 % |
wolffd@0 | 5 % node is the number of a node in this equivalence class. |
wolffd@0 | 6 % T is an optional argument (same shape as the CPT in tabular_CPD, but missing the last (child) |
wolffd@0 | 7 % dimension). By default, entries in T are chosen u.a.r. from 0:1 (using 'rand'). |
wolffd@0 | 8 |
wolffd@0 | 9 if nargin==0 |
wolffd@0 | 10 % This occurs if we are trying to load an object from a file. |
wolffd@0 | 11 CPD = init_fields; |
wolffd@0 | 12 clamp = 0; |
wolffd@0 | 13 CPD = class(CPD, 'tabular_utility_node'); |
wolffd@0 | 14 return; |
wolffd@0 | 15 elseif isa(bnet, 'tabular_utility_node') |
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 ns = bnet.node_sizes; |
wolffd@0 | 24 ps = parents(bnet.dag, node); |
wolffd@0 | 25 sz = ns(ps); |
wolffd@0 | 26 |
wolffd@0 | 27 if nargin < 3 |
wolffd@0 | 28 T = myrand(sz); |
wolffd@0 | 29 else |
wolffd@0 | 30 T = myreshape(T, sz); |
wolffd@0 | 31 end |
wolffd@0 | 32 |
wolffd@0 | 33 CPD.T = T; |
wolffd@0 | 34 CPD.sizes = sz; |
wolffd@0 | 35 |
wolffd@0 | 36 CPD = class(CPD, 'tabular_utility_node'); |
wolffd@0 | 37 |
wolffd@0 | 38 %%%%%%%%%%% |
wolffd@0 | 39 |
wolffd@0 | 40 function CPD = init_fields() |
wolffd@0 | 41 % This ensures we define the fields in the same order |
wolffd@0 | 42 % no matter whether we load an object from a file, |
wolffd@0 | 43 % or create it from scratch. (Matlab requires this.) |
wolffd@0 | 44 |
wolffd@0 | 45 CPD.T = []; |
wolffd@0 | 46 CPD.sizes = []; |