|
Revision 1013, 1.2 kB
(checked in by smidl, 16 years ago)
|
|
Flatten has an extra argument
|
| Line | |
|---|
| 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)+10*ones(2,50)]; |
|---|
| 8 | |
|---|
| 9 | [Mix0,P0]=mixef_init(Data,com); |
|---|
| 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 | |
|---|
| 19 | % Do Quasi Bayes |
|---|
| 20 | |
|---|
| 21 | tic |
|---|
| 22 | %use same or new data |
|---|
| 23 | MixQB = Mix0; |
|---|
| 24 | n = length(MixQB.Coms); |
|---|
| 25 | for 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); |
|---|
| 41 | end |
|---|
| 42 | toc |
|---|
| 43 | |
|---|
| 44 | tic |
|---|
| 45 | % should be the same as: |
|---|
| 46 | MixQBc = bm_bayes_batch(MixQB,Data); |
|---|
| 47 | toc |
|---|
| 48 | |
|---|
| 49 | %% display results |
|---|
| 50 | |
|---|
| 51 | PredQB = bm_epredictor(MixQB); |
|---|
| 52 | figure(2); |
|---|
| 53 | hold off |
|---|
| 54 | plot(Data(1,:), Data(2,:),'.'); |
|---|
| 55 | hold on |
|---|
| 56 | epdf_2dplot(PredQB); |
|---|
| 57 | |
|---|
| 58 | %% relations between components |
|---|
| 59 | Batta_dist=zeros(n); |
|---|
| 60 | for i=1:n |
|---|
| 61 | for j=i:n |
|---|
| 62 | Batta_dist(i,j) = enorm_bhattacharyya(PredQB.pdfs{i}, PredQB.pdfs{j}); |
|---|
| 63 | end |
|---|
| 64 | end |
|---|
| 65 | figure(3) |
|---|
| 66 | imagesc(Batta_dist); |
|---|