wolffd@0
|
1 function CPD = noisyor_CPD(bnet, self, leak_inhibit, inhibit)
|
wolffd@0
|
2 % NOISYOR_CPD Make a noisy-or CPD
|
wolffd@0
|
3 % CPD = NOISYOR_CPD(BNET, NODE_NUM, LEAK_INHIBIT, INHIBIT)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % A noisy-or node turns on if any of its parents are on, provided they are not inhibited.
|
wolffd@0
|
6 % The prob. that the i'th parent gets inhibited (flipped from 1 to 0) is inhibit(i).
|
wolffd@0
|
7 % The prob that the leak node (a dummy parent that is always on) gets inhibit is leak_inhibit.
|
wolffd@0
|
8 % These params default to random values if omitted.
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % Example: suppose C has parents A and B, and the
|
wolffd@0
|
11 % link of A->C fails with prob pA and the link B->C fails with pB.
|
wolffd@0
|
12 % Then the noisy-OR gate defines the following distribution
|
wolffd@0
|
13 %
|
wolffd@0
|
14 % A B P(C=0)
|
wolffd@0
|
15 % 0 0 1.0
|
wolffd@0
|
16 % 1 0 pA
|
wolffd@0
|
17 % 0 1 pB
|
wolffd@0
|
18 % 1 1 pA * PB
|
wolffd@0
|
19 %
|
wolffd@0
|
20 % Currently, learning is not supported for noisy-or nodes
|
wolffd@0
|
21 % (since the M step is somewhat complicated).
|
wolffd@0
|
22 %
|
wolffd@0
|
23 % For simple generalizations of the noisy-OR model, see e.g.,
|
wolffd@0
|
24 % - Srinivas, "A generalization of the noisy-OR model", UAI 93
|
wolffd@0
|
25 % - Meek and Heckerman, "Learning Causal interaction models", UAI 97.
|
wolffd@0
|
26
|
wolffd@0
|
27
|
wolffd@0
|
28
|
wolffd@0
|
29 if nargin==0
|
wolffd@0
|
30 % This occurs if we are trying to load an object from a file.
|
wolffd@0
|
31 CPD = init_fields;
|
wolffd@0
|
32 CPD = class(CPD, 'noisyor_CPD', discrete_CPD(1, []));
|
wolffd@0
|
33 return;
|
wolffd@0
|
34 elseif isa(bnet, 'noisyor_CPD')
|
wolffd@0
|
35 % This might occur if we are copying an object.
|
wolffd@0
|
36 CPD = bnet;
|
wolffd@0
|
37 return;
|
wolffd@0
|
38 end
|
wolffd@0
|
39 CPD = init_fields;
|
wolffd@0
|
40
|
wolffd@0
|
41
|
wolffd@0
|
42 ps = parents(bnet.dag, self);
|
wolffd@0
|
43 fam = [ps self];
|
wolffd@0
|
44 ns = bnet.node_sizes;
|
wolffd@0
|
45 assert(all(ns(fam)==2));
|
wolffd@0
|
46 assert(isempty(myintersect(fam, bnet.cnodes)));
|
wolffd@0
|
47
|
wolffd@0
|
48 if nargin < 3, leak_inhibit = rand(1, 1); end
|
wolffd@0
|
49 if nargin < 4, inhibit = rand(1, length(ps)); end
|
wolffd@0
|
50
|
wolffd@0
|
51 CPD.self = self;
|
wolffd@0
|
52 CPD.inhibit = inhibit;
|
wolffd@0
|
53 CPD.leak_inhibit = leak_inhibit;
|
wolffd@0
|
54
|
wolffd@0
|
55
|
wolffd@0
|
56 % For BIC
|
wolffd@0
|
57 CPD.nparams = 0;
|
wolffd@0
|
58 CPD.nsamples = 0;
|
wolffd@0
|
59
|
wolffd@0
|
60 CPD.CPT = []; % cached copy, to speed up CPD_to_CPT
|
wolffd@0
|
61
|
wolffd@0
|
62 clamped = 1;
|
wolffd@0
|
63 CPD = class(CPD, 'noisyor_CPD', discrete_CPD(clamped, ns([ps self])));
|
wolffd@0
|
64
|
wolffd@0
|
65
|
wolffd@0
|
66
|
wolffd@0
|
67 %%%%%%%%%%%
|
wolffd@0
|
68
|
wolffd@0
|
69 function CPD = init_fields()
|
wolffd@0
|
70 % This ensures we define the fields in the same order
|
wolffd@0
|
71 % no matter whether we load an object from a file,
|
wolffd@0
|
72 % or create it from scratch. (Matlab requires this.)
|
wolffd@0
|
73
|
wolffd@0
|
74 CPD.self = [];
|
wolffd@0
|
75 CPD.inhibit = [];
|
wolffd@0
|
76 CPD.leak_inhibit = [];
|
wolffd@0
|
77 CPD.nparams = [];
|
wolffd@0
|
78 CPD.nsamples = [];
|
wolffd@0
|
79 CPD.CPT = [];
|