88 | | <a name="l00062"></a><a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14">00062</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a>; |
89 | | <a name="l00063"></a>00063 |
90 | | <a name="l00065"></a><a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e">00065</a> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>; |
91 | | <a name="l00066"></a>00066 |
92 | | <a name="l00068"></a><a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7">00068</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a>; |
93 | | <a name="l00069"></a>00069 |
94 | | <a name="l00071"></a><a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b">00071</a> it_file* <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
95 | | <a name="l00072"></a>00072 <span class="keyword">public</span>: |
96 | | <a name="l00075"></a>00075 |
97 | | <a name="l00077"></a><a class="code" href="classbdm_1_1merger__base.html#f9d8c6c26c6520dbb17d4e80f635e7be">00077</a> <a class="code" href="classbdm_1_1merger__base.html#f9d8c6c26c6520dbb17d4e80f635e7be" title="Empty constructor.">merger_base</a> () : <a class="code" href="classbdm_1_1compositepdf.html" title="Chain rule of pdfs - abstract part common for mprod and merger. this abstract class...">compositepdf</a>() {<a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a> = <span class="keyword">false</span>;<a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a> = NULL;}; |
98 | | <a name="l00079"></a><a class="code" href="classbdm_1_1merger__base.html#9c81a9624506da8e557c56d1af845de0">00079</a> <a class="code" href="classbdm_1_1merger__base.html#9c81a9624506da8e557c56d1af845de0" title="Constructor from sources.">merger_base</a> (<span class="keyword">const</span> Array<mpdf*> &S, <span class="keywordtype">bool</span> own=<span class="keyword">false</span>) {<a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d" title="Function setting the main internal structures.">set_sources</a> (S,own);}; |
99 | | <a name="l00081"></a><a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d">00081</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d" title="Function setting the main internal structures.">set_sources</a> (<span class="keyword">const</span> Array<mpdf*> &Sources, <span class="keywordtype">bool</span> own) { |
100 | | <a name="l00082"></a>00082 compositepdf::set_elements (Sources,own); |
101 | | <a name="l00083"></a>00083 <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a>=<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); |
102 | | <a name="l00084"></a>00084 <span class="comment">//set sizes</span> |
103 | | <a name="l00085"></a>00085 <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a>.set_size (Sources.length()); |
104 | | <a name="l00086"></a>00086 <a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a>.set_size (Sources.length()); |
105 | | <a name="l00087"></a>00087 <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a>.set_size (Sources.length()); |
106 | | <a name="l00088"></a>00088 |
107 | | <a name="l00089"></a>00089 <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> = <a class="code" href="classbdm_1_1compositepdf.html#c73d39acc4378eee6a63155c3517d3c9" title="find common rv, flag">getrv</a> (<span class="comment">/* checkoverlap = */</span> <span class="keyword">false</span>); |
108 | | <a name="l00090"></a>00090 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvc; <a class="code" href="classbdm_1_1compositepdf.html#c71fc2c51f49d797e61f479f543c75ce" title="common rvc of all mpdfs is written to rvc">setrvc</a> (<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>, rvc); <span class="comment">// Extend rv by rvc!</span> |
109 | | <a name="l00091"></a>00091 <span class="comment">// join rv and rvc - see descriprion</span> |
110 | | <a name="l00092"></a>00092 <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#87841b5ee43997b79789c0c22047e224" title="Add (concat) another variable to the current one,.">add</a> (rvc); |
111 | | <a name="l00093"></a>00093 <span class="comment">// get dimension</span> |
112 | | <a name="l00094"></a>00094 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(); |
113 | | <a name="l00095"></a>00095 |
114 | | <a name="l00096"></a>00096 <span class="comment">// create links between sources and common rv</span> |
115 | | <a name="l00097"></a>00097 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> xytmp; |
116 | | <a name="l00098"></a>00098 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length();i++) { |
117 | | <a name="l00099"></a>00099 <span class="comment">//Establich connection between mpdfs and merger</span> |
118 | | <a name="l00100"></a>00100 <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a> (i) = <span class="keyword">new</span> <a class="code" href="classbdm_1_1datalink__m2e.html" title="data link between">datalink_m2e</a>; |
119 | | <a name="l00101"></a>00101 <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a> (i)->set_connection (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)-><a class="code" href="classbdm_1_1epdf.html#a4ab378d5e004c3ff3e2d4e64f7bba21" title="Return name (fails when isnamed is false).">_rv</a>(), <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rvc(), <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
120 | | <a name="l00102"></a>00102 |
121 | | <a name="l00103"></a>00103 <span class="comment">// find out what is missing in each mpdf</span> |
122 | | <a name="l00104"></a>00104 xytmp = <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rv(); |
123 | | <a name="l00105"></a>00105 xytmp.<a class="code" href="classbdm_1_1RV.html#87841b5ee43997b79789c0c22047e224" title="Add (concat) another variable to the current one,.">add</a> (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rvc()); |
124 | | <a name="l00106"></a>00106 <span class="comment">// z_i = common_rv-xy</span> |
125 | | <a name="l00107"></a>00107 <a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a> (i) = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#aec44dabdf0a6d90fbae95e1356eda39" title="Subtract another variable from the current one.">subt</a> (xytmp); |
126 | | <a name="l00108"></a>00108 <span class="comment">//establish connection between extension (z_i|x,y)s and common rv</span> |
127 | | <a name="l00109"></a>00109 <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a> (i) = <span class="keyword">new</span> <a class="code" href="classbdm_1_1datalink__m2e.html" title="data link between">datalink_m2e</a>; <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a> (i)->set_connection (<a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a> (i), xytmp, <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>) ; |
128 | | <a name="l00110"></a>00110 }; |
129 | | <a name="l00111"></a>00111 } |
130 | | <a name="l00113"></a><a class="code" href="classbdm_1_1merger__base.html#337e1e56ef95d3d3ee922e8b81be95f8">00113</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#337e1e56ef95d3d3ee922e8b81be95f8" title="Rectangular support each vector of XYZ specifies (begining-end) interval for each...">set_support</a> (<span class="keyword">const</span> Array<vec> &XYZ, <span class="keyword">const</span> <span class="keywordtype">int</span> dimsize) { |
131 | | <a name="l00114"></a>00114 <a class="code" href="classbdm_1_1merger__base.html#337e1e56ef95d3d3ee922e8b81be95f8" title="Rectangular support each vector of XYZ specifies (begining-end) interval for each...">set_support</a>(XYZ,dimsize*ones_i(XYZ.length())); |
132 | | <a name="l00115"></a>00115 } |
133 | | <a name="l00117"></a><a class="code" href="classbdm_1_1merger__base.html#3e2c8028be0ccd10058d030250a91a60">00117</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#3e2c8028be0ccd10058d030250a91a60" title="Rectangular support each vector of XYZ specifies (begining-end) interval for each...">set_support</a> (<span class="keyword">const</span> Array<vec> &XYZ, <span class="keyword">const</span> ivec &gridsize) { |
134 | | <a name="l00118"></a>00118 <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = XYZ.length(); <span class="comment">//check with internal dim!!</span> |
135 | | <a name="l00119"></a>00119 <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a> = prod (gridsize); |
136 | | <a name="l00120"></a>00120 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> (<a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>, <span class="keyword">false</span>); |
137 | | <a name="l00121"></a>00121 Array<vec> &samples = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
138 | | <a name="l00122"></a>00122 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() = ones (<a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>) / <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; <span class="comment">//unifrom size of bins</span> |
139 | | <a name="l00123"></a>00123 <span class="comment">//set samples</span> |
140 | | <a name="l00124"></a>00124 ivec ind = zeros_i (dim); <span class="comment">//indeces of dimensions in for cycle;</span> |
141 | | <a name="l00125"></a>00125 vec smpi (dim); <span class="comment">// ith sample</span> |
142 | | <a name="l00126"></a>00126 vec steps =zeros(dim); <span class="comment">// ith sample</span> |
143 | | <a name="l00127"></a>00127 <span class="comment">// first corner</span> |
144 | | <a name="l00128"></a>00128 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < dim; j++) { |
145 | | <a name="l00129"></a>00129 smpi (j) = XYZ (j) (0); <span class="comment">/* beginning of the interval*/</span> |
146 | | <a name="l00130"></a>00130 it_assert(gridsize(j)!=0.0,<span class="stringliteral">"Zeros in gridsize!"</span>); |
147 | | <a name="l00131"></a>00131 steps (j) = ( XYZ(j)(1)-smpi(j) )/gridsize(j); |
148 | | <a name="l00132"></a>00132 } |
149 | | <a name="l00133"></a>00133 <span class="comment">// fill samples</span> |
150 | | <a name="l00134"></a>00134 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; i++) { |
151 | | <a name="l00135"></a>00135 <span class="comment">// copy </span> |
152 | | <a name="l00136"></a>00136 samples(i) = smpi; |
153 | | <a name="l00137"></a>00137 <span class="comment">// go through all dimensions</span> |
154 | | <a name="l00138"></a>00138 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0;j < dim;j++) { |
155 | | <a name="l00139"></a>00139 <span class="keywordflow">if</span> (ind (j) == gridsize (j) - 1) { <span class="comment">//j-th index is full</span> |
156 | | <a name="l00140"></a>00140 ind (j) = 0; <span class="comment">//shift back</span> |
157 | | <a name="l00141"></a>00141 smpi(j) = XYZ(j)(0); |
158 | | <a name="l00142"></a>00142 |
159 | | <a name="l00143"></a>00143 <span class="keywordflow">if</span> (i<Npoints-1) { |
160 | | <a name="l00144"></a>00144 ind (j + 1) ++; <span class="comment">//increase the next dimension;</span> |
161 | | <a name="l00145"></a>00145 smpi(j+1) += steps(j+1); |
162 | | <a name="l00146"></a>00146 <span class="keywordflow">break</span>; |
163 | | <a name="l00147"></a>00147 } |
164 | | <a name="l00148"></a>00148 |
165 | | <a name="l00149"></a>00149 } <span class="keywordflow">else</span> { |
166 | | <a name="l00150"></a>00150 ind (j) ++; |
167 | | <a name="l00151"></a>00151 smpi(j) +=steps(j); |
168 | | <a name="l00152"></a>00152 <span class="keywordflow">break</span>; |
169 | | <a name="l00153"></a>00153 } |
170 | | <a name="l00154"></a>00154 } |
171 | | <a name="l00155"></a>00155 } |
172 | | <a name="l00156"></a>00156 } |
173 | | <a name="l00158"></a><a class="code" href="classbdm_1_1merger__base.html#e4514484bac243585b0a1e44325e8add">00158</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#e4514484bac243585b0a1e44325e8add" title="set debug file">set_debug_file</a> (<span class="keyword">const</span> <span class="keywordtype">string</span> fname) { |
174 | | <a name="l00159"></a>00159 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a>) <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
175 | | <a name="l00160"></a>00160 <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a> = <span class="keyword">new</span> it_file (fname); |
176 | | <a name="l00161"></a>00161 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>) <a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a> = <span class="keyword">true</span>; |
177 | | <a name="l00162"></a>00162 } |
178 | | <a name="l00164"></a><a class="code" href="classbdm_1_1merger__base.html#e779dc28c822539be5131a46e6ec82aa">00164</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#e779dc28c822539be5131a46e6ec82aa" title="Set internal parameters used in approximation.">set_method</a> (MERGER_METHOD MTH, <span class="keywordtype">double</span> beta0 = 0.0) { |
179 | | <a name="l00165"></a>00165 <a class="code" href="classbdm_1_1merger__base.html#ee197330820127f3d12106ddee6b25c7" title="switch of the methoh used for merging">METHOD</a> = MTH; |
180 | | <a name="l00166"></a>00166 <a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a> = beta0; |
| 88 | <a name="l00062"></a><a class="code" href="classbdm_1_1merger__base.html#7acdf3aeded70475ba8a26450a4e197c">00062</a> <span class="keyword">static</span> <span class="keyword">const</span> MERGER_METHOD <a class="code" href="classbdm_1_1merger__base.html#7acdf3aeded70475ba8a26450a4e197c" title="Default for METHOD.">DFLT_METHOD</a>; |
| 89 | <a name="l00063"></a>00063 |
| 90 | <a name="l00065"></a><a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14">00065</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a>; |
| 91 | <a name="l00067"></a><a class="code" href="classbdm_1_1merger__base.html#dfe17e57529d84e122e61401543e9de6">00067</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1merger__base.html#dfe17e57529d84e122e61401543e9de6" title="default for beta">DFLT_beta</a>; |
| 92 | <a name="l00068"></a>00068 |
| 93 | <a name="l00070"></a><a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e">00070</a> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>; |
| 94 | <a name="l00071"></a>00071 |
| 95 | <a name="l00073"></a><a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7">00073</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a>; |
| 96 | <a name="l00074"></a>00074 |
| 97 | <a name="l00076"></a><a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b">00076</a> it_file* <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
| 98 | <a name="l00077"></a>00077 <span class="keyword">public</span>: |
| 99 | <a name="l00080"></a>00080 |
| 100 | <a name="l00082"></a><a class="code" href="classbdm_1_1merger__base.html#f9d8c6c26c6520dbb17d4e80f635e7be">00082</a> <a class="code" href="classbdm_1_1merger__base.html#f9d8c6c26c6520dbb17d4e80f635e7be" title="Empty constructor.">merger_base</a> () : <a class="code" href="classbdm_1_1compositepdf.html" title="Chain rule of pdfs - abstract part common for mprod and merger. this abstract class...">compositepdf</a>() {<a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a> = <span class="keyword">false</span>;<a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a> = NULL;}; |
| 101 | <a name="l00084"></a><a class="code" href="classbdm_1_1merger__base.html#9c81a9624506da8e557c56d1af845de0">00084</a> <a class="code" href="classbdm_1_1merger__base.html#9c81a9624506da8e557c56d1af845de0" title="Constructor from sources.">merger_base</a> (<span class="keyword">const</span> Array<mpdf*> &S, <span class="keywordtype">bool</span> own=<span class="keyword">false</span>) {<a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d" title="Function setting the main internal structures.">set_sources</a> (S,own);}; |
| 102 | <a name="l00086"></a><a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d">00086</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d" title="Function setting the main internal structures.">set_sources</a> (<span class="keyword">const</span> Array<mpdf*> &Sources, <span class="keywordtype">bool</span> own) { |
| 103 | <a name="l00087"></a>00087 compositepdf::set_elements (Sources,own); |
| 104 | <a name="l00088"></a>00088 <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a>=<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); |
| 105 | <a name="l00089"></a>00089 <span class="comment">//set sizes</span> |
| 106 | <a name="l00090"></a>00090 <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a>.set_size (Sources.length()); |
| 107 | <a name="l00091"></a>00091 <a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a>.set_size (Sources.length()); |
| 108 | <a name="l00092"></a>00092 <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a>.set_size (Sources.length()); |
| 109 | <a name="l00093"></a>00093 |
| 110 | <a name="l00094"></a>00094 <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> = <a class="code" href="classbdm_1_1compositepdf.html#c73d39acc4378eee6a63155c3517d3c9" title="find common rv, flag">getrv</a> (<span class="comment">/* checkoverlap = */</span> <span class="keyword">false</span>); |
| 111 | <a name="l00095"></a>00095 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvc; <a class="code" href="classbdm_1_1compositepdf.html#c71fc2c51f49d797e61f479f543c75ce" title="common rvc of all mpdfs is written to rvc">setrvc</a> (<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>, rvc); <span class="comment">// Extend rv by rvc!</span> |
| 112 | <a name="l00096"></a>00096 <span class="comment">// join rv and rvc - see descriprion</span> |
| 113 | <a name="l00097"></a>00097 <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#87841b5ee43997b79789c0c22047e224" title="Add (concat) another variable to the current one,.">add</a> (rvc); |
| 114 | <a name="l00098"></a>00098 <span class="comment">// get dimension</span> |
| 115 | <a name="l00099"></a>00099 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(); |
| 116 | <a name="l00100"></a>00100 |
| 117 | <a name="l00101"></a>00101 <span class="comment">// create links between sources and common rv</span> |
| 118 | <a name="l00102"></a>00102 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> xytmp; |
| 119 | <a name="l00103"></a>00103 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length();i++) { |
| 120 | <a name="l00104"></a>00104 <span class="comment">//Establich connection between mpdfs and merger</span> |
| 121 | <a name="l00105"></a>00105 <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a> (i) = <span class="keyword">new</span> <a class="code" href="classbdm_1_1datalink__m2e.html" title="data link between">datalink_m2e</a>; |
| 122 | <a name="l00106"></a>00106 <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a> (i)->set_connection (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)-><a class="code" href="classbdm_1_1epdf.html#a4ab378d5e004c3ff3e2d4e64f7bba21" title="Return name (fails when isnamed is false).">_rv</a>(), <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rvc(), <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
| 123 | <a name="l00107"></a>00107 |
| 124 | <a name="l00108"></a>00108 <span class="comment">// find out what is missing in each mpdf</span> |
| 125 | <a name="l00109"></a>00109 xytmp = <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rv(); |
| 126 | <a name="l00110"></a>00110 xytmp.<a class="code" href="classbdm_1_1RV.html#87841b5ee43997b79789c0c22047e224" title="Add (concat) another variable to the current one,.">add</a> (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rvc()); |
| 127 | <a name="l00111"></a>00111 <span class="comment">// z_i = common_rv-xy</span> |
| 128 | <a name="l00112"></a>00112 <a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a> (i) = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#aec44dabdf0a6d90fbae95e1356eda39" title="Subtract another variable from the current one.">subt</a> (xytmp); |
| 129 | <a name="l00113"></a>00113 <span class="comment">//establish connection between extension (z_i|x,y)s and common rv</span> |
| 130 | <a name="l00114"></a>00114 <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a> (i) = <span class="keyword">new</span> <a class="code" href="classbdm_1_1datalink__m2e.html" title="data link between">datalink_m2e</a>; <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a> (i)->set_connection (<a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a> (i), xytmp, <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>) ; |
| 131 | <a name="l00115"></a>00115 }; |
| 132 | <a name="l00116"></a>00116 } |
| 133 | <a name="l00118"></a><a class="code" href="classbdm_1_1merger__base.html#337e1e56ef95d3d3ee922e8b81be95f8">00118</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#337e1e56ef95d3d3ee922e8b81be95f8" title="Rectangular support each vector of XYZ specifies (begining-end) interval for each...">set_support</a> (<span class="keyword">const</span> Array<vec> &XYZ, <span class="keyword">const</span> <span class="keywordtype">int</span> dimsize) { |
| 134 | <a name="l00119"></a>00119 <a class="code" href="classbdm_1_1merger__base.html#337e1e56ef95d3d3ee922e8b81be95f8" title="Rectangular support each vector of XYZ specifies (begining-end) interval for each...">set_support</a>(XYZ,dimsize*ones_i(XYZ.length())); |
| 135 | <a name="l00120"></a>00120 } |
| 136 | <a name="l00122"></a><a class="code" href="classbdm_1_1merger__base.html#3e2c8028be0ccd10058d030250a91a60">00122</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#3e2c8028be0ccd10058d030250a91a60" title="Rectangular support each vector of XYZ specifies (begining-end) interval for each...">set_support</a> (<span class="keyword">const</span> Array<vec> &XYZ, <span class="keyword">const</span> ivec &gridsize) { |
| 137 | <a name="l00123"></a>00123 <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = XYZ.length(); <span class="comment">//check with internal dim!!</span> |
| 138 | <a name="l00124"></a>00124 <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a> = prod (gridsize); |
| 139 | <a name="l00125"></a>00125 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> (<a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>, <span class="keyword">false</span>); |
| 140 | <a name="l00126"></a>00126 Array<vec> &samples = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
| 141 | <a name="l00127"></a>00127 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() = ones (<a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>) / <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; <span class="comment">//unifrom size of bins</span> |
| 142 | <a name="l00128"></a>00128 <span class="comment">//set samples</span> |
| 143 | <a name="l00129"></a>00129 ivec ind = zeros_i (dim); <span class="comment">//indeces of dimensions in for cycle;</span> |
| 144 | <a name="l00130"></a>00130 vec smpi (dim); <span class="comment">// ith sample</span> |
| 145 | <a name="l00131"></a>00131 vec steps =zeros(dim); <span class="comment">// ith sample</span> |
| 146 | <a name="l00132"></a>00132 <span class="comment">// first corner</span> |
| 147 | <a name="l00133"></a>00133 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < dim; j++) { |
| 148 | <a name="l00134"></a>00134 smpi (j) = XYZ (j) (0); <span class="comment">/* beginning of the interval*/</span> |
| 149 | <a name="l00135"></a>00135 it_assert(gridsize(j)!=0.0,<span class="stringliteral">"Zeros in gridsize!"</span>); |
| 150 | <a name="l00136"></a>00136 steps (j) = ( XYZ(j)(1)-smpi(j) )/gridsize(j); |
| 151 | <a name="l00137"></a>00137 } |
| 152 | <a name="l00138"></a>00138 <span class="comment">// fill samples</span> |
| 153 | <a name="l00139"></a>00139 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; i++) { |
| 154 | <a name="l00140"></a>00140 <span class="comment">// copy </span> |
| 155 | <a name="l00141"></a>00141 samples(i) = smpi; |
| 156 | <a name="l00142"></a>00142 <span class="comment">// go through all dimensions</span> |
| 157 | <a name="l00143"></a>00143 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0;j < dim;j++) { |
| 158 | <a name="l00144"></a>00144 <span class="keywordflow">if</span> (ind (j) == gridsize (j) - 1) { <span class="comment">//j-th index is full</span> |
| 159 | <a name="l00145"></a>00145 ind (j) = 0; <span class="comment">//shift back</span> |
| 160 | <a name="l00146"></a>00146 smpi(j) = XYZ(j)(0); |
| 161 | <a name="l00147"></a>00147 |
| 162 | <a name="l00148"></a>00148 <span class="keywordflow">if</span> (i<Npoints-1) { |
| 163 | <a name="l00149"></a>00149 ind (j + 1) ++; <span class="comment">//increase the next dimension;</span> |
| 164 | <a name="l00150"></a>00150 smpi(j+1) += steps(j+1); |
| 165 | <a name="l00151"></a>00151 <span class="keywordflow">break</span>; |
| 166 | <a name="l00152"></a>00152 } |
| 167 | <a name="l00153"></a>00153 |
| 168 | <a name="l00154"></a>00154 } <span class="keywordflow">else</span> { |
| 169 | <a name="l00155"></a>00155 ind (j) ++; |
| 170 | <a name="l00156"></a>00156 smpi(j) +=steps(j); |
| 171 | <a name="l00157"></a>00157 <span class="keywordflow">break</span>; |
| 172 | <a name="l00158"></a>00158 } |
| 173 | <a name="l00159"></a>00159 } |
| 174 | <a name="l00160"></a>00160 } |
| 175 | <a name="l00161"></a>00161 } |
| 176 | <a name="l00163"></a><a class="code" href="classbdm_1_1merger__base.html#e4514484bac243585b0a1e44325e8add">00163</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#e4514484bac243585b0a1e44325e8add" title="set debug file">set_debug_file</a> (<span class="keyword">const</span> <span class="keywordtype">string</span> fname) { |
| 177 | <a name="l00164"></a>00164 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a>) <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
| 178 | <a name="l00165"></a>00165 <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a> = <span class="keyword">new</span> it_file (fname); |
| 179 | <a name="l00166"></a>00166 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>) <a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a> = <span class="keyword">true</span>; |
186 | | <a name="l00173"></a>00173 |
187 | | <a name="l00175"></a><a class="code" href="classbdm_1_1merger__base.html#32d7e1dd6d91f77c81df7e82aac18689">00175</a> <span class="keyword">virtual</span> <a class="code" href="classbdm_1_1merger__base.html#32d7e1dd6d91f77c81df7e82aac18689" title="Destructor.">~merger_base</a>() { |
188 | | <a name="l00176"></a>00176 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a>; i++) { |
189 | | <a name="l00177"></a>00177 <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a> (i); |
190 | | <a name="l00178"></a>00178 <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a> (i); |
191 | | <a name="l00179"></a>00179 } |
192 | | <a name="l00180"></a>00180 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a>) <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
193 | | <a name="l00181"></a>00181 }; |
194 | | <a name="l00183"></a>00183 |
195 | | <a name="l00186"></a>00186 |
196 | | <a name="l00188"></a><a class="code" href="classbdm_1_1merger__base.html#df4a0094dcc40b3057675443bccb6511">00188</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#df4a0094dcc40b3057675443bccb6511" title="Merge given sources in given points.">merge</a> () { |
197 | | <a name="l00189"></a>00189 <a class="code" href="classbdm_1_1merger__base.html#400e222d4c41dc57ac19e6735429c4cb" title="This method TODO.">validate</a>(); |
198 | | <a name="l00190"></a>00190 |
199 | | <a name="l00191"></a>00191 <span class="comment">//check if sources overlap:</span> |
200 | | <a name="l00192"></a>00192 <span class="keywordtype">bool</span> OK = <span class="keyword">true</span>; |
201 | | <a name="l00193"></a>00193 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); i++) { |
202 | | <a name="l00194"></a>00194 OK &= (<a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a> (i)._dsize() == 0); <span class="comment">// z_i is empty</span> |
203 | | <a name="l00195"></a>00195 OK &= (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rvc()._dsize() == 0); <span class="comment">// y_i is empty</span> |
204 | | <a name="l00196"></a>00196 } |
205 | | <a name="l00197"></a>00197 |
206 | | <a name="l00198"></a>00198 <span class="keywordflow">if</span> (OK) { |
207 | | <a name="l00199"></a>00199 mat lW = zeros (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(), <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>().length()); |
208 | | <a name="l00200"></a>00200 |
209 | | <a name="l00201"></a>00201 vec emptyvec (0); |
210 | | <a name="l00202"></a>00202 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); i++) { |
211 | | <a name="l00203"></a>00203 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>().length(); j++) { |
212 | | <a name="l00204"></a>00204 lW (i, j) = <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->evallogcond (<a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() (j), emptyvec); |
213 | | <a name="l00205"></a>00205 } |
214 | | <a name="l00206"></a>00206 } |
215 | | <a name="l00207"></a>00207 |
216 | | <a name="l00208"></a>00208 vec w_nn=<a class="code" href="classbdm_1_1merger__base.html#1f52bf47d2cdd23a95b19e3da902e431" title="Merge log-likelihood values in points using method specified by parameter METHOD...">merge_points</a> (lW); |
217 | | <a name="l00209"></a>00209 vec wtmp = exp (w_nn-max(w_nn)); |
218 | | <a name="l00210"></a>00210 <span class="comment">//renormalize</span> |
219 | | <a name="l00211"></a>00211 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() = wtmp / sum (wtmp); |
220 | | <a name="l00212"></a>00212 } <span class="keywordflow">else</span> { |
221 | | <a name="l00213"></a>00213 it_error (<span class="stringliteral">"Sources are not compatible - use merger_mix"</span>); |
222 | | <a name="l00214"></a>00214 } |
223 | | <a name="l00215"></a>00215 }; |
224 | | <a name="l00216"></a>00216 |
225 | | <a name="l00217"></a>00217 |
226 | | <a name="l00219"></a>00219 vec <a class="code" href="classbdm_1_1merger__base.html#1f52bf47d2cdd23a95b19e3da902e431" title="Merge log-likelihood values in points using method specified by parameter METHOD...">merge_points</a> (mat &lW); |
227 | | <a name="l00220"></a>00220 |
| 185 | <a name="l00174"></a><a class="code" href="classbdm_1_1merger__base.html#28af7b365ecd8c3a15f0e934496871e0">00174</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#28af7b365ecd8c3a15f0e934496871e0" title="Set support points from a pdf by drawing N samples.">set_support</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> &overall, <span class="keywordtype">int</span> N) { |
| 186 | <a name="l00175"></a>00175 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#7cfd383180b486fe4526bdf0179350c0" title="Set samples and weights.">set_statistics</a> (&overall, N); |
| 187 | <a name="l00176"></a>00176 <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a> = N; |
| 188 | <a name="l00177"></a>00177 } |
| 189 | <a name="l00178"></a>00178 |
| 190 | <a name="l00180"></a><a class="code" href="classbdm_1_1merger__base.html#32d7e1dd6d91f77c81df7e82aac18689">00180</a> <span class="keyword">virtual</span> <a class="code" href="classbdm_1_1merger__base.html#32d7e1dd6d91f77c81df7e82aac18689" title="Destructor.">~merger_base</a>() { |
| 191 | <a name="l00181"></a>00181 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a>; i++) { |
| 192 | <a name="l00182"></a>00182 <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a> (i); |
| 193 | <a name="l00183"></a>00183 <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a> (i); |
| 194 | <a name="l00184"></a>00184 } |
| 195 | <a name="l00185"></a>00185 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a>) <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
| 196 | <a name="l00186"></a>00186 }; |
| 197 | <a name="l00188"></a>00188 |
| 198 | <a name="l00191"></a>00191 |
| 199 | <a name="l00193"></a><a class="code" href="classbdm_1_1merger__base.html#df4a0094dcc40b3057675443bccb6511">00193</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#df4a0094dcc40b3057675443bccb6511" title="Merge given sources in given points.">merge</a> () { |
| 200 | <a name="l00194"></a>00194 <a class="code" href="classbdm_1_1merger__base.html#400e222d4c41dc57ac19e6735429c4cb" title="This method TODO.">validate</a>(); |
| 201 | <a name="l00195"></a>00195 |
| 202 | <a name="l00196"></a>00196 <span class="comment">//check if sources overlap:</span> |
| 203 | <a name="l00197"></a>00197 <span class="keywordtype">bool</span> OK = <span class="keyword">true</span>; |
| 204 | <a name="l00198"></a>00198 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); i++) { |
| 205 | <a name="l00199"></a>00199 OK &= (<a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a> (i)._dsize() == 0); <span class="comment">// z_i is empty</span> |
| 206 | <a name="l00200"></a>00200 OK &= (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rvc()._dsize() == 0); <span class="comment">// y_i is empty</span> |
| 207 | <a name="l00201"></a>00201 } |
| 208 | <a name="l00202"></a>00202 |
| 209 | <a name="l00203"></a>00203 <span class="keywordflow">if</span> (OK) { |
| 210 | <a name="l00204"></a>00204 mat lW = zeros (<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(), <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>().length()); |
| 211 | <a name="l00205"></a>00205 |
| 212 | <a name="l00206"></a>00206 vec emptyvec (0); |
| 213 | <a name="l00207"></a>00207 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); i++) { |
| 214 | <a name="l00208"></a>00208 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>().length(); j++) { |
| 215 | <a name="l00209"></a>00209 lW (i, j) = <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->evallogcond (<a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() (j), emptyvec); |
| 216 | <a name="l00210"></a>00210 } |
| 217 | <a name="l00211"></a>00211 } |
| 218 | <a name="l00212"></a>00212 |
| 219 | <a name="l00213"></a>00213 vec w_nn=<a class="code" href="classbdm_1_1merger__base.html#1f52bf47d2cdd23a95b19e3da902e431" title="Merge log-likelihood values in points using method specified by parameter METHOD...">merge_points</a> (lW); |
| 220 | <a name="l00214"></a>00214 vec wtmp = exp (w_nn-max(w_nn)); |
| 221 | <a name="l00215"></a>00215 <span class="comment">//renormalize</span> |
| 222 | <a name="l00216"></a>00216 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() = wtmp / sum (wtmp); |
| 223 | <a name="l00217"></a>00217 } <span class="keywordflow">else</span> { |
| 224 | <a name="l00218"></a>00218 it_error (<span class="stringliteral">"Sources are not compatible - use merger_mix"</span>); |
| 225 | <a name="l00219"></a>00219 } |
| 226 | <a name="l00220"></a>00220 }; |
229 | | <a name="l00224"></a><a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0">00224</a> vec <a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>()<span class="keyword"> const </span>{ |
230 | | <a name="l00225"></a>00225 <span class="keyword">const</span> Vec<double> &w = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>(); |
231 | | <a name="l00226"></a>00226 <span class="keyword">const</span> Array<vec> &S = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
232 | | <a name="l00227"></a>00227 vec tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
233 | | <a name="l00228"></a>00228 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; i++) { |
234 | | <a name="l00229"></a>00229 tmp += w (i) * S (i); |
235 | | <a name="l00230"></a>00230 } |
236 | | <a name="l00231"></a>00231 <span class="keywordflow">return</span> tmp; |
237 | | <a name="l00232"></a>00232 } |
238 | | <a name="l00233"></a>00233 mat covariance()<span class="keyword"> const </span>{ |
239 | | <a name="l00234"></a>00234 <span class="keyword">const</span> vec &w = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>(); |
240 | | <a name="l00235"></a>00235 <span class="keyword">const</span> Array<vec> &S = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
241 | | <a name="l00236"></a>00236 |
242 | | <a name="l00237"></a>00237 vec mea = <a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>(); |
243 | | <a name="l00238"></a>00238 |
244 | | <a name="l00239"></a>00239 cout << sum (w) << <span class="stringliteral">","</span> << w*w << endl; |
245 | | <a name="l00240"></a>00240 |
246 | | <a name="l00241"></a>00241 mat Tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
247 | | <a name="l00242"></a>00242 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; i++) { |
248 | | <a name="l00243"></a>00243 Tmp += w (i) * outer_product (S (i), S (i)); |
249 | | <a name="l00244"></a>00244 } |
250 | | <a name="l00245"></a>00245 <span class="keywordflow">return</span> Tmp -outer_product (mea, mea); |
251 | | <a name="l00246"></a>00246 } |
252 | | <a name="l00247"></a><a class="code" href="classbdm_1_1merger__base.html#76fe431922844d132b4e1ecf70f53c99">00247</a> vec <a class="code" href="classbdm_1_1merger__base.html#76fe431922844d132b4e1ecf70f53c99" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
253 | | <a name="l00248"></a>00248 <span class="keyword">const</span> vec &w = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>(); |
254 | | <a name="l00249"></a>00249 <span class="keyword">const</span> Array<vec> &S = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
255 | | <a name="l00250"></a>00250 |
256 | | <a name="l00251"></a>00251 vec tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
257 | | <a name="l00252"></a>00252 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a>; i++) { |
258 | | <a name="l00253"></a>00253 tmp += w (i) * pow (S (i), 2); |
259 | | <a name="l00254"></a>00254 } |
260 | | <a name="l00255"></a>00255 <span class="keywordflow">return</span> tmp -pow (<a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>(), 2); |
261 | | <a name="l00256"></a>00256 } |
262 | | <a name="l00258"></a>00258 |
263 | | <a name="l00261"></a>00261 |
264 | | <a name="l00263"></a><a class="code" href="classbdm_1_1merger__base.html#fb682e470103f4e0b353b7c9200d177f">00263</a> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>& <a class="code" href="classbdm_1_1merger__base.html#fb682e470103f4e0b353b7c9200d177f" title="Access function.">_Smp</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>;} |
265 | | <a name="l00264"></a>00264 |
266 | | <a name="l00266"></a><a class="code" href="classbdm_1_1merger__base.html#10dd390fc6f0d1733bb07cb51977160c">00266</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#10dd390fc6f0d1733bb07cb51977160c" title="load from setting">from_setting</a> (<span class="keyword">const</span> Setting& <span class="keyword">set</span>) { |
267 | | <a name="l00267"></a>00267 <span class="comment">// get support</span> |
268 | | <a name="l00268"></a>00268 <span class="comment">// find which method to use</span> |
269 | | <a name="l00269"></a>00269 <span class="keywordtype">string</span> meth_str; |
270 | | <a name="l00270"></a>00270 UI::get<string> (meth_str, <span class="keyword">set</span>, <span class="stringliteral">"method"</span>); |
271 | | <a name="l00271"></a>00271 <span class="keywordflow">if</span> (!strcmp (meth_str.c_str(), <span class="stringliteral">"arithmetic"</span>)) |
272 | | <a name="l00272"></a>00272 <a class="code" href="classbdm_1_1merger__base.html#e779dc28c822539be5131a46e6ec82aa" title="Set internal parameters used in approximation.">set_method</a> (ARITHMETIC); |
273 | | <a name="l00273"></a>00273 <span class="keywordflow">else</span> { |
274 | | <a name="l00274"></a>00274 <span class="keywordflow">if</span> (!strcmp (meth_str.c_str(), <span class="stringliteral">"geometric"</span>)) |
275 | | <a name="l00275"></a>00275 <a class="code" href="classbdm_1_1merger__base.html#e779dc28c822539be5131a46e6ec82aa" title="Set internal parameters used in approximation.">set_method</a> (GEOMETRIC); |
276 | | <a name="l00276"></a>00276 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp (meth_str.c_str(), <span class="stringliteral">"lognormal"</span>)) { |
277 | | <a name="l00277"></a>00277 <a class="code" href="classbdm_1_1merger__base.html#e779dc28c822539be5131a46e6ec82aa" title="Set internal parameters used in approximation.">set_method</a> (LOGNORMAL); |
278 | | <a name="l00278"></a>00278 <span class="keyword">set</span>.lookupValue( <span class="stringliteral">"beta"</span>,<a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a>); |
279 | | <a name="l00279"></a>00279 } |
280 | | <a name="l00280"></a>00280 } |
281 | | <a name="l00281"></a>00281 <span class="keywordflow">if</span> (<span class="keyword">set</span>.exists(<span class="stringliteral">"dbg_file"</span>)){ |
282 | | <a name="l00282"></a>00282 <span class="keywordtype">string</span> <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
283 | | <a name="l00283"></a>00283 UI::get<string> (dbg_file, <span class="keyword">set</span>, <span class="stringliteral">"dbg_file"</span>); |
284 | | <a name="l00284"></a>00284 <a class="code" href="classbdm_1_1merger__base.html#e4514484bac243585b0a1e44325e8add" title="set debug file">set_debug_file</a>(dbg_file); |
| 228 | <a name="l00222"></a>00222 |
| 229 | <a name="l00224"></a>00224 vec <a class="code" href="classbdm_1_1merger__base.html#1f52bf47d2cdd23a95b19e3da902e431" title="Merge log-likelihood values in points using method specified by parameter METHOD...">merge_points</a> (mat &lW); |
| 230 | <a name="l00225"></a>00225 |
| 231 | <a name="l00226"></a>00226 |
| 232 | <a name="l00229"></a><a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0">00229</a> vec <a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>()<span class="keyword"> const </span>{ |
| 233 | <a name="l00230"></a>00230 <span class="keyword">const</span> Vec<double> &w = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>(); |
| 234 | <a name="l00231"></a>00231 <span class="keyword">const</span> Array<vec> &S = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
| 235 | <a name="l00232"></a>00232 vec tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 236 | <a name="l00233"></a>00233 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; i++) { |
| 237 | <a name="l00234"></a>00234 tmp += w (i) * S (i); |
| 238 | <a name="l00235"></a>00235 } |
| 239 | <a name="l00236"></a>00236 <span class="keywordflow">return</span> tmp; |
| 240 | <a name="l00237"></a>00237 } |
| 241 | <a name="l00238"></a>00238 mat covariance()<span class="keyword"> const </span>{ |
| 242 | <a name="l00239"></a>00239 <span class="keyword">const</span> vec &w = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>(); |
| 243 | <a name="l00240"></a>00240 <span class="keyword">const</span> Array<vec> &S = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
| 244 | <a name="l00241"></a>00241 |
| 245 | <a name="l00242"></a>00242 vec mea = <a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>(); |
| 246 | <a name="l00243"></a>00243 |
| 247 | <a name="l00244"></a>00244 cout << sum (w) << <span class="stringliteral">","</span> << w*w << endl; |
| 248 | <a name="l00245"></a>00245 |
| 249 | <a name="l00246"></a>00246 mat Tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 250 | <a name="l00247"></a>00247 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#39d263d92aa85553730c44958a92a541" title="number of support points">Npoints</a>; i++) { |
| 251 | <a name="l00248"></a>00248 Tmp += w (i) * outer_product (S (i), S (i)); |
| 252 | <a name="l00249"></a>00249 } |
| 253 | <a name="l00250"></a>00250 <span class="keywordflow">return</span> Tmp -outer_product (mea, mea); |
| 254 | <a name="l00251"></a>00251 } |
| 255 | <a name="l00252"></a><a class="code" href="classbdm_1_1merger__base.html#76fe431922844d132b4e1ecf70f53c99">00252</a> vec <a class="code" href="classbdm_1_1merger__base.html#76fe431922844d132b4e1ecf70f53c99" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
| 256 | <a name="l00253"></a>00253 <span class="keyword">const</span> vec &w = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>(); |
| 257 | <a name="l00254"></a>00254 <span class="keyword">const</span> Array<vec> &S = <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>(); |
| 258 | <a name="l00255"></a>00255 |
| 259 | <a name="l00256"></a>00256 vec tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 260 | <a name="l00257"></a>00257 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a>; i++) { |
| 261 | <a name="l00258"></a>00258 tmp += w (i) * pow (S (i), 2); |
| 262 | <a name="l00259"></a>00259 } |
| 263 | <a name="l00260"></a>00260 <span class="keywordflow">return</span> tmp -pow (<a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>(), 2); |
| 264 | <a name="l00261"></a>00261 } |
| 265 | <a name="l00263"></a>00263 |
| 266 | <a name="l00266"></a>00266 |
| 267 | <a name="l00268"></a><a class="code" href="classbdm_1_1merger__base.html#fb682e470103f4e0b353b7c9200d177f">00268</a> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>& <a class="code" href="classbdm_1_1merger__base.html#fb682e470103f4e0b353b7c9200d177f" title="Access function.">_Smp</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>;} |
| 268 | <a name="l00269"></a>00269 |
| 269 | <a name="l00271"></a><a class="code" href="classbdm_1_1merger__base.html#10dd390fc6f0d1733bb07cb51977160c">00271</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#10dd390fc6f0d1733bb07cb51977160c" title="load from setting">from_setting</a> (<span class="keyword">const</span> Setting& <span class="keyword">set</span>) { |
| 270 | <a name="l00272"></a>00272 <span class="comment">// get support</span> |
| 271 | <a name="l00273"></a>00273 <span class="comment">// find which method to use</span> |
| 272 | <a name="l00274"></a>00274 <span class="keywordtype">string</span> meth_str; |
| 273 | <a name="l00275"></a>00275 UI::get<string> (meth_str, <span class="keyword">set</span>, <span class="stringliteral">"method"</span>); |
| 274 | <a name="l00276"></a>00276 <span class="keywordflow">if</span> (!strcmp (meth_str.c_str(), <span class="stringliteral">"arithmetic"</span>)) |
| 275 | <a name="l00277"></a>00277 <a class="code" href="classbdm_1_1merger__base.html#86698b7fd1e4320e9830d7dc24ee6c9e" title="Set internal parameters used in approximation.">set_method</a> (ARITHMETIC); |
| 276 | <a name="l00278"></a>00278 <span class="keywordflow">else</span> { |
| 277 | <a name="l00279"></a>00279 <span class="keywordflow">if</span> (!strcmp (meth_str.c_str(), <span class="stringliteral">"geometric"</span>)) |
| 278 | <a name="l00280"></a>00280 <a class="code" href="classbdm_1_1merger__base.html#86698b7fd1e4320e9830d7dc24ee6c9e" title="Set internal parameters used in approximation.">set_method</a> (GEOMETRIC); |
| 279 | <a name="l00281"></a>00281 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp (meth_str.c_str(), <span class="stringliteral">"lognormal"</span>)) { |
| 280 | <a name="l00282"></a>00282 <a class="code" href="classbdm_1_1merger__base.html#86698b7fd1e4320e9830d7dc24ee6c9e" title="Set internal parameters used in approximation.">set_method</a> (LOGNORMAL); |
| 281 | <a name="l00283"></a>00283 <span class="keyword">set</span>.lookupValue( <span class="stringliteral">"beta"</span>,<a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a>); |
| 282 | <a name="l00284"></a>00284 } |
286 | | <a name="l00286"></a>00286 <span class="comment">//validate() - not used</span> |
287 | | <a name="l00287"></a>00287 } |
288 | | <a name="l00288"></a>00288 |
289 | | <a name="l00289"></a><a class="code" href="classbdm_1_1merger__base.html#400e222d4c41dc57ac19e6735429c4cb">00289</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#400e222d4c41dc57ac19e6735429c4cb" title="This method TODO.">validate</a>() { |
290 | | <a name="l00290"></a>00290 it_assert (<a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>().length() > 0, <span class="stringliteral">"Empty support, use set_support()."</span>); |
291 | | <a name="l00291"></a>00291 it_assert (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> == <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() (0).length(), <span class="stringliteral">"Support points and rv are not compatible!"</span>); |
292 | | <a name="l00292"></a>00292 it_assert (<a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(),<span class="stringliteral">"mergers must be named"</span>); |
293 | | <a name="l00293"></a>00293 } |
294 | | <a name="l00295"></a>00295 }; |
295 | | <a name="l00296"></a>00296 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(merger_base); |
296 | | <a name="l00297"></a>00297 |
297 | | <a name="l00298"></a>00298 <span class="keyword">class </span>merger_mix : <span class="keyword">public</span> merger_base |
298 | | <a name="l00299"></a>00299 { |
299 | | <a name="l00300"></a>00300 <span class="keyword">protected</span>: |
300 | | <a name="l00302"></a>00302 MixEF Mix; |
301 | | <a name="l00304"></a>00304 <span class="keywordtype">int</span> Ncoms; |
302 | | <a name="l00306"></a>00306 <span class="keywordtype">double</span> effss_coef; |
303 | | <a name="l00308"></a>00308 <span class="keywordtype">int</span> stop_niter; |
304 | | <a name="l00309"></a>00309 |
305 | | <a name="l00310"></a>00310 <span class="keyword">public</span>: |
306 | | <a name="l00313"></a>00313 merger_mix () {}; |
307 | | <a name="l00314"></a>00314 merger_mix (<span class="keyword">const</span> Array<mpdf*> &S,<span class="keywordtype">bool</span> own=<span class="keyword">false</span>) {set_sources (S,own);}; |
308 | | <a name="l00316"></a>00316 <span class="keywordtype">void</span> set_sources (<span class="keyword">const</span> Array<mpdf*> &S, <span class="keywordtype">bool</span> own) { |
309 | | <a name="l00317"></a>00317 <a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d" title="Function setting the main internal structures.">merger_base::set_sources</a> (S,own); |
310 | | <a name="l00318"></a>00318 <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a> = S.length(); |
311 | | <a name="l00319"></a>00319 } |
312 | | <a name="l00321"></a>00321 <span class="keywordtype">void</span> set_parameters (<span class="keywordtype">int</span> Ncoms0 = 10, <span class="keywordtype">double</span> effss_coef0 = 0.5) { |
313 | | <a name="l00322"></a>00322 Ncoms = Ncoms0; |
314 | | <a name="l00323"></a>00323 effss_coef = effss_coef0; |
315 | | <a name="l00324"></a>00324 } |
316 | | <a name="l00326"></a>00326 |
317 | | <a name="l00329"></a>00329 |
318 | | <a name="l00331"></a>00331 <span class="keywordtype">void</span> merge (); |
319 | | <a name="l00332"></a>00332 |
320 | | <a name="l00334"></a>00334 vec sample ()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> Mix.posterior().sample();} |
321 | | <a name="l00336"></a>00336 <span class="keywordtype">double</span> evallog (<span class="keyword">const</span> vec &dt)<span class="keyword"> const </span>{ |
322 | | <a name="l00337"></a>00337 vec dtf = ones (dt.length() + 1); |
323 | | <a name="l00338"></a>00338 dtf.set_subvector (0, dt); |
324 | | <a name="l00339"></a>00339 <span class="keywordflow">return</span> Mix.logpred (dtf); |
325 | | <a name="l00340"></a>00340 } |
| 284 | <a name="l00286"></a>00286 <span class="keywordflow">if</span> (<span class="keyword">set</span>.exists(<span class="stringliteral">"dbg_file"</span>)){ |
| 285 | <a name="l00287"></a>00287 <span class="keywordtype">string</span> <a class="code" href="classbdm_1_1merger__base.html#b2c6278b996696cb711cb7be900ccf5b" title="debugging file">dbg_file</a>; |
| 286 | <a name="l00288"></a>00288 UI::get<string> (dbg_file, <span class="keyword">set</span>, <span class="stringliteral">"dbg_file"</span>); |
| 287 | <a name="l00289"></a>00289 <a class="code" href="classbdm_1_1merger__base.html#e4514484bac243585b0a1e44325e8add" title="set debug file">set_debug_file</a>(dbg_file); |
| 288 | <a name="l00290"></a>00290 } |
| 289 | <a name="l00291"></a>00291 <span class="comment">//validate() - not used</span> |
| 290 | <a name="l00292"></a>00292 } |
| 291 | <a name="l00293"></a>00293 |
| 292 | <a name="l00294"></a><a class="code" href="classbdm_1_1merger__base.html#400e222d4c41dc57ac19e6735429c4cb">00294</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#400e222d4c41dc57ac19e6735429c4cb" title="This method TODO.">validate</a>() { |
| 293 | <a name="l00295"></a>00295 it_assert (<a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>().length() > 0, <span class="stringliteral">"Empty support, use set_support()."</span>); |
| 294 | <a name="l00296"></a>00296 it_assert (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> == <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.<a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() (0).length(), <span class="stringliteral">"Support points and rv are not compatible!"</span>); |
| 295 | <a name="l00297"></a>00297 it_assert (<a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(),<span class="stringliteral">"mergers must be named"</span>); |
| 296 | <a name="l00298"></a>00298 } |
| 297 | <a name="l00300"></a>00300 }; |
| 298 | <a name="l00301"></a>00301 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(merger_base); |
| 299 | <a name="l00302"></a>00302 |
| 300 | <a name="l00303"></a>00303 <span class="keyword">class </span>merger_mix : <span class="keyword">public</span> merger_base |
| 301 | <a name="l00304"></a>00304 { |
| 302 | <a name="l00305"></a>00305 <span class="keyword">protected</span>: |
| 303 | <a name="l00307"></a>00307 MixEF Mix; |
| 304 | <a name="l00309"></a>00309 <span class="keywordtype">int</span> Ncoms; |
| 305 | <a name="l00311"></a>00311 <span class="keywordtype">double</span> effss_coef; |
| 306 | <a name="l00313"></a>00313 <span class="keywordtype">int</span> stop_niter; |
| 307 | <a name="l00314"></a>00314 |
| 308 | <a name="l00316"></a>00316 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> DFLT_Ncoms; |
| 309 | <a name="l00318"></a>00318 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">double</span> DFLT_effss_coef; |
| 310 | <a name="l00319"></a>00319 |
| 311 | <a name="l00320"></a>00320 <span class="keyword">public</span>: |
| 312 | <a name="l00323"></a>00323 merger_mix () {}; |
| 313 | <a name="l00324"></a>00324 merger_mix (<span class="keyword">const</span> Array<mpdf*> &S,<span class="keywordtype">bool</span> own=<span class="keyword">false</span>) {set_sources (S,own);}; |
| 314 | <a name="l00326"></a>00326 <span class="keywordtype">void</span> set_sources (<span class="keyword">const</span> Array<mpdf*> &S, <span class="keywordtype">bool</span> own) { |
| 315 | <a name="l00327"></a>00327 <a class="code" href="classbdm_1_1merger__base.html#591d4ba19c9ece40aa96ee44d05e148d" title="Function setting the main internal structures.">merger_base::set_sources</a> (S,own); |
| 316 | <a name="l00328"></a>00328 <a class="code" href="classbdm_1_1merger__base.html#4f6cd7ebe1c3c7556039dbfeb00f71f5" title="number of sources">Nsources</a> = S.length(); |
| 317 | <a name="l00329"></a>00329 } |
| 318 | <a name="l00331"></a>00331 <span class="keywordtype">void</span> set_parameters (<span class="keywordtype">int</span> Ncoms0 = DFLT_Ncoms, <span class="keywordtype">double</span> effss_coef0 = DFLT_effss_coef) { |
| 319 | <a name="l00332"></a>00332 Ncoms = Ncoms0; |
| 320 | <a name="l00333"></a>00333 effss_coef = effss_coef0; |
| 321 | <a name="l00334"></a>00334 } |
| 322 | <a name="l00336"></a>00336 |
| 323 | <a name="l00339"></a>00339 |
| 324 | <a name="l00341"></a>00341 <span class="keywordtype">void</span> merge (); |