1 | clear all |
---|
2 | |
---|
3 | com.class='ARX'; |
---|
4 | com.yrv = RV({'d'},[2],[0]); |
---|
5 | com.rgr = RV({},[],[]); |
---|
6 | |
---|
7 | Data = [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 | |
---|
12 | Pred = bm_epredictor(Mix0); |
---|
13 | figure(1); |
---|
14 | hold off |
---|
15 | plot(Data(1,:), Data(2,:),'.'); |
---|
16 | hold on |
---|
17 | epdf_2dplot(Pred); |
---|
18 | hold on |
---|
19 | for i=1:length(Pred.pdfs) |
---|
20 | mea=epdf_mean(Pred.pdfs{i}); |
---|
21 | plot(mea(1),mea(2),'+r'); |
---|
22 | end |
---|
23 | |
---|
24 | % Do Quasi Bayes |
---|
25 | |
---|
26 | tic |
---|
27 | %use same or new data |
---|
28 | MixQB = Mix0; |
---|
29 | n = length(MixQB.Coms); |
---|
30 | for 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); |
---|
46 | end |
---|
47 | toc |
---|
48 | |
---|
49 | tic |
---|
50 | % should be the same as: |
---|
51 | MixQBc = bm_bayes_batch(MixQB,Data); |
---|
52 | toc |
---|
53 | |
---|
54 | %% display results |
---|
55 | |
---|
56 | PredQB = bm_epredictor(MixQB); |
---|
57 | figure(2); |
---|
58 | hold off |
---|
59 | plot(Data(1,:), Data(2,:),'.'); |
---|
60 | hold on |
---|
61 | epdf_2dplot(PredQB); |
---|
62 | |
---|
63 | PredQBc = bm_epredictor(MixQBc); |
---|
64 | figure(3); |
---|
65 | hold off |
---|
66 | plot(Data(1,:), Data(2,:),'.'); |
---|
67 | hold on |
---|
68 | epdf_2dplot(PredQBc); |
---|
69 | |
---|
70 | %% relations between components |
---|
71 | Batta_dist=zeros(n); |
---|
72 | for i=1:n |
---|
73 | for j=i:n |
---|
74 | Batta_dist(i,j) = enorm_bhattacharyya(PredQB.pdfs{i}, PredQB.pdfs{j}); |
---|
75 | end |
---|
76 | end |
---|
77 | figure(4) |
---|
78 | imagesc(Batta_dist); |
---|