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