Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@pearl_dbn_inf_engine/pearl_dbn_inf_engine.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 engine = pearl_dbn_inf_engine(bnet, varargin) | |
2 % LOOPY_DBN_INF_ENGINE Loopy Pearl version of forwards-backwards | |
3 % engine = loopy_dbn_inf_engine(bnet, ...) | |
4 % | |
5 % Optional arguments | |
6 % 'max_iter' - specifies the max num. forward-backward passes to perform [1] | |
7 % 'tol' - as in loopy_pearl [1e-3] | |
8 % 'momentum' - as in loopy_pearl [0] | |
9 | |
10 error('pearl_dbn does not work yet') | |
11 | |
12 max_iter = 1; | |
13 tol = 1e-3; | |
14 momentum = 0; | |
15 | |
16 if nargin >= 2 | |
17 args = varargin; | |
18 nargs = length(args); | |
19 for i=1:2:nargs | |
20 switch args{i}, | |
21 case 'max_iter', max_iter = args{i+1}; | |
22 case 'tol', tol = args{i+1}; | |
23 case 'momentum', momentum = args{i+1}; | |
24 end | |
25 end | |
26 end | |
27 | |
28 | |
29 engine.max_iter = max_iter; | |
30 engine.tol = tol; | |
31 engine.momentum = momentum; | |
32 engine.pearl_engine = []; | |
33 engine.T = []; | |
34 engine.ss = length(bnet.intra); | |
35 | |
36 engine.marginal = []; | |
37 engine.evidence = []; | |
38 engine.msg = []; | |
39 engine.parent_index = []; | |
40 engine.child_index = []; | |
41 %[engine.parent_index, engine.child_index] = mk_pearl_msg_indices(bnet); % need to unroll first | |
42 | |
43 ss = length(bnet.intra); | |
44 engines.ss = ss; | |
45 onodes = bnet.observed; | |
46 hnodes = mysetdiff(1:ss, onodes); | |
47 obschild = zeros(1,ss); | |
48 for i=hnodes(:)' | |
49 %ocs = myintersect(children(bnet.dag, i), onodes); | |
50 ocs = children(bnet.intra, i); | |
51 assert(length(ocs) <= 1); | |
52 if length(ocs)==1 | |
53 obschild(i) = ocs(1); | |
54 end | |
55 end | |
56 engine.obschild = obschild; | |
57 | |
58 engine.mult_self_ndx = []; | |
59 engine.mult_parent_ndx = []; | |
60 engine.marg_self_ndx = []; | |
61 engine.marg_parent_ndx = []; | |
62 | |
63 | |
64 engine = class(engine, 'loopy_dbn_inf_engine', inf_engine(bnet)); | |
65 |