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