annotate _FullBNT/BNT/learning/bayes_update_params.m @ 9:4ea6619cb3f5 tip

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