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, prior, clamped, counts
|
wolffd@0
|
8 %
|
wolffd@0
|
9 % e.g., CPD = set_params(CPD, 'CPT', 'rnd')
|
wolffd@0
|
10
|
wolffd@0
|
11 args = varargin;
|
wolffd@0
|
12 nargs = length(args);
|
wolffd@0
|
13 for i=1:2:nargs
|
wolffd@0
|
14 switch args{i},
|
wolffd@0
|
15 case 'CPT',
|
wolffd@0
|
16 if ischar(args{i+1})
|
wolffd@0
|
17 switch args{i+1}
|
wolffd@0
|
18 case 'unif', CPD.CPT = mk_stochastic(myones(CPD.sizes));
|
wolffd@0
|
19 case 'rnd', CPD.CPT = mk_stochastic(myrand(CPD.sizes));
|
wolffd@0
|
20 otherwise, error(['invalid type ' args{i+1}]);
|
wolffd@0
|
21 end
|
wolffd@0
|
22 elseif isscalarBNT(args{i+1})
|
wolffd@0
|
23 p = args{i+1};
|
wolffd@0
|
24 k = CPD.sizes(end);
|
wolffd@0
|
25 % Bug fix by Hervé Boutrouille 10/1/01
|
wolffd@0
|
26 CPD.CPT = myreshape(sample_dirichlet(p*ones(1,k), prod(CPD.sizes(1:end-1)), CPD.sizes));
|
wolffd@0
|
27 %CPD.CPT = myreshape(sample_dirichlet(p*ones(1,k), prod(CPD.sizes(1:end-1))), CPD.sizes);
|
wolffd@0
|
28 else
|
wolffd@0
|
29 CPD.CPT = myreshape(args{i+1}, CPD.sizes);
|
wolffd@0
|
30 end
|
wolffd@0
|
31
|
wolffd@0
|
32 case 'prior',
|
wolffd@0
|
33 if ischar(args{i+1}) & strcmp(args{i+1}, 'unif')
|
wolffd@0
|
34 CPD.prior = myones(CPD.sizes);
|
wolffd@0
|
35 elseif isscalarBNT(args{i+1})
|
wolffd@0
|
36 CPD.prior = args{i+1} * normalise(myones(CPD.sizes));
|
wolffd@0
|
37 else
|
wolffd@0
|
38 CPD.prior = myreshape(args{i+1}, CPD.sizes);
|
wolffd@0
|
39 end
|
wolffd@0
|
40
|
wolffd@0
|
41 %case 'clamped', CPD.clamped = strcmp(args{i+1}, 'yes');
|
wolffd@0
|
42 %case 'clamped', CPD = set_clamped(CPD, strcmp(args{i+1}, 'yes'));
|
wolffd@0
|
43 case 'clamped', CPD = set_clamped(CPD, args{i+1});
|
wolffd@0
|
44
|
wolffd@0
|
45 case 'counts', CPD.counts = 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
|