comparison toolboxes/FullBNT-1.0.7/bnt/learning/score_dags.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function score = score_dags(data, ns, dags, varargin)
2 % SCORE_DAGS Compute the score of one or more DAGs
3 % score = score_dags(data, ns, dags, varargin)
4 %
5 % data{i,m} = value of node i in case m (can be a cell array).
6 % node_sizes(i) is the number of size of node i.
7 % dags{g} is the g'th dag
8 % score(g) is the score of the i'th dag
9 %
10 % The following optional arguments can be specified in the form of name/value pairs:
11 % [default value in brackets]
12 %
13 % scoring_fn - 'bayesian' or 'bic' [ 'bayesian' ]
14 % Currently, only networks with all tabular nodes support Bayesian scoring.
15 % type - type{i} is the type of CPD to use for node i, where the type is a string
16 % of the form 'tabular', 'noisy_or', 'gaussian', etc. [ all cells contain 'tabular' ]
17 % params - params{i} contains optional arguments passed to the CPD constructor for node i,
18 % or [] if none. [ all cells contain {'prior', 1}, meaning use uniform Dirichlet priors ]
19 % discrete - the list of discrete nodes [ 1:N ]
20 % clamped - clamped(i,m) = 1 if node i is clamped in case m [ zeros(N, ncases) ]
21 %
22 % e.g., score = score_dags(data, ns, mk_all_dags(n), 'scoring_fn', 'bic', 'params', []);
23 %
24 % If the DAGs have a lot of families in common, we can cache the sufficient statistics,
25 % making this potentially more efficient than scoring the DAGs one at a time.
26 % (Caching is not currently implemented, however.)
27
28 [n ncases] = size(data);
29
30 % set default params
31 type = cell(1,n);
32 params = cell(1,n);
33 for i=1:n
34 type{i} = 'tabular';
35 params{i} = { 'prior_type', 'dirichlet', 'dirichlet_weight', 1 };
36 end
37 scoring_fn = 'bayesian';
38 discrete = 1:n;
39
40 u = [1:ncases]'; % DWH
41 isclamped = 0; %DWH
42 clamped = zeros(n, ncases);
43
44 args = varargin;
45 nargs = length(args);
46 for i=1:2:nargs
47 switch args{i},
48 case 'scoring_fn', scoring_fn = args{i+1};
49 case 'type', type = args{i+1};
50 case 'discrete', discrete = args{i+1};
51 case 'clamped', clamped = args{i+1}, isclamped = 1; %DWH
52 case 'params', if isempty(args{i+1}), params = cell(1,n); else params = args{i+1}; end
53 end
54 end
55
56 NG = length(dags);
57 score = zeros(1, NG);
58 for g=1:NG
59 dag = dags{g};
60 for j=1:n
61 if isclamped %DWH
62 u = find(clamped(j,:)==0);
63 end
64 ps = parents(dag, j);
65 score(g) = score(g) + score_family(j, ps, type{j}, scoring_fn, ns, discrete, data(:,u), params{j});
66 end
67 end