annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@tree_CPD/set_fields.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 = set_fields(CPD, varargin)
wolffd@0 2 % SET_PARAMS Set the parameters (fields) for a tabular_CPD object
wolffd@0 3 % CPD = set_params(CPD, name/value pairs)
wolffd@0 4 %
wolffd@0 5 % The following optional arguments can be specified in the form of name/value pairs:
wolffd@0 6 %
wolffd@0 7 % CPT - the CPT
wolffd@0 8 % prior - the prior
wolffd@0 9 % clamped - 1 means don't adjust during EM
wolffd@0 10 %
wolffd@0 11 % e.g., CPD = set_params(CPD, 'CPT', 'rnd')
wolffd@0 12
wolffd@0 13 args = varargin;
wolffd@0 14 nargs = length(args);
wolffd@0 15 for i=1:2:nargs
wolffd@0 16 switch args{i},
wolffd@0 17 case 'CPT',
wolffd@0 18 if ischar(args{i+1})
wolffd@0 19 switch args{i+1}
wolffd@0 20 case 'unif', CPD.CPT = mk_stochastic(myones(CPD.sizes));
wolffd@0 21 case 'rnd', CPD.CPT = mk_stochastic(myrand(CPD.sizes));
wolffd@0 22 otherwise, error(['invalid type ' args{i+1}]);
wolffd@0 23 end
wolffd@0 24 elseif isscalarBNT(args{i+1})
wolffd@0 25 p = args{i+1};
wolffd@0 26 k = CPD.sizes(end);
wolffd@0 27 % Bug fix by Hervé BOUTROUILLE 10/1/01
wolffd@0 28 CPD.CPT = myreshape(sample_dirichlet(p*ones(1,k), prod(CPD.sizes(1:end-1)), CPD.sizes));
wolffd@0 29 %CPD.CPT = myreshape(sample_dirichlet(p*ones(1,k), prod(CPD.sizes(1:end-1))), CPD.sizes);
wolffd@0 30 else
wolffd@0 31 CPD.CPT = myreshape(args{i+1}, CPD.sizes);
wolffd@0 32 end
wolffd@0 33
wolffd@0 34 case 'prior',
wolffd@0 35 if ischar(args{i+1}) & strcmp(args{i+1}, 'unif')
wolffd@0 36 CPD.prior = myones(CPD.sizes);
wolffd@0 37 elseif isscalarBNT(args{i+1})
wolffd@0 38 CPD.prior = args{i+1} * normalise(myones(CPD.sizes));
wolffd@0 39 else
wolffd@0 40 CPD.prior = myreshape(args{i+1}, CPD.sizes);
wolffd@0 41 end
wolffd@0 42
wolffd@0 43 %case 'clamped', CPD.clamped = strcmp(args{i+1}, 'yes');
wolffd@0 44 %case 'clamped', CPD = set_clamped(CPD, strcmp(args{i+1}, 'yes'));
wolffd@0 45 case 'clamped', CPD = set_clamped(CPD, args{i+1});
wolffd@0 46
wolffd@0 47 otherwise,
wolffd@0 48 %error(['invalid argument name ' args{i}]);
wolffd@0 49 end
wolffd@0 50 end
wolffd@0 51
wolffd@0 52