root/applications/bdmtoolbox/tutorial/userguide/mixef_basic.m @ 1013

Revision 1013, 1.2 kB (checked in by smidl, 14 years ago)

Flatten has an extra argument

Line 
1clear all
2
3com.class='ARX';
4com.yrv = RV({'d'},[2],[0]);
5com.rgr = RV({},[],[]);
6
7Data = [randn(2,50) randn(2,50)+10*ones(2,50)];
8
9[Mix0,P0]=mixef_init(Data,com);
10% show predictor
11
12Pred = bm_epredictor(Mix0);
13figure(1);
14hold off
15plot(Data(1,:), Data(2,:),'.');
16hold on
17epdf_2dplot(Pred);
18
19% Do Quasi Bayes
20
21tic
22%use same or new data
23MixQB = Mix0;
24n = length(MixQB.Coms);
25for t=1:size(Data,2)
26    log_w_nn = zeros(1,n);
27    % get predictions
28    for c=1:n
29        yt = Data(:,t);
30        [dummy, log_w_nn(c)]=bm_bayes(MixQB.Coms{c}, yt);
31    end
32    % normalize weights
33    w = exp(log_w_nn-max(log_w_nn));
34    w = w/sum(w)
35   
36    for c=1:n
37        yt = Data(:,t);
38        [MixQB.Coms{c}]=bm_bayesweighted(MixQB.Coms{c}, yt, [], w(c));
39    end
40    MixQB.weights = bm_bayes(MixQB.weights, w);
41end
42toc
43
44tic
45% should be the same as:
46MixQBc = bm_bayes_batch(MixQB,Data);
47toc
48
49%% display results
50
51PredQB = bm_epredictor(MixQB);
52figure(2);
53hold off
54plot(Data(1,:), Data(2,:),'.');
55hold on
56epdf_2dplot(PredQB);
57
58%% relations between components
59Batta_dist=zeros(n);
60for i=1:n
61    for j=i:n
62        Batta_dist(i,j) = enorm_bhattacharyya(PredQB.pdfs{i}, PredQB.pdfs{j});
63    end
64end
65figure(3)
66imagesc(Batta_dist);
Note: See TracBrowser for help on using the browser.