comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/mixexp3.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 % Fit a piece-wise linear regression model.
2 % Here is the model
3 %
4 % X \
5 % | |
6 % Q |
7 % | /
8 % Y
9 %
10 % where all arcs point down.
11 % We condition everything on X, so X is a root node. Q is a softmax, and Y is a linear Gaussian.
12 % Q is hidden, X and Y are observed.
13
14 X = 1;
15 Q = 2;
16 Y = 3;
17 dag = zeros(3,3);
18 dag(X,[Q Y]) = 1;
19 dag(Q,Y) = 1;
20 ns = [1 2 1]; % make X and Y scalars, and have 2 experts
21 dnodes = [2];
22 onodes = [1 3];
23 bnet = mk_bnet(dag, ns, 'discrete', dnodes, 'observed', onodes);
24
25 IRLS_iter = 10;
26 clamped = 0;
27
28 bnet.CPD{1} = root_CPD(bnet, 1);
29
30 % start with good initial params
31 w = [-5 5]; % w(:,i) is the normal vector to the i'th decisions boundary
32 b = [0 0]; % b(i) is the offset (bias) to the i'th decisions boundary
33
34 mu = [0 0];
35 sigma = 1;
36 Sigma = repmat(sigma*eye(ns(Y)), [ns(Y) ns(Y) ns(Q)]);
37 W = [-1 1];
38 W2 = reshape(W, [ns(Y) ns(X) ns(Q)]);
39
40 bnet.CPD{2} = softmax_CPD(bnet, 2, w, b, clamped, IRLS_iter);
41 bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', mu, 'cov', Sigma, 'weights', W2);
42
43
44 engine = jtree_inf_engine(bnet);
45
46 evidence = cell(1,3);
47 evidence{X} = 0.68;
48
49 engine = enter_evidence(engine, evidence);
50
51 m = marginal_nodes(engine, Y);
52 m.mu