annotate toolboxes/FullBNT-1.0.7/bnt/learning/bayes_update_params.m @ 0:cc4b1211e677 tip

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