Changeset 429 for applications
- Timestamp:
- 07/27/09 13:12:23 (15 years ago)
- Location:
- applications/bdmtoolbox
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/merger.cpp
r411 r429 118 118 119 119 // save results 120 Array<vec> source_vals(Sources.length()); 121 for (int i=0;i<Sources.length();i++){ 122 datalink_m2e dl; 123 dl.set_connection(Sources(i)->_rv(), Sources(i)->_rvc(), Merger->_rv()); 124 125 vec ll(Merger->_Smp()._samples().length()); 126 for(int j=0; j<Merger->_Smp()._samples().length(); j++){ 127 vec dt=dl.pushdown(Merger->_Smp()._samples()(j)); 128 vec dtc=dl.get_cond(Merger->_Smp()._samples()(j)); 129 ll(j)=Sources(i)->evallogcond(dt,dtc); 130 } 131 132 vec sll = exp(ll); 133 134 source_vals(i)=sll/sum(sll); 135 } 136 137 vec ll(Merger->_Smp()._samples().length()); 138 for(int j=0; j<Merger->_Smp()._samples().length(); j++){ 139 ll(j)=Merger->evallog(Merger->_Smp()._samples()(j)); 140 } 141 142 vec sll = exp(ll); 143 144 vec mix_val=sll/sum(sll); 145 120 146 121 147 #ifdef MEX … … 137 163 vec2mxArray(w,fldw); 138 164 mxReplaceFieldNM(tmp, "weights", fldw); 165 166 //mixture values 167 mxArray* fldm=mxCreateDoubleMatrix(1, w.length(), mxREAL); 168 vec2mxArray(mix_val,fldm); 169 mxReplaceFieldNM(tmp, "mix", fldm); 139 170 140 171 // sources … … 142 173 for (int i=0;i<Sources.length();i++){ 143 174 sprintf(srcstr,"source%d",i+1); 144 vec sll=exp(Sources(i)->evallogcond_m(Merger->_Smp()._samples(),vec(0))); 145 146 mxArray* fldw=mxCreateDoubleMatrix(1, sll.length(), mxREAL); 147 vec2mxArray(sll/sum(sll),fldw); 175 mxArray* fldw=mxCreateDoubleMatrix(1, source_vals(i).length(), mxREAL); 176 vec2mxArray(source_vals(i),fldw); 148 177 mxReplaceFieldNM(tmp, srcstr, fldw); 149 178 } -
applications/bdmtoolbox/tutorial/merging/merge_frag.m
r411 r429 6 6 % Sources 7 7 f1.class= 'enorm<ldmat>'; 8 f1.mu = 3;8 f1.mu = 5; 9 9 f1.R = 1; 10 10 f1.rv = b; … … 13 13 Merger.class='merger_mix'; 14 14 Merger.method='lognormal'; 15 Merger.beta= 2;15 Merger.beta=1.2; 16 16 Merger.ncoms=20; 17 Merger.stop_niter=5 ;17 Merger.stop_niter=50; 18 18 Merger.effss_coef=1; 19 19 %Merger.dbg_file='merger_mix_dbg'; … … 23 23 f3 = struct('class','enorm<ldmat>',... 24 24 'mu',[1,2],... 25 'R', [ 2 0; 0 1.5],...25 'R', [1 -0.5; -0.5 1],... 26 26 'rv', ab); 27 f4 = struct('class','egiw',... 28 'V',4*[5 2; 2 1],... 29 'nu', 4,... 30 'dimx', 1,... 31 'rv', ab); 27 f4 = struct('class','mlnorm<ldmat>',... 28 'rv',a,... 29 'rvc', b,... 30 'A', 1,... 31 'const', 0,... 32 'R',1); 32 33 % 2D support 33 support2.grid={[-5,5],[0.001, 5]};34 support2.nbins=[ 20,20];34 support2.grid={[-5,5],[0.001,9]}; 35 support2.nbins=[30,30]; 35 36 36 37 % 2D 37 vy2=merger({f3,f1}, support2, Merger) 38 X=zeros(support2.nbins(1)); 39 Y=zeros(support2.nbins(1)); 40 Z=zeros(support2.nbins(1)); 38 %vy2=merger({f3,f1}, support2, Merger) 39 vy2=merger({f3,f4}, support2, Merger) 41 40 42 41 figure(2); 43 subplot(1,3,1); 42 subplot(2,2,1); 43 contour_2(vy2.support(1,:),vy2.support(2,:),vy2.source1) 44 % set(gca,'XLim',[-5,5]) 45 % set(gca,'YLim',[-1,7]) 46 title('Source 1') 47 subplot(2,2,2); 48 contour_2(vy2.support(1,:),vy2.support(2,:),vy2.source2') 49 % set(gca,'XLim',[-5,5]) 50 % set(gca,'YLim',[-1,7]) 51 title('Source 2') 52 53 subplot(2,2,3); 54 hold off 55 contour_2(vy2.support(1,:),vy2.support(2,:),vy2.mix) 56 % set(gca,'XLim',[-5,5]) 57 % set(gca,'YLim',[-1,7]) 58 title('Mixture Approximation') 59 60 subplot(2,2,4); 44 61 hold off 45 62 plot(vy2.support(1,:),vy2.support(2,:),'.','MarkerSize',4) 46 63 hold on 47 64 contour_2(vy2.support(1,:),vy2.support(2,:),vy2.weights) 48 subplot(1,3,2); 49 contour_2(vy2.support(1,:),vy2.support(2,:),vy2.source1)50 subplot(1,3,3); 51 contour_2(vy2.support(1,:),vy2.support(2,:),vy2.source2) 65 % set(gca,'XLim',[-5,5]) 66 % set(gca,'YLim',[-1,7]) 67 title('Weighted Empirical') 68