annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/reveal1.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 % Make a DBN with the following inter-connectivity matrix
Daniel@0 2 % 1
Daniel@0 3 % / \
Daniel@0 4 % 2 3
Daniel@0 5 % \ /
Daniel@0 6 % 4
Daniel@0 7 % |
Daniel@0 8 % 5
Daniel@0 9 % where all arcs point down. In addition, there are persistence arcs from each node to itself.
Daniel@0 10 % There are no intra-slice connections.
Daniel@0 11 % Nodes have noisy-or CPDs.
Daniel@0 12 % Node 1 turns on spontaneously due to its leaky source.
Daniel@0 13 % This effect trickles down to the other nodes in the order shown.
Daniel@0 14 % All the other nodes inhibit their leaks.
Daniel@0 15 % None of the nodes inhibit the connection from themselves, so that once they are on, they remain
Daniel@0 16 % on (persistence).
Daniel@0 17 %
Daniel@0 18 % This model was used in the experiments reported in
Daniel@0 19 % - "Learning the structure of DBNs", Friedman, Murphy and Russell, UAI 1998.
Daniel@0 20 % where the structure was learned even in the presence of missing data.
Daniel@0 21 % In that paper, we used the structural EM algorithm.
Daniel@0 22 % Here, we assume full observability and tabular CPDs for the learner, so we can use a much
Daniel@0 23 % simpler learning algorithm.
Daniel@0 24
Daniel@0 25 ss = 5;
Daniel@0 26
Daniel@0 27 inter = eye(ss);
Daniel@0 28 inter(1,[2 3]) = 1;
Daniel@0 29 inter(2,4)=1;
Daniel@0 30 inter(3,4)=1;
Daniel@0 31 inter(4,5)=1;
Daniel@0 32
Daniel@0 33 intra = zeros(ss);
Daniel@0 34 ns = 2*ones(1,ss);
Daniel@0 35
Daniel@0 36 bnet = mk_dbn(intra, inter, ns);
Daniel@0 37
Daniel@0 38 % All nodes start out off
Daniel@0 39 for i=1:ss
Daniel@0 40 bnet.CPD{i} = tabular_CPD(bnet, i, [1.0 0.0]');
Daniel@0 41 end
Daniel@0 42
Daniel@0 43 % The following params correspond to Fig 4a in the UAI 98 paper
Daniel@0 44 % The first arg is the leak inhibition prob.
Daniel@0 45 % The vector contains the inhib probs from the parents in the previous slice;
Daniel@0 46 % the last element is self, which is never inhibited.
Daniel@0 47 bnet.CPD{1+ss} = noisyor_CPD(bnet, 1+ss, 0.8, 0);
Daniel@0 48 bnet.CPD{2+ss} = noisyor_CPD(bnet, 2+ss, 1, [0.9 0]);
Daniel@0 49 bnet.CPD{3+ss} = noisyor_CPD(bnet, 3+ss, 1, [0.8 0]);
Daniel@0 50 bnet.CPD{4+ss} = noisyor_CPD(bnet, 4+ss, 1, [0.7 0.6 0]);
Daniel@0 51 bnet.CPD{5+ss} = noisyor_CPD(bnet, 5+ss, 1, [0.5 0]);
Daniel@0 52
Daniel@0 53
Daniel@0 54 % Generate some training data
Daniel@0 55
Daniel@0 56 nseqs = 20;
Daniel@0 57 seqs = cell(1,nseqs);
Daniel@0 58 T = 30;
Daniel@0 59 for i=1:nseqs
Daniel@0 60 seqs{i} = sample_dbn(bnet, T);
Daniel@0 61 end
Daniel@0 62
Daniel@0 63 max_fan_in = 3; % let's cheat a little here
Daniel@0 64
Daniel@0 65 % computing num. incorrect edges as a fn of the size of the training set
Daniel@0 66 %sz = [5 10 15 20];
Daniel@0 67 sz = [5 10];
Daniel@0 68 h = zeros(1, length(sz));
Daniel@0 69 for i=1:length(sz)
Daniel@0 70 inter2 = learn_struct_dbn_reveal(seqs(1:sz(i)), ns, max_fan_in);
Daniel@0 71 h(i) = sum(abs(inter(:)-inter2(:))); % hamming distance
Daniel@0 72 end
Daniel@0 73 h