Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@gibbs_sampling_inf_engine/private/get_slice_dbn.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 slice = get_slice_dbn(bnet, state, i, n, j, m, strides, families, ... | |
2 CPT) | |
3 % slice = get_slice(bnet, state, i, n, j, m, strides, families, cpt) | |
4 % | |
5 % GET_SLICE get one-dimensional slice of the CPT for node X_i^n | |
6 % that corresponds to the different values of X_j^m, where all | |
7 % other nodes have values given by state. | |
8 % strides is the result of | |
9 % calling compute_strides(bnet) | |
10 % families is the result of calling compute_families(bnet) | |
11 % cpts is the result of calling get_cpts(bnet) | |
12 % | |
13 % slice is a 1-d array | |
14 | |
15 | |
16 if (n == 1) | |
17 | |
18 k = bnet.eclass1(i); | |
19 c = CPT{k}; | |
20 | |
21 % Figure out evidence on family | |
22 fam = families{i, 1}; | |
23 ev = state(fam, 1); | |
24 | |
25 % Remove evidence on node j | |
26 pos = find(fam == j); | |
27 ev(pos) = 1; | |
28 dim = size(ev, 1); | |
29 | |
30 % Compute initial index and stride | |
31 start_ind = 1+strides(k, 1:dim)*(ev-1); | |
32 stride = strides(k, pos); | |
33 | |
34 % Compute the slice | |
35 slice = c(start_ind:stride:start_ind+(bnet.node_sizes(j, 1)-1)*stride); | |
36 | |
37 else | |
38 | |
39 k = bnet.eclass2(i); | |
40 c = CPT{k}; | |
41 | |
42 fam = families{i, 2}; | |
43 ss = length(bnet.intra); | |
44 | |
45 % Divide the family into nodes in this time step and nodes in the | |
46 % previous time step | |
47 this_time_step = fam(find(fam > ss)); | |
48 prev_time_step = fam(find(fam <= ss)); | |
49 | |
50 % Normalize the node numbers | |
51 this_time_step = this_time_step - ss; | |
52 | |
53 % Get the evidence | |
54 this_step_ev = state(this_time_step, n); | |
55 prev_step_ev = state(prev_time_step, n-1); | |
56 | |
57 % Remove the evidence for X_j^m | |
58 if (m == n) | |
59 pos = find(this_time_step == j); | |
60 this_step_ev(pos) = 1; | |
61 pos = pos + size(prev_time_step, 2); | |
62 else | |
63 assert (m == n-1); | |
64 pos = find(prev_time_step == j); | |
65 prev_step_ev(pos) = 1; | |
66 end | |
67 | |
68 % Combine the two time steps | |
69 ev = [prev_step_ev; this_step_ev]; | |
70 dim = size(ev, 1); | |
71 | |
72 | |
73 % Compute starting index and stride | |
74 start_ind = 1 + strides(k, 1:dim)*(ev-1); | |
75 stride = strides(k, pos); | |
76 | |
77 % Compute slice | |
78 if (m == 1) | |
79 q = 1; | |
80 else | |
81 q = 2; | |
82 end | |
83 slice = c(start_ind:stride:start_ind+(bnet.node_sizes(j, q)-1)*stride); | |
84 end | |
85 | |
86 | |
87 |