Revision 1013, 1.2 kB
(checked in by smidl, 15 years ago)
|
Flatten has an extra argument
|
Rev | Line | |
---|
[934] | 1 | clear all |
---|
| 2 | |
---|
[735] | 3 | com.class='ARX'; |
---|
[1005] | 4 | com.yrv = RV({'d'},[2],[0]); |
---|
[735] | 5 | com.rgr = RV({},[],[]); |
---|
| 6 | |
---|
[1013] | 7 | Data = [randn(2,50) randn(2,50)+10*ones(2,50)]; |
---|
[735] | 8 | |
---|
[1005] | 9 | [Mix0,P0]=mixef_init(Data,com); |
---|
| 10 | % show predictor |
---|
| 11 | |
---|
| 12 | Pred = bm_epredictor(Mix0); |
---|
[1013] | 13 | figure(1); |
---|
| 14 | hold off |
---|
| 15 | plot(Data(1,:), Data(2,:),'.'); |
---|
| 16 | hold on |
---|
[1005] | 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)); |
---|
[1013] | 34 | w = w/sum(w) |
---|
[1005] | 35 | |
---|
| 36 | for c=1:n |
---|
| 37 | yt = Data(:,t); |
---|
[1013] | 38 | [MixQB.Coms{c}]=bm_bayesweighted(MixQB.Coms{c}, yt, [], w(c)); |
---|
[1005] | 39 | end |
---|
[1013] | 40 | MixQB.weights = bm_bayes(MixQB.weights, w); |
---|
[1005] | 41 | end |
---|
| 42 | toc |
---|
| 43 | |
---|
| 44 | tic |
---|
| 45 | % should be the same as: |
---|
[1013] | 46 | MixQBc = bm_bayes_batch(MixQB,Data); |
---|
[1005] | 47 | toc |
---|
| 48 | |
---|
| 49 | %% display results |
---|
| 50 | |
---|
[1013] | 51 | PredQB = bm_epredictor(MixQB); |
---|
[1005] | 52 | figure(2); |
---|
[1013] | 53 | hold off |
---|
| 54 | plot(Data(1,:), Data(2,:),'.'); |
---|
| 55 | hold on |
---|
| 56 | epdf_2dplot(PredQB); |
---|
[1005] | 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 |
---|
[1013] | 65 | figure(3) |
---|
[1005] | 66 | imagesc(Batta_dist); |
---|