Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/learning/bayes_update_params.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 bnet = bayes_update_params(bnet, cases, clamped) | |
2 % BAYES_UPDATE_PARAMS Bayesian parameter updating given completely observed data | |
3 % bnet = bayes_update_params(bnet, cases, clamped) | |
4 % | |
5 % If there is a missing data, you must use EM. | |
6 % cases(i,m) is the value assigned to node i in case m (this can also be a cell array). | |
7 % clamped(i,m) = 1 if node i was set by intervention in case m (default: clamped = zeros). | |
8 % Clamped nodes are not updated. | |
9 % If there is a single case, clamped is a list of the clamped nodes, not a bit vector. | |
10 | |
11 | |
12 %if iscell(cases), usecell = 1; else usecell = 0; end | |
13 | |
14 n = length(bnet.dag); | |
15 ncases = size(cases, 2); | |
16 if n ~= size(cases, 1) | |
17 error('data must be of size nnodes * ncases'); | |
18 end | |
19 | |
20 if ncases == 1 % clamped is a list of nodes | |
21 if nargin < 3, clamped = []; end | |
22 clamp_set = clamped; | |
23 clamped = zeros(n,1); | |
24 clamped(clamp_set) = 1; | |
25 else % each row of clamped is a bit vector | |
26 if nargin < 3, clamped = zeros(n,ncases); end | |
27 end | |
28 | |
29 for i=1:n | |
30 e = bnet.equiv_class(i); | |
31 if adjustable_CPD(bnet.CPD{e}) | |
32 u = find(clamped(i,:)==0); | |
33 ps = parents(bnet.dag, i); | |
34 bnet.CPD{e} = bayes_update_params(bnet.CPD{e}, cases(i,u), cases(ps,u)); | |
35 end | |
36 end | |
37 | |
38 |