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