annotate toolboxes/FullBNT-1.0.7/bnt/general/noisyORtoTable.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 CPT = noisyORtoTable(inhibit, leak_inhibit)
Daniel@0 2 % NOISYORTOTABLE Convert noisyOR distribution to CPT
Daniel@0 3 % function CPT = noisyORtoTable(inhibit, leak_inhibit)
Daniel@0 4 %
Daniel@0 5 % inhibit(i) = prob i'th parent will be inhibited (flipped from 1 to 0)
Daniel@0 6 % leak_inhibit - optional suppression of leak
Daniel@0 7 % CPT(U1,...,Un, X) = Pr(X|U1,...,Un) where the Us are the parents (excluding leak).
Daniel@0 8 % State 1 = off, 2 = on
Daniel@0 9
Daniel@0 10 if nargin < 2, leak_inhibit = 1; end
Daniel@0 11
Daniel@0 12 q = [leak_inhibit inhibit(:)'];
Daniel@0 13
Daniel@0 14 if length(q)==1
Daniel@0 15 CPT = [q 1-q];
Daniel@0 16 return;
Daniel@0 17 end
Daniel@0 18
Daniel@0 19 n = length(q);
Daniel@0 20 Bn = ind2subv(2*ones(1,n), 1:(2^n))-1; % all n bit vectors, with the left most column toggling fastest (LSB)
Daniel@0 21 CPT = zeros(2^n, 2);
Daniel@0 22 % Pr(X=0 | U_1 .. U_n) = prod_{i: U_i = on} q_i = prod_i q_i ^ U_i = exp(u' * log(q_i))
Daniel@0 23 % This method is problematic when q contains zeros
Daniel@0 24
Daniel@0 25 Q = repmat(q(:)', 2^n, 1);
Daniel@0 26 Q(logical(~Bn)) = 1;
Daniel@0 27 CPT(:,1) = prod(Q,2);
Daniel@0 28 CPT(:,2) = 1-CPT(:,1);
Daniel@0 29
Daniel@0 30 CPT = reshape(CPT(2:2:end), 2*ones(1,n)); % skip cases in which the leak is off
Daniel@0 31
Daniel@0 32