wolffd@0: function CPT = noisyORtoTable(inhibit, leak_inhibit) wolffd@0: % NOISYORTOTABLE Convert noisyOR distribution to CPT wolffd@0: % function CPT = noisyORtoTable(inhibit, leak_inhibit) wolffd@0: % wolffd@0: % inhibit(i) = prob i'th parent will be inhibited (flipped from 1 to 0) wolffd@0: % leak_inhibit - optional suppression of leak wolffd@0: % CPT(U1,...,Un, X) = Pr(X|U1,...,Un) where the Us are the parents (excluding leak). wolffd@0: % State 1 = off, 2 = on wolffd@0: wolffd@0: if nargin < 2, leak_inhibit = 1; end wolffd@0: wolffd@0: q = [leak_inhibit inhibit(:)']; wolffd@0: wolffd@0: if length(q)==1 wolffd@0: CPT = [q 1-q]; wolffd@0: return; wolffd@0: end wolffd@0: wolffd@0: n = length(q); wolffd@0: Bn = ind2subv(2*ones(1,n), 1:(2^n))-1; % all n bit vectors, with the left most column toggling fastest (LSB) wolffd@0: CPT = zeros(2^n, 2); wolffd@0: % 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)) wolffd@0: % This method is problematic when q contains zeros wolffd@0: wolffd@0: Q = repmat(q(:)', 2^n, 1); wolffd@0: Q(logical(~Bn)) = 1; wolffd@0: CPT(:,1) = prod(Q,2); wolffd@0: CPT(:,2) = 1-CPT(:,1); wolffd@0: wolffd@0: CPT = reshape(CPT(2:2:end), 2*ones(1,n)); % skip cases in which the leak is off wolffd@0: wolffd@0: