7 | | UIFile Cfg("merger_mx.cfg"); |
8 | | |
| 15 | // Check the number of inputs and output arguments |
| 16 | if(n_input!=3) mexErrMsgTxt("Usage:\n" |
| 17 | "result=merger(sources, support, merger)\n" |
| 18 | " sources= { struct('class','epdf'),... }; % cell of pdfs (epdfs or mpdfs) to be merged,\n" |
| 19 | " support= struct(\n" |
| 20 | " grid = {[dim1_start,dim1_end], [dim2_start, dim2_end]...} %support boundary \n" |
| 21 | " nbins = [bins_in_dim1, bins_in_dim2,...] %fixed \n" |
| 22 | " === OR ==\n" |
| 23 | " pdf = struct('class','epdf'); % pdf to draw samples from\n" |
| 24 | " nsamples= 100; % number of samples\n" |
| 25 | " );\n" |
| 26 | " If all elements are present, (grid,nbins) is used;\n" |
| 27 | " merger = struct('class','merger_*'); % object to be used for merging,\n\n" |
| 28 | "see documentation of classes epdf, mpdf, merger_base and their offsprings in BDM."); |
| 29 | |
| 30 | // LOAD CONFIG |
| 31 | UImxArray Cfg; |
| 32 | Cfg.addList(input[0],"Sources"); |
| 33 | Cfg.addGroup(input[1],"Support"); |
| 34 | Cfg.addGroup(input[2],"Merger"); |
| 35 | |
| 36 | //DBG |
| 37 | Cfg.writeFile("merger.cfg"); |
| 38 | #else |
| 39 | int main() |
| 40 | { |
| 41 | UIFile Cfg("merger.cfg"); |
| 42 | #endif |
| 101 | // save results |
| 102 | |
| 103 | #ifdef MEX |
| 104 | mxArray* tmp ; |
| 105 | // Save results |
| 106 | if (n_output>0){ |
| 107 | tmp = mxCreateStructMatrix(1,1,0,NULL); |
| 108 | //support |
| 109 | Array<vec> &samples=Merger->_Smp()._samples(); |
| 110 | if (samples.size()>0){ |
| 111 | mxArray* fld=mxCreateDoubleMatrix(samples(0).length(), samples.size(), mxREAL); |
| 112 | Arrayvec2mxArray(samples,fld); |
| 113 | mxReplaceFieldNM(tmp, "support", fld); |
| 114 | } |
| 115 | |
| 116 | //weights |
| 117 | vec &w = Merger->_Smp()._w(); |
| 118 | mxArray* fldw=mxCreateDoubleMatrix(1, w.length(), mxREAL); |
| 119 | vec2mxArray(w,fldw); |
| 120 | mxReplaceFieldNM(tmp, "weights", fldw); |
| 121 | |
| 122 | // sources |
| 123 | char srcstr[20]; |
| 124 | for (int i=0;i<Sources.length();i++){ |
| 125 | sprintf(srcstr,"source%d",i+1); |
| 126 | vec sll=exp(Sources(i)->evallogcond_m(Merger->_Smp()._samples(),vec(0))); |
| 127 | |
| 128 | mxArray* fldw=mxCreateDoubleMatrix(1, sll.length(), mxREAL); |
| 129 | vec2mxArray(sll/sum(sll),fldw); |
| 130 | mxReplaceFieldNM(tmp, srcstr, fldw); |
| 131 | } |
| 132 | |
| 133 | output[0] = tmp; |
| 134 | } |
| 135 | #endif |