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