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

Revision 1016, 1.4 kB (checked in by smidl, 14 years ago)

Mixtures details

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