1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: merger.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>merger.h</h1><a href="merger_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef MER_H</span> |
---|
67 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define MER_H</span> |
---|
68 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
69 | <a name="l00016"></a>00016 |
---|
70 | <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="mixef_8h.html" title="Bayesian Filtering for mixtures of exponential family (EF) members.">mixef.h</a>"</span> |
---|
71 | <a name="l00018"></a>00018 |
---|
72 | <a name="l00019"></a>00019 <span class="keyword">namespace </span>bdm |
---|
73 | <a name="l00020"></a>00020 { |
---|
74 | <a name="l00021"></a>00021 <span class="keyword">using</span> std::string; |
---|
75 | <a name="l00022"></a>00022 |
---|
76 | <a name="l00024"></a>00024 <span class="keyword">enum</span> MERGER_METHOD {ARITHMETIC = 0, GEOMETRIC = 1, LOGNORMAL = 2}; |
---|
77 | <a name="l00025"></a>00025 |
---|
78 | <a name="l00045"></a><a class="code" href="classbdm_1_1merger__base.html">00045</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1merger__base.html" title="Base class for general combination of pdfs on discrete support.">merger_base</a> : <span class="keyword">public</span> <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>, <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
---|
79 | <a name="l00046"></a>00046 { |
---|
80 | <a name="l00047"></a>00047 <span class="keyword">protected</span>: |
---|
81 | <a name="l00049"></a><a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7">00049</a> Array<datalink_m2e*> <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a>; |
---|
82 | <a name="l00051"></a><a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f">00051</a> Array<RV> <a class="code" href="classbdm_1_1merger__base.html#4e66803b04fc04b21b3716b3a317421f" title="Array of rvs that are not modelled by mpdfs at all, .">rvzs</a>; |
---|
83 | <a name="l00053"></a><a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694">00053</a> Array<datalink_m2e*> <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a>; |
---|
84 | <a name="l00055"></a><a class="code" href="classbdm_1_1merger__base.html#52e33b1aa153fa700cc036be2b12f9bd">00055</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1merger__base.html#52e33b1aa153fa700cc036be2b12f9bd" title="number of sources">Ns</a>; |
---|
85 | <a name="l00056"></a>00056 |
---|
86 | <a name="l00058"></a><a class="code" href="classbdm_1_1merger__base.html#ee197330820127f3d12106ddee6b25c7">00058</a> MERGER_METHOD <a class="code" href="classbdm_1_1merger__base.html#ee197330820127f3d12106ddee6b25c7" title="switch of the methoh used for merging">METHOD</a>; |
---|
87 | <a name="l00060"></a><a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14">00060</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>; |
---|
88 | <a name="l00061"></a>00061 |
---|
89 | <a name="l00063"></a><a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e">00063</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>; |
---|
90 | <a name="l00064"></a>00064 |
---|
91 | <a name="l00066"></a><a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7">00066</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a>; |
---|
92 | <a name="l00067"></a>00067 |
---|
93 | <a name="l00069"></a><a class="code" href="classbdm_1_1merger__base.html#7b0b7549b8335cdd26faee68093da3ad">00069</a> it_file* <a class="code" href="classbdm_1_1merger__base.html#7b0b7549b8335cdd26faee68093da3ad" title="debugging file">dbg</a>; |
---|
94 | <a name="l00070"></a>00070 <span class="keyword">public</span>: |
---|
95 | <a name="l00073"></a>00073 |
---|
96 | <a name="l00075"></a><a class="code" href="classbdm_1_1merger__base.html#f9d8c6c26c6520dbb17d4e80f635e7be">00075</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>() {}; |
---|
97 | <a name="l00077"></a><a class="code" href="classbdm_1_1merger__base.html#ed5cbd925628893a51c36bc1807f4a75">00077</a> <a class="code" href="classbdm_1_1merger__base.html#ed5cbd925628893a51c36bc1807f4a75" title="Constructor from sources.">merger_base</a> (<span class="keyword">const</span> Array<mpdf*> &S) {<a class="code" href="classbdm_1_1merger__base.html#bde0fd02ae620b4130e768fa70aafa94" title="Function setting the main internal structures.">set_sources</a> (S);}; |
---|
98 | <a name="l00079"></a><a class="code" href="classbdm_1_1merger__base.html#bde0fd02ae620b4130e768fa70aafa94">00079</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#bde0fd02ae620b4130e768fa70aafa94" title="Function setting the main internal structures.">set_sources</a> (<span class="keyword">const</span> Array<mpdf*> &Sources) { |
---|
99 | <a name="l00080"></a>00080 compositepdf::set_elements (Sources); |
---|
100 | <a name="l00081"></a>00081 <span class="comment">//set sizes</span> |
---|
101 | <a name="l00082"></a>00082 <a class="code" href="classbdm_1_1merger__base.html#09bc4d43dec350a40d17953b8b59d3b7" title="Data link for each mpdf in mpdfs.">dls</a>.set_size (Sources.length()); |
---|
102 | <a name="l00083"></a>00083 <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()); |
---|
103 | <a name="l00084"></a>00084 <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a>.set_size (Sources.length()); |
---|
104 | <a name="l00085"></a>00085 |
---|
105 | <a name="l00086"></a>00086 <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>); |
---|
106 | <a name="l00087"></a>00087 <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> |
---|
107 | <a name="l00088"></a>00088 <span class="comment">// join rv and rvc - see descriprion</span> |
---|
108 | <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_1RV.html#87841b5ee43997b79789c0c22047e224" title="Add (concat) another variable to the current one,.">add</a> (rvc); |
---|
109 | <a name="l00090"></a>00090 <span class="comment">// get dimension</span> |
---|
110 | <a name="l00091"></a>00091 <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>(); |
---|
111 | <a name="l00092"></a>00092 |
---|
112 | <a name="l00093"></a>00093 <span class="comment">// create links between sources and common rv</span> |
---|
113 | <a name="l00094"></a>00094 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> xytmp; |
---|
114 | <a name="l00095"></a>00095 <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++) { |
---|
115 | <a name="l00096"></a>00096 <span class="comment">//Establich connection between mpdfs and merger</span> |
---|
116 | <a name="l00097"></a>00097 <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>; |
---|
117 | <a name="l00098"></a>00098 <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>); |
---|
118 | <a name="l00099"></a>00099 |
---|
119 | <a name="l00100"></a>00100 <span class="comment">// find out what is missing in each mpdf</span> |
---|
120 | <a name="l00101"></a>00101 xytmp = <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> (i)->_rv(); |
---|
121 | <a name="l00102"></a>00102 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()); |
---|
122 | <a name="l00103"></a>00103 <span class="comment">// z_i = common_rv-xy</span> |
---|
123 | <a name="l00104"></a>00104 <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); |
---|
124 | <a name="l00105"></a>00105 <span class="comment">//establish connection between extension (z_i|x,y)s and common rv</span> |
---|
125 | <a name="l00106"></a>00106 <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>) ; |
---|
126 | <a name="l00107"></a>00107 }; |
---|
127 | <a name="l00108"></a>00108 <span class="comment">//Set Default values of parameters</span> |
---|
128 | <a name="l00109"></a>00109 <a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a> = <span class="keyword">false</span>; |
---|
129 | <a name="l00110"></a>00110 <a class="code" href="classbdm_1_1merger__base.html#ee197330820127f3d12106ddee6b25c7" title="switch of the methoh used for merging">METHOD</a> = LOGNORMAL; |
---|
130 | <a name="l00111"></a>00111 <a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a> = 2.0; |
---|
131 | <a name="l00112"></a>00112 } |
---|
132 | <a name="l00114"></a><a class="code" href="classbdm_1_1merger__base.html#e4514484bac243585b0a1e44325e8add">00114</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) { <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#7b0b7549b8335cdd26faee68093da3ad" title="debugging file">dbg</a>; <a class="code" href="classbdm_1_1merger__base.html#7b0b7549b8335cdd26faee68093da3ad" title="debugging file">dbg</a> = <span class="keyword">new</span> it_file (fname); <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1merger__base.html#7b0b7549b8335cdd26faee68093da3ad" title="debugging file">dbg</a>) <a class="code" href="classbdm_1_1merger__base.html#dd180c651a75a131d125305f6bb017f7" title="debug or not debug">DBG</a> = <span class="keyword">true</span>;} |
---|
133 | <a name="l00116"></a><a class="code" href="classbdm_1_1merger__base.html#5c85ba8a7c5246674891c6ebbf59ef54">00116</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#5c85ba8a7c5246674891c6ebbf59ef54" title="Set internal parameters used in approximation.">set_parameters</a> (<span class="keywordtype">double</span> beta0, MERGER_METHOD MTH) {<a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a> = beta0;<a class="code" href="classbdm_1_1merger__base.html#ee197330820127f3d12106ddee6b25c7" title="switch of the methoh used for merging">METHOD</a> = MTH;} |
---|
134 | <a name="l00118"></a><a class="code" href="classbdm_1_1merger__base.html#c02a1c55042c40cd190e240f1329d8d4">00118</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#c02a1c55042c40cd190e240f1329d8d4" title="Set support points from a pdf.">set_support</a>(<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){<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);<a class="code" href="classbdm_1_1merger__base.html#52e33b1aa153fa700cc036be2b12f9bd" title="number of sources">Ns</a>=N;} |
---|
135 | <a name="l00119"></a>00119 |
---|
136 | <a name="l00121"></a><a class="code" href="classbdm_1_1merger__base.html#32d7e1dd6d91f77c81df7e82aac18689">00121</a> <span class="keyword">virtual</span> <a class="code" href="classbdm_1_1merger__base.html#32d7e1dd6d91f77c81df7e82aac18689" title="Destructor.">~merger_base</a>() { |
---|
137 | <a name="l00122"></a>00122 <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++) { |
---|
138 | <a name="l00123"></a>00123 <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); |
---|
139 | <a name="l00124"></a>00124 <span class="keyword">delete</span> <a class="code" href="classbdm_1_1merger__base.html#8098858f2edb1294122cbe4f05bf8694" title="Data Links for extension .">zdls</a> (i); |
---|
140 | <a name="l00125"></a>00125 } |
---|
141 | <a name="l00126"></a>00126 <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#7b0b7549b8335cdd26faee68093da3ad" title="debugging file">dbg</a>; |
---|
142 | <a name="l00127"></a>00127 }; |
---|
143 | <a name="l00129"></a>00129 |
---|
144 | <a name="l00132"></a>00132 |
---|
145 | <a name="l00134"></a><a class="code" href="classbdm_1_1merger__base.html#fcaf1960643dba08fd17dec57b05c1f2">00134</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#fcaf1960643dba08fd17dec57b05c1f2" title="Merge given sources in given points.">merge</a> () { |
---|
146 | <a name="l00135"></a>00135 <span class="keywordflow">if</span> (<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) {it_error(<span class="stringliteral">"Empty support points use set_support"</span> );} |
---|
147 | <a name="l00136"></a>00136 <span class="comment">//check if sources overlap:</span> |
---|
148 | <a name="l00137"></a>00137 <span class="keywordtype">bool</span> OK = <span class="keyword">true</span>; |
---|
149 | <a name="l00138"></a>00138 <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++) { |
---|
150 | <a name="l00139"></a>00139 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> |
---|
151 | <a name="l00140"></a>00140 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> |
---|
152 | <a name="l00141"></a>00141 } |
---|
153 | <a name="l00142"></a>00142 |
---|
154 | <a name="l00143"></a>00143 <span class="keywordflow">if</span> (OK) { |
---|
155 | <a name="l00144"></a>00144 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()); |
---|
156 | <a name="l00145"></a>00145 |
---|
157 | <a name="l00146"></a>00146 vec emptyvec (0); |
---|
158 | <a name="l00147"></a>00147 <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++) { |
---|
159 | <a name="l00148"></a>00148 <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++) { |
---|
160 | <a name="l00149"></a>00149 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); |
---|
161 | <a name="l00150"></a>00150 } |
---|
162 | <a name="l00151"></a>00151 } |
---|
163 | <a name="l00152"></a>00152 |
---|
164 | <a name="l00153"></a>00153 vec wtmp = exp (<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)); |
---|
165 | <a name="l00154"></a>00154 <span class="comment">//renormalize</span> |
---|
166 | <a name="l00155"></a>00155 <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); |
---|
167 | <a name="l00156"></a>00156 } <span class="keywordflow">else</span> { |
---|
168 | <a name="l00157"></a>00157 it_error(<span class="stringliteral">"Sources are not compatible - use merger_mix"</span>); |
---|
169 | <a name="l00158"></a>00158 } |
---|
170 | <a name="l00159"></a>00159 ; |
---|
171 | <a name="l00160"></a>00160 }; |
---|
172 | <a name="l00161"></a>00161 |
---|
173 | <a name="l00162"></a>00162 |
---|
174 | <a name="l00164"></a>00164 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); |
---|
175 | <a name="l00165"></a>00165 |
---|
176 | <a name="l00166"></a>00166 |
---|
177 | <a name="l00169"></a><a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0">00169</a> vec <a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>()<span class="keyword"> const </span>{ |
---|
178 | <a name="l00170"></a>00170 <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>(); |
---|
179 | <a name="l00171"></a>00171 <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>(); |
---|
180 | <a name="l00172"></a>00172 vec tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
---|
181 | <a name="l00173"></a>00173 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#52e33b1aa153fa700cc036be2b12f9bd" title="number of sources">Ns</a>; i++) { |
---|
182 | <a name="l00174"></a>00174 tmp += w (i) * S (i); |
---|
183 | <a name="l00175"></a>00175 } |
---|
184 | <a name="l00176"></a>00176 <span class="keywordflow">return</span> tmp; |
---|
185 | <a name="l00177"></a>00177 } |
---|
186 | <a name="l00178"></a>00178 mat covariance()<span class="keyword"> const </span>{ |
---|
187 | <a name="l00179"></a>00179 <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>(); |
---|
188 | <a name="l00180"></a>00180 <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>(); |
---|
189 | <a name="l00181"></a>00181 |
---|
190 | <a name="l00182"></a>00182 vec mea = <a class="code" href="classbdm_1_1merger__base.html#021acbf1a6e3bfde2a1b9c1c73cea6e0" title="weight w is a">mean</a>(); |
---|
191 | <a name="l00183"></a>00183 |
---|
192 | <a name="l00184"></a>00184 cout << sum (w) << <span class="stringliteral">","</span> << w*w << endl; |
---|
193 | <a name="l00185"></a>00185 |
---|
194 | <a name="l00186"></a>00186 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>); |
---|
195 | <a name="l00187"></a>00187 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1merger__base.html#52e33b1aa153fa700cc036be2b12f9bd" title="number of sources">Ns</a>; i++) { |
---|
196 | <a name="l00188"></a>00188 Tmp += w (i) * outer_product (S (i), S (i)); |
---|
197 | <a name="l00189"></a>00189 } |
---|
198 | <a name="l00190"></a>00190 <span class="keywordflow">return</span> Tmp -outer_product (mea, mea); |
---|
199 | <a name="l00191"></a>00191 } |
---|
200 | <a name="l00192"></a><a class="code" href="classbdm_1_1merger__base.html#76fe431922844d132b4e1ecf70f53c99">00192</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>{ |
---|
201 | <a name="l00193"></a>00193 <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>(); |
---|
202 | <a name="l00194"></a>00194 <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>(); |
---|
203 | <a name="l00195"></a>00195 |
---|
204 | <a name="l00196"></a>00196 vec tmp = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
---|
205 | <a name="l00197"></a>00197 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < Ns; i++) { |
---|
206 | <a name="l00198"></a>00198 tmp += w (i) * pow (S (i), 2); |
---|
207 | <a name="l00199"></a>00199 } |
---|
208 | <a name="l00200"></a>00200 <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); |
---|
209 | <a name="l00201"></a>00201 } |
---|
210 | <a name="l00203"></a>00203 |
---|
211 | <a name="l00206"></a>00206 |
---|
212 | <a name="l00208"></a><a class="code" href="classbdm_1_1merger__base.html#fb682e470103f4e0b353b7c9200d177f">00208</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>;} |
---|
213 | <a name="l00209"></a>00209 |
---|
214 | <a name="l00211"></a>00211 }; |
---|
215 | <a name="l00212"></a>00212 |
---|
216 | <a name="l00213"></a>00213 <span class="keyword">class </span>merger_mix : <span class="keyword">public</span> merger_base |
---|
217 | <a name="l00214"></a>00214 { |
---|
218 | <a name="l00215"></a>00215 <span class="keyword">protected</span>: |
---|
219 | <a name="l00217"></a>00217 MixEF Mix; |
---|
220 | <a name="l00219"></a>00219 <span class="keywordtype">int</span> Nc; |
---|
221 | <a name="l00221"></a>00221 <span class="keywordtype">double</span> effss_coef; |
---|
222 | <a name="l00222"></a>00222 |
---|
223 | <a name="l00223"></a>00223 <span class="keyword">public</span>: |
---|
224 | <a name="l00225"></a>00225 merger_mix () {}; |
---|
225 | <a name="l00226"></a>00226 merger_mix (<span class="keyword">const</span> Array<mpdf*> &S) {set_sources(S);}; |
---|
226 | <a name="l00228"></a>00228 <span class="keywordtype">void</span> set_sources (<span class="keyword">const</span> Array<mpdf*> &S) { |
---|
227 | <a name="l00229"></a>00229 <a class="code" href="classbdm_1_1merger__base.html#bde0fd02ae620b4130e768fa70aafa94" title="Function setting the main internal structures.">merger_base::set_sources</a>(S); |
---|
228 | <a name="l00230"></a>00230 <span class="comment">//Set Default values of parameters</span> |
---|
229 | <a name="l00231"></a>00231 Ns = 100; |
---|
230 | <a name="l00232"></a>00232 Nc = 10; |
---|
231 | <a name="l00233"></a>00233 Mix.set_method (EM); |
---|
232 | <a name="l00234"></a>00234 } |
---|
233 | <a name="l00236"></a>00236 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1merger__base.html#5c85ba8a7c5246674891c6ebbf59ef54" title="Set internal parameters used in approximation.">set_parameters</a> (<span class="keywordtype">double</span> beta0, <span class="keywordtype">int</span> Ns0, <span class="keywordtype">int</span> Nc0, <span class="keywordtype">double</span> effss_coef0 = 0.5) { |
---|
234 | <a name="l00237"></a>00237 <a class="code" href="classbdm_1_1merger__base.html#972f64f6f388b929cf94d2c478116f14" title="Prior on the log-normal merging model.">beta</a> = beta0; |
---|
235 | <a name="l00238"></a>00238 Ns = Ns0; |
---|
236 | <a name="l00239"></a>00239 Nc = Nc0; |
---|
237 | <a name="l00240"></a>00240 effss_coef = effss_coef0; |
---|
238 | <a name="l00241"></a>00241 <a class="code" href="classbdm_1_1merger__base.html#a042ce6ee1fb91048ea89bec9934718e" title="Projection to empirical density (could also be piece-wise linear).">eSmp</a>.set_parameters (Ns0, <span class="keyword">false</span>); |
---|
239 | <a name="l00242"></a>00242 } |
---|
240 | <a name="l00244"></a>00244 <span class="keywordtype">void</span> init() { |
---|
241 | <a name="l00245"></a>00245 Array<vec> Smps (Ns); |
---|
242 | <a name="l00246"></a>00246 <span class="comment">//Gibbs sampling</span> |
---|
243 | <a name="l00247"></a>00247 <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++) {Smps (i) = zeros (0);} |
---|
244 | <a name="l00248"></a>00248 } |
---|
245 | <a name="l00250"></a>00250 <span class="keywordtype">void</span> merge (); |
---|
246 | <a name="l00251"></a>00251 |
---|
247 | <a name="l00254"></a>00254 vec sample ()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> Mix.posterior().sample();} |
---|
248 | <a name="l00255"></a>00255 <span class="keywordtype">double</span> evallog (<span class="keyword">const</span> vec &dt)<span class="keyword"> const </span>{ |
---|
249 | <a name="l00256"></a>00256 vec dtf = ones (dt.length() + 1); |
---|
250 | <a name="l00257"></a>00257 dtf.set_subvector (0, dt); |
---|
251 | <a name="l00258"></a>00258 <span class="keywordflow">return</span> Mix.logpred (dtf); |
---|
252 | <a name="l00259"></a>00259 } |
---|
253 | <a name="l00260"></a>00260 vec mean()<span class="keyword"> const </span>{ |
---|
254 | <a name="l00261"></a>00261 <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>._w(); |
---|
255 | <a name="l00262"></a>00262 <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>._samples(); |
---|
256 | <a name="l00263"></a>00263 vec tmp = zeros (dim); |
---|
257 | <a name="l00264"></a>00264 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < Ns; i++) { |
---|
258 | <a name="l00265"></a>00265 tmp += w (i) * S (i); |
---|
259 | <a name="l00266"></a>00266 } |
---|
260 | <a name="l00267"></a>00267 <span class="keywordflow">return</span> tmp; |
---|
261 | <a name="l00268"></a>00268 } |
---|
262 | <a name="l00269"></a>00269 mat covariance()<span class="keyword"> const </span>{ |
---|
263 | <a name="l00270"></a>00270 <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>._w(); |
---|
264 | <a name="l00271"></a>00271 <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>._samples(); |
---|
265 | <a name="l00272"></a>00272 |
---|
266 | <a name="l00273"></a>00273 vec mea = mean(); |
---|
267 | <a name="l00274"></a>00274 |
---|
268 | <a name="l00275"></a>00275 cout << sum (w) << <span class="stringliteral">","</span> << w*w << endl; |
---|
269 | <a name="l00276"></a>00276 |
---|
270 | <a name="l00277"></a>00277 mat Tmp = zeros (dim, dim); |
---|
271 | <a name="l00278"></a>00278 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < Ns; i++) { |
---|
272 | <a name="l00279"></a>00279 Tmp += w (i) * outer_product (S (i), S (i)); |
---|
273 | <a name="l00280"></a>00280 } |
---|
274 | <a name="l00281"></a>00281 <span class="keywordflow">return</span> Tmp -outer_product (mea, mea); |
---|
275 | <a name="l00282"></a>00282 } |
---|
276 | <a name="l00283"></a>00283 vec variance()<span class="keyword"> const </span>{ |
---|
277 | <a name="l00284"></a>00284 <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>._w(); |
---|
278 | <a name="l00285"></a>00285 <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>._samples(); |
---|
279 | <a name="l00286"></a>00286 |
---|
280 | <a name="l00287"></a>00287 vec tmp = zeros (dim); |
---|
281 | <a name="l00288"></a>00288 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < Ns; i++) { |
---|
282 | <a name="l00289"></a>00289 tmp += w (i) * pow (S (i), 2); |
---|
283 | <a name="l00290"></a>00290 } |
---|
284 | <a name="l00291"></a>00291 <span class="keywordflow">return</span> tmp -pow (mean(), 2); |
---|
285 | <a name="l00292"></a>00292 } |
---|
286 | <a name="l00293"></a>00293 |
---|
287 | <a name="l00295"></a>00295 MixEF& _Mix() {<span class="keywordflow">return</span> Mix;} |
---|
288 | <a name="l00297"></a>00297 emix* proposal() {emix* tmp = Mix.epredictor(); tmp->set_rv (rv); <span class="keywordflow">return</span> tmp;} |
---|
289 | <a name="l00299"></a>00299 eEmp& _Smp() {<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>;} |
---|
290 | <a name="l00300"></a>00300 }; |
---|
291 | <a name="l00301"></a>00301 |
---|
292 | <a name="l00302"></a>00302 } |
---|
293 | <a name="l00303"></a>00303 |
---|
294 | <a name="l00304"></a>00304 <span class="preprocessor">#endif // MER_H</span> |
---|
295 | </pre></div></div> |
---|
296 | <hr size="1"><address style="text-align: right;"><small>Generated on Wed Jun 17 14:13:28 2009 for mixpp by |
---|
297 | <a href="http://www.doxygen.org/index.html"> |
---|
298 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
299 | </body> |
---|
300 | </html> |
---|