To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / general / noisyORtoTable.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1013 Bytes)
| 1 |
function CPT = noisyORtoTable(inhibit, leak_inhibit) |
|---|---|
| 2 |
% NOISYORTOTABLE Convert noisyOR distribution to CPT |
| 3 |
% function CPT = noisyORtoTable(inhibit, leak_inhibit) |
| 4 |
% |
| 5 |
% inhibit(i) = prob i'th parent will be inhibited (flipped from 1 to 0) |
| 6 |
% leak_inhibit - optional suppression of leak |
| 7 |
% CPT(U1,...,Un, X) = Pr(X|U1,...,Un) where the Us are the parents (excluding leak). |
| 8 |
% State 1 = off, 2 = on |
| 9 |
|
| 10 |
if nargin < 2, leak_inhibit = 1; end |
| 11 |
|
| 12 |
q = [leak_inhibit inhibit(:)']; |
| 13 |
|
| 14 |
if length(q)==1 |
| 15 |
CPT = [q 1-q]; |
| 16 |
return; |
| 17 |
end |
| 18 |
|
| 19 |
n = length(q); |
| 20 |
Bn = ind2subv(2*ones(1,n), 1:(2^n))-1; % all n bit vectors, with the left most column toggling fastest (LSB) |
| 21 |
CPT = zeros(2^n, 2); |
| 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))
|
| 23 |
% This method is problematic when q contains zeros |
| 24 |
|
| 25 |
Q = repmat(q(:)', 2^n, 1); |
| 26 |
Q(logical(~Bn)) = 1; |
| 27 |
CPT(:,1) = prod(Q,2); |
| 28 |
CPT(:,2) = 1-CPT(:,1); |
| 29 |
|
| 30 |
CPT = reshape(CPT(2:2:end), 2*ones(1,n)); % skip cases in which the leak is off |
| 31 |
|
| 32 |
|