129 | | <a name="l00107"></a>00107 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
130 | | <a name="l00108"></a><a class="code" href="classbdm_1_1enorm.html">00108</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
131 | | <a name="l00109"></a>00109 { |
132 | | <a name="l00110"></a>00110 <span class="keyword">protected</span>: |
133 | | <a name="l00112"></a><a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7">00112</a> vec <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
134 | | <a name="l00114"></a><a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2">00114</a> sq_T <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>; |
135 | | <a name="l00115"></a>00115 <span class="keyword">public</span>: |
136 | | <a name="l00118"></a>00118 |
137 | | <a name="l00119"></a>00119 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> (), <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> (), <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> () {}; |
138 | | <a name="l00120"></a>00120 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> (<span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>, <span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>) {set_parameters (mu, R);} |
139 | | <a name="l00121"></a>00121 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>, <span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>); |
140 | | <a name="l00122"></a>00122 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">from_setting</a> (<span class="keyword">const</span> Setting &root); |
141 | | <a name="l00123"></a><a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea">00123</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea" title="This method TODO.">validate</a>() { |
142 | | <a name="l00124"></a>00124 it_assert (<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>.length() == <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows(), <span class="stringliteral">"parameters mismatch"</span>); |
143 | | <a name="l00125"></a>00125 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>.length(); |
144 | | <a name="l00126"></a>00126 } |
145 | | <a name="l00128"></a>00128 |
146 | | <a name="l00131"></a>00131 |
147 | | <a name="l00133"></a>00133 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">dupdate</a> (mat &v, <span class="keywordtype">double</span> nu = 1.0); |
148 | | <a name="l00134"></a>00134 |
149 | | <a name="l00135"></a>00135 vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
150 | | <a name="l00136"></a>00136 |
151 | | <a name="l00137"></a>00137 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">evallog_nn</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
152 | | <a name="l00138"></a>00138 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
153 | | <a name="l00139"></a><a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600">00139</a> vec <a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
154 | | <a name="l00140"></a><a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773">00140</a> vec <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> diag (<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.to_mat());} |
155 | | <a name="l00141"></a>00141 <span class="comment">// mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why?</span> |
156 | | <a name="l00142"></a>00142 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> <a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span>; |
157 | | <a name="l00143"></a>00143 |
158 | | <a name="l00144"></a>00144 <span class="comment">// target not typed to mlnorm<sq_T, enorm<sq_T> > &</span> |
159 | | <a name="l00145"></a>00145 <span class="comment">// because that doesn't compile (perhaps because we</span> |
160 | | <a name="l00146"></a>00146 <span class="comment">// haven't finished defining enorm yet), but the type</span> |
161 | | <a name="l00147"></a>00147 <span class="comment">// is required</span> |
162 | | <a name="l00148"></a>00148 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where is random variable, rv, and...">mpdf</a> &target ) <span class="keyword">const</span>; |
163 | | <a name="l00149"></a>00149 |
164 | | <a name="l00150"></a>00150 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> <a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span>; |
165 | | <a name="l00151"></a>00151 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> &target ) <span class="keyword">const</span>; |
166 | | <a name="l00153"></a>00153 |
167 | | <a name="l00156"></a>00156 |
168 | | <a name="l00157"></a>00157 vec& _mu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
169 | | <a name="l00158"></a>00158 <span class="keywordtype">void</span> set_mu (<span class="keyword">const</span> vec mu0) { <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> = mu0;} |
170 | | <a name="l00159"></a>00159 sq_T& _R() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
171 | | <a name="l00160"></a>00160 <span class="keyword">const</span> sq_T& _R()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
172 | | <a name="l00162"></a>00162 |
173 | | <a name="l00163"></a>00163 }; |
174 | | <a name="l00164"></a>00164 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (enorm, chmat); |
175 | | <a name="l00165"></a>00165 SHAREDPTR2 ( enorm, chmat ); |
176 | | <a name="l00166"></a>00166 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (enorm, ldmat); |
177 | | <a name="l00167"></a>00167 SHAREDPTR2 ( enorm, ldmat ); |
178 | | <a name="l00168"></a>00168 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (enorm, fsqmat); |
179 | | <a name="l00169"></a>00169 SHAREDPTR2 ( enorm, fsqmat ); |
| 131 | <a name="l00103"></a><a class="code" href="classbdm_1_1BMEF.html#b2916a2e71a958665054473124d5e749">00103</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#b2916a2e71a958665054473124d5e749" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> * B) { |
| 132 | <a name="l00104"></a>00104 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
| 133 | <a name="l00105"></a>00105 } |
| 134 | <a name="l00106"></a>00106 |
| 135 | <a name="l00107"></a><a class="code" href="classbdm_1_1BMEF.html#62d2e4691bed41a1efa6b9c2e35e5c67">00107</a> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* <a class="code" href="classbdm_1_1BMEF.html#62d2e4691bed41a1efa6b9c2e35e5c67">_copy_</a> ()<span class="keyword"> const </span>{ |
| 136 | <a name="l00108"></a>00108 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"function _copy_ not implemented for this BM"</span>); |
| 137 | <a name="l00109"></a>00109 <span class="keywordflow">return</span> NULL; |
| 138 | <a name="l00110"></a>00110 } |
| 139 | <a name="l00111"></a>00111 }; |
| 140 | <a name="l00112"></a>00112 |
| 141 | <a name="l00113"></a>00113 <span class="keyword">template</span><<span class="keyword">class</span> sq_T, <span class="keyword">template</span> <<span class="keyword">typename</span>> <span class="keyword">class </span>TEpdf> |
| 142 | <a name="l00114"></a>00114 <span class="keyword">class </span>mlnorm; |
| 143 | <a name="l00115"></a>00115 |
| 144 | <a name="l00121"></a>00121 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 145 | <a name="l00122"></a><a class="code" href="classbdm_1_1enorm.html">00122</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
| 146 | <a name="l00123"></a>00123 { |
| 147 | <a name="l00124"></a>00124 <span class="keyword">protected</span>: |
| 148 | <a name="l00126"></a><a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7">00126</a> vec <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
| 149 | <a name="l00128"></a><a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2">00128</a> sq_T <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>; |
| 150 | <a name="l00129"></a>00129 <span class="keyword">public</span>: |
| 151 | <a name="l00132"></a>00132 |
| 152 | <a name="l00133"></a>00133 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> (), <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> (), <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> () {}; |
| 153 | <a name="l00134"></a>00134 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> (<span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>, <span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>) {set_parameters (mu, R);} |
| 154 | <a name="l00135"></a>00135 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>, <span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>); |
| 155 | <a name="l00136"></a>00136 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">from_setting</a> (<span class="keyword">const</span> Setting &root); |
| 156 | <a name="l00137"></a><a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea">00137</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea" title="This method TODO.">validate</a>() { |
| 157 | <a name="l00138"></a>00138 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>.length() == <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows(), <span class="stringliteral">"parameters mismatch"</span>); |
| 158 | <a name="l00139"></a>00139 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>.length(); |
| 159 | <a name="l00140"></a>00140 } |
| 160 | <a name="l00142"></a>00142 |
| 161 | <a name="l00145"></a>00145 |
| 162 | <a name="l00147"></a>00147 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">dupdate</a> (mat &v, <span class="keywordtype">double</span> nu = 1.0); |
| 163 | <a name="l00148"></a>00148 |
| 164 | <a name="l00149"></a>00149 vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 165 | <a name="l00150"></a>00150 |
| 166 | <a name="l00151"></a>00151 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">evallog_nn</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
| 167 | <a name="l00152"></a>00152 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
| 168 | <a name="l00153"></a><a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600">00153</a> vec <a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
| 169 | <a name="l00154"></a><a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773">00154</a> vec <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> diag (<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.to_mat());} |
| 170 | <a name="l00155"></a>00155 <span class="comment">// mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why?</span> |
| 171 | <a name="l00156"></a>00156 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> <a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span>; |
| 172 | <a name="l00157"></a>00157 |
| 173 | <a name="l00158"></a>00158 <span class="comment">// target not typed to mlnorm<sq_T, enorm<sq_T> > &</span> |
| 174 | <a name="l00159"></a>00159 <span class="comment">// because that doesn't compile (perhaps because we</span> |
| 175 | <a name="l00160"></a>00160 <span class="comment">// haven't finished defining enorm yet), but the type</span> |
| 176 | <a name="l00161"></a>00161 <span class="comment">// is required</span> |
| 177 | <a name="l00162"></a>00162 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where is random variable, rv, and...">mpdf</a> &target ) <span class="keyword">const</span>; |
| 178 | <a name="l00163"></a>00163 |
| 179 | <a name="l00164"></a>00164 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> <a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span>; |
| 180 | <a name="l00165"></a>00165 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> &target ) <span class="keyword">const</span>; |
| 181 | <a name="l00167"></a>00167 |
207 | | <a name="l00210"></a>00210 vec <a class="code" href="classbdm_1_1egiw.html#920f21548b7a3723923dd108fe514c61" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
208 | | <a name="l00211"></a>00211 vec <a class="code" href="classbdm_1_1egiw.html#df70c05f918c3a6f86d60f10c1fd6ba2" title="return expected value">mean</a>() <span class="keyword">const</span>; |
209 | | <a name="l00212"></a>00212 vec <a class="code" href="classbdm_1_1egiw.html#c1ecc406613cc2341225dc10c3d3b46a" title="return expected variance (not covariance!)">variance</a>() <span class="keyword">const</span>; |
210 | | <a name="l00213"></a>00213 |
211 | | <a name="l00215"></a>00215 vec <a class="code" href="classbdm_1_1egiw.html#66d2ba9295c306012b309efcc9e516f0" title="LS estimate of .">est_theta</a>() <span class="keyword">const</span>; |
212 | | <a name="l00216"></a>00216 |
213 | | <a name="l00218"></a>00218 ldmat <a class="code" href="classbdm_1_1egiw.html#88c321a2051d1afdbb31a098896a717b" title="Covariance of the LS estimate.">est_theta_cov</a>() <span class="keyword">const</span>; |
214 | | <a name="l00219"></a>00219 |
215 | | <a name="l00221"></a>00221 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#d2075aa2306648b3e4fe40bb86628d5c" title="expected values of the linear coefficient and the covariance matrix are written to...">mean_mat</a> (mat &M, mat&R) <span class="keyword">const</span>; |
216 | | <a name="l00223"></a>00223 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#bfb8e7c619b34ad804a73bff71742b5e" title="In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise...">evallog_nn</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
217 | | <a name="l00224"></a>00224 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#41d72ba7b2abc8a9a4209ffa98ed5633" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
218 | | <a name="l00225"></a><a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be">00225</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be" title="Power of the density, used e.g. to flatten the density.">pow</a> (<span class="keywordtype">double</span> p) {V *= p;<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> *= p;}; |
219 | | <a name="l00226"></a>00226 |
220 | | <a name="l00229"></a>00229 |
221 | | <a name="l00230"></a>00230 <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V() {<span class="keywordflow">return</span> V;} |
222 | | <a name="l00231"></a>00231 <span class="keyword">const</span> ldmat& _V()<span class="keyword"> const </span>{<span class="keywordflow">return</span> V;} |
223 | | <a name="l00232"></a>00232 <span class="keywordtype">double</span>& _nu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
224 | | <a name="l00233"></a>00233 <span class="keyword">const</span> <span class="keywordtype">double</span>& _nu()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
225 | | <a name="l00234"></a><a class="code" href="classbdm_1_1egiw.html#55b76ec75bd2df5ef9cab3be20a33bbb">00234</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#55b76ec75bd2df5ef9cab3be20a33bbb">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
226 | | <a name="l00235"></a>00235 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>, <span class="keyword">set</span>, <span class="stringliteral">"nu"</span>, UI::compulsory); |
227 | | <a name="l00236"></a>00236 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>, <span class="keyword">set</span>, <span class="stringliteral">"dimx"</span>, UI::compulsory); |
228 | | <a name="l00237"></a>00237 mat V; |
229 | | <a name="l00238"></a>00238 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (V, <span class="keyword">set</span>, <span class="stringliteral">"V"</span>, UI::compulsory); |
230 | | <a name="l00239"></a>00239 set_parameters (<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>, V, <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>); |
231 | | <a name="l00240"></a>00240 <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1:shared_ptr spec.">shared_ptr<RV></a> <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> = UI::build<RV> (<span class="keyword">set</span>, <span class="stringliteral">"rv"</span>, UI::compulsory); |
232 | | <a name="l00241"></a>00241 <a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> (*rv); |
233 | | <a name="l00242"></a>00242 } |
234 | | <a name="l00244"></a>00244 }; |
235 | | <a name="l00245"></a>00245 <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> ( egiw ); |
236 | | <a name="l00246"></a>00246 SHAREDPTR ( egiw ); |
237 | | <a name="l00247"></a>00247 |
238 | | <a name="l00256"></a><a class="code" href="classbdm_1_1eDirich.html">00256</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
239 | | <a name="l00257"></a>00257 { |
240 | | <a name="l00258"></a>00258 <span class="keyword">protected</span>: |
241 | | <a name="l00260"></a><a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2">00260</a> vec <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>; |
242 | | <a name="l00261"></a>00261 <span class="keyword">public</span>: |
243 | | <a name="l00264"></a>00264 |
244 | | <a name="l00265"></a>00265 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {}; |
245 | | <a name="l00266"></a>00266 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> &D0) : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {set_parameters (D0.<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
246 | | <a name="l00267"></a>00267 eDirich (<span class="keyword">const</span> vec &beta0) {set_parameters (beta0);}; |
247 | | <a name="l00268"></a>00268 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &beta0) { |
248 | | <a name="l00269"></a>00269 <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> = beta0; |
249 | | <a name="l00270"></a>00270 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length(); |
250 | | <a name="l00271"></a>00271 } |
251 | | <a name="l00273"></a>00273 |
252 | | <a name="l00274"></a><a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc">00274</a> vec <a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{it_error (<span class="stringliteral">"Not implemented"</span>);<span class="keywordflow">return</span> vec_1 (0.0);}; |
253 | | <a name="l00275"></a><a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6">00275</a> vec <a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> / sum (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
254 | | <a name="l00276"></a><a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc">00276</a> vec <a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordtype">double</span> gamma = sum (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); <span class="keywordflow">return</span> elem_mult (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>, (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> + 1)) / (gamma* (gamma + 1));} |
255 | | <a name="l00278"></a><a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318">00278</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318" title="In this instance, val is ...">evallog_nn</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
256 | | <a name="l00279"></a>00279 <span class="keywordtype">double</span> tmp; tmp = (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> - 1) * log (val); |
257 | | <a name="l00280"></a>00280 <span class="comment">// it_assert_debug ( std::isfinite ( tmp ),"Infinite value" );</span> |
258 | | <a name="l00281"></a>00281 <span class="keywordflow">return</span> tmp; |
259 | | <a name="l00282"></a>00282 }; |
260 | | <a name="l00283"></a><a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2">00283</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const </span>{ |
261 | | <a name="l00284"></a>00284 <span class="keywordtype">double</span> tmp; |
262 | | <a name="l00285"></a>00285 <span class="keywordtype">double</span> gam = sum (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); |
263 | | <a name="l00286"></a>00286 <span class="keywordtype">double</span> lgb = 0.0; |
264 | | <a name="l00287"></a>00287 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length();i++) {lgb += lgamma (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> (i));} |
265 | | <a name="l00288"></a>00288 tmp = lgb - lgamma (gam); |
266 | | <a name="l00289"></a>00289 <span class="comment">// it_assert_debug ( std::isfinite ( tmp ),"Infinite value" );</span> |
267 | | <a name="l00290"></a>00290 <span class="keywordflow">return</span> tmp; |
268 | | <a name="l00291"></a>00291 }; |
269 | | <a name="l00293"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00293</a> vec& <a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>;} |
270 | | <a name="l00295"></a>00295 }; |
271 | | <a name="l00296"></a>00296 |
272 | | <a name="l00298"></a><a class="code" href="classbdm_1_1multiBM.html">00298</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> |
273 | | <a name="l00299"></a>00299 { |
274 | | <a name="l00300"></a>00300 <span class="keyword">protected</span>: |
275 | | <a name="l00302"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00302</a> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>; |
276 | | <a name="l00304"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00304</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
277 | | <a name="l00305"></a>00305 <span class="keyword">public</span>: |
278 | | <a name="l00307"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00307</a> <a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf" title="Default constructor.">multiBM</a> () : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> (), <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> (), <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> (<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta()) { |
279 | | <a name="l00308"></a>00308 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>.length() > 0) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
280 | | <a name="l00309"></a>00309 <span class="keywordflow">else</span>{<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = 0.0;} |
281 | | <a name="l00310"></a>00310 } |
282 | | <a name="l00312"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00312</a> <a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31" title="Copy constructor.">multiBM</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> &B) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> (B), <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> (B.<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>), <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> (<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta()) {} |
283 | | <a name="l00314"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00314</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52" title="Sets sufficient statistics to match that of givefrom mB0.">set_statistics</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* mB0) {<span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* mB = <span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> (mB0); <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = mB-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;} |
284 | | <a name="l00315"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00315</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95" title="Incremental Bayes rule.">bayes</a> (<span class="keyword">const</span> vec &dt) { |
285 | | <a name="l00316"></a>00316 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> < 1.0) {<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> *= <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
286 | | <a name="l00317"></a>00317 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> += dt; |
287 | | <a name="l00318"></a>00318 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {<a class="code" href="classbdm_1_1BM.html#4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>() - <a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
288 | | <a name="l00319"></a>00319 } |
289 | | <a name="l00320"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00320</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">logpred</a> (<span class="keyword">const</span> vec &dt)<span class="keyword"> const </span>{ |
290 | | <a name="l00321"></a>00321 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> pred (<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>); |
291 | | <a name="l00322"></a>00322 vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = pred.<a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>(); |
292 | | <a name="l00323"></a>00323 |
293 | | <a name="l00324"></a>00324 <span class="keywordtype">double</span> lll; |
294 | | <a name="l00325"></a>00325 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> < 1.0) |
295 | | <a name="l00326"></a>00326 {beta *= <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;lll = pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
296 | | <a name="l00327"></a>00327 <span class="keywordflow">else</span> |
297 | | <a name="l00328"></a>00328 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {lll = <a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
298 | | <a name="l00329"></a>00329 <span class="keywordflow">else</span>{lll = pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
299 | | <a name="l00330"></a>00330 |
300 | | <a name="l00331"></a>00331 beta += dt; |
301 | | <a name="l00332"></a>00332 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>() - lll; |
302 | | <a name="l00333"></a>00333 } |
303 | | <a name="l00334"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00334</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* B) { |
304 | | <a name="l00335"></a>00335 <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* E = <span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> (B); |
305 | | <a name="l00336"></a>00336 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
306 | | <a name="l00337"></a>00337 <span class="keyword">const</span> vec &Eb = E-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;<span class="comment">//const_cast<multiBM*> ( E )->_beta();</span> |
307 | | <a name="l00338"></a>00338 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> *= (sum (Eb) / sum (<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>)); |
308 | | <a name="l00339"></a>00339 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
309 | | <a name="l00340"></a>00340 } |
310 | | <a name="l00342"></a><a class="code" href="classbdm_1_1multiBM.html#31ff93f89473f099e489b9e1dc8d9513">00342</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>& <a class="code" href="classbdm_1_1multiBM.html#31ff93f89473f099e489b9e1dc8d9513" title="reimplemnetation of BM::posterior()">posterior</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
311 | | <a name="l00344"></a><a class="code" href="classbdm_1_1multiBM.html#7a480eace4446661bacca94c57499f01">00344</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#7a480eace4446661bacca94c57499f01" title="constructor function">set_parameters</a> (<span class="keyword">const</span> vec &beta0) { |
312 | | <a name="l00345"></a>00345 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#a06af2376976a33e1eceaed7e8da75a5">set_parameters</a> (beta0); |
313 | | <a name="l00346"></a>00346 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
314 | | <a name="l00347"></a>00347 } |
315 | | <a name="l00348"></a>00348 }; |
| 209 | <a name="l00210"></a>00210 <span class="keywordtype">void</span> set_parameters (<span class="keywordtype">int</span> dimx0, ldmat V0, <span class="keywordtype">double</span> nu0 = -1.0) { |
| 210 | <a name="l00211"></a>00211 <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> = dimx0; |
| 211 | <a name="l00212"></a>00212 <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> = V0.rows() - <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
| 212 | <a name="l00213"></a>00213 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> * (<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> + <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a>); <span class="comment">// size(R) + size(Theta)</span> |
| 213 | <a name="l00214"></a>00214 |
| 214 | <a name="l00215"></a>00215 <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a> = V0; |
| 215 | <a name="l00216"></a>00216 <span class="keywordflow">if</span> (nu0 < 0) { |
| 216 | <a name="l00217"></a>00217 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> = 0.1 + <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> + 2 * <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> + 2; <span class="comment">// +2 assures finite expected value of R</span> |
| 217 | <a name="l00218"></a>00218 <span class="comment">// terms before that are sufficient for finite normalization</span> |
| 218 | <a name="l00219"></a>00219 } <span class="keywordflow">else</span> { |
| 219 | <a name="l00220"></a>00220 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> = nu0; |
| 220 | <a name="l00221"></a>00221 } |
| 221 | <a name="l00222"></a>00222 } |
| 222 | <a name="l00224"></a>00224 |
| 223 | <a name="l00225"></a>00225 vec <a class="code" href="classbdm_1_1egiw.html#920f21548b7a3723923dd108fe514c61" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 224 | <a name="l00226"></a>00226 vec <a class="code" href="classbdm_1_1egiw.html#df70c05f918c3a6f86d60f10c1fd6ba2" title="return expected value">mean</a>() <span class="keyword">const</span>; |
| 225 | <a name="l00227"></a>00227 vec <a class="code" href="classbdm_1_1egiw.html#c1ecc406613cc2341225dc10c3d3b46a" title="return expected variance (not covariance!)">variance</a>() <span class="keyword">const</span>; |
| 226 | <a name="l00228"></a>00228 |
| 227 | <a name="l00230"></a>00230 vec <a class="code" href="classbdm_1_1egiw.html#66d2ba9295c306012b309efcc9e516f0" title="LS estimate of .">est_theta</a>() <span class="keyword">const</span>; |
| 228 | <a name="l00231"></a>00231 |
| 229 | <a name="l00233"></a>00233 ldmat <a class="code" href="classbdm_1_1egiw.html#88c321a2051d1afdbb31a098896a717b" title="Covariance of the LS estimate.">est_theta_cov</a>() <span class="keyword">const</span>; |
| 230 | <a name="l00234"></a>00234 |
| 231 | <a name="l00236"></a>00236 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#d2075aa2306648b3e4fe40bb86628d5c" title="expected values of the linear coefficient and the covariance matrix are written to...">mean_mat</a> (mat &M, mat&R) <span class="keyword">const</span>; |
| 232 | <a name="l00238"></a>00238 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#bfb8e7c619b34ad804a73bff71742b5e" title="In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise...">evallog_nn</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
| 233 | <a name="l00239"></a>00239 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#41d72ba7b2abc8a9a4209ffa98ed5633" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
| 234 | <a name="l00240"></a><a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be">00240</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be" title="Power of the density, used e.g. to flatten the density.">pow</a> (<span class="keywordtype">double</span> p) {V *= p;<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> *= p;}; |
| 235 | <a name="l00241"></a>00241 |
| 236 | <a name="l00244"></a>00244 |
| 237 | <a name="l00245"></a>00245 <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V() {<span class="keywordflow">return</span> V;} |
| 238 | <a name="l00246"></a>00246 <span class="keyword">const</span> ldmat& _V()<span class="keyword"> const </span>{<span class="keywordflow">return</span> V;} |
| 239 | <a name="l00247"></a>00247 <span class="keywordtype">double</span>& _nu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
| 240 | <a name="l00248"></a>00248 <span class="keyword">const</span> <span class="keywordtype">double</span>& _nu()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
| 241 | <a name="l00249"></a><a class="code" href="classbdm_1_1egiw.html#55b76ec75bd2df5ef9cab3be20a33bbb">00249</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#55b76ec75bd2df5ef9cab3be20a33bbb">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 242 | <a name="l00250"></a>00250 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>, <span class="keyword">set</span>, <span class="stringliteral">"nu"</span>, UI::compulsory); |
| 243 | <a name="l00251"></a>00251 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>, <span class="keyword">set</span>, <span class="stringliteral">"dimx"</span>, UI::compulsory); |
| 244 | <a name="l00252"></a>00252 mat V; |
| 245 | <a name="l00253"></a>00253 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (V, <span class="keyword">set</span>, <span class="stringliteral">"V"</span>, UI::compulsory); |
| 246 | <a name="l00254"></a>00254 set_parameters (<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>, V, <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>); |
| 247 | <a name="l00255"></a>00255 <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr<RV></a> <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> = UI::build<RV> (<span class="keyword">set</span>, <span class="stringliteral">"rv"</span>, UI::compulsory); |
| 248 | <a name="l00256"></a>00256 <a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> (*rv); |
| 249 | <a name="l00257"></a>00257 } |
| 250 | <a name="l00259"></a>00259 }; |
| 251 | <a name="l00260"></a>00260 <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> ( egiw ); |
| 252 | <a name="l00261"></a>00261 SHAREDPTR ( egiw ); |
| 253 | <a name="l00262"></a>00262 |
| 254 | <a name="l00271"></a><a class="code" href="classbdm_1_1eDirich.html">00271</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
| 255 | <a name="l00272"></a>00272 { |
| 256 | <a name="l00273"></a>00273 <span class="keyword">protected</span>: |
| 257 | <a name="l00275"></a><a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2">00275</a> vec <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>; |
| 258 | <a name="l00276"></a>00276 <span class="keyword">public</span>: |
| 259 | <a name="l00279"></a>00279 |
| 260 | <a name="l00280"></a>00280 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {}; |
| 261 | <a name="l00281"></a>00281 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> &D0) : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {set_parameters (D0.<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
| 262 | <a name="l00282"></a>00282 eDirich (<span class="keyword">const</span> vec &beta0) {set_parameters (beta0);}; |
| 263 | <a name="l00283"></a>00283 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &beta0) { |
| 264 | <a name="l00284"></a>00284 <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> = beta0; |
| 265 | <a name="l00285"></a>00285 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length(); |
| 266 | <a name="l00286"></a>00286 } |
| 267 | <a name="l00288"></a>00288 |
| 268 | <a name="l00289"></a><a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc">00289</a> vec <a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 269 | <a name="l00290"></a>00290 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
| 270 | <a name="l00291"></a>00291 <span class="keywordflow">return</span> vec(); |
| 271 | <a name="l00292"></a>00292 } |
| 272 | <a name="l00293"></a>00293 |
| 273 | <a name="l00294"></a><a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6">00294</a> vec <a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> / sum (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
| 274 | <a name="l00295"></a><a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc">00295</a> vec <a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordtype">double</span> gamma = sum (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); <span class="keywordflow">return</span> elem_mult (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>, (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> + 1)) / (gamma* (gamma + 1));} |
| 275 | <a name="l00297"></a><a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318">00297</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318" title="In this instance, val is ...">evallog_nn</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
| 276 | <a name="l00298"></a>00298 <span class="keywordtype">double</span> tmp; tmp = (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> - 1) * log (val); |
| 277 | <a name="l00299"></a>00299 <span class="keywordflow">return</span> tmp; |
| 278 | <a name="l00300"></a>00300 } |
| 279 | <a name="l00301"></a>00301 |
| 280 | <a name="l00302"></a><a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2">00302</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const </span>{ |
| 281 | <a name="l00303"></a>00303 <span class="keywordtype">double</span> tmp; |
| 282 | <a name="l00304"></a>00304 <span class="keywordtype">double</span> gam = sum (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); |
| 283 | <a name="l00305"></a>00305 <span class="keywordtype">double</span> lgb = 0.0; |
| 284 | <a name="l00306"></a>00306 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length();i++) {lgb += lgamma (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> (i));} |
| 285 | <a name="l00307"></a>00307 tmp = lgb - lgamma (gam); |
| 286 | <a name="l00308"></a>00308 <span class="keywordflow">return</span> tmp; |
| 287 | <a name="l00309"></a>00309 } |
| 288 | <a name="l00310"></a>00310 |
| 289 | <a name="l00312"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00312</a> vec& <a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>;} |
| 290 | <a name="l00314"></a>00314 }; |
| 291 | <a name="l00315"></a>00315 |
| 292 | <a name="l00317"></a><a class="code" href="classbdm_1_1multiBM.html">00317</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> |
| 293 | <a name="l00318"></a>00318 { |
| 294 | <a name="l00319"></a>00319 <span class="keyword">protected</span>: |
| 295 | <a name="l00321"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00321</a> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>; |
| 296 | <a name="l00323"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00323</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
| 297 | <a name="l00324"></a>00324 <span class="keyword">public</span>: |
| 298 | <a name="l00326"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00326</a> <a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf" title="Default constructor.">multiBM</a> () : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> (), <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> (), <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> (<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta()) { |
| 299 | <a name="l00327"></a>00327 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>.length() > 0) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 300 | <a name="l00328"></a>00328 <span class="keywordflow">else</span>{<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = 0.0;} |
| 301 | <a name="l00329"></a>00329 } |
| 302 | <a name="l00331"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00331</a> <a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31" title="Copy constructor.">multiBM</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> &B) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> (B), <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> (B.<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>), <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> (<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta()) {} |
| 303 | <a name="l00333"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00333</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52" title="Sets sufficient statistics to match that of givefrom mB0.">set_statistics</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* mB0) {<span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* mB = <span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> (mB0); <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = mB-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;} |
| 304 | <a name="l00334"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00334</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95" title="Incremental Bayes rule.">bayes</a> (<span class="keyword">const</span> vec &dt) { |
| 305 | <a name="l00335"></a>00335 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> < 1.0) {<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> *= <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 306 | <a name="l00336"></a>00336 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> += dt; |
| 307 | <a name="l00337"></a>00337 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {<a class="code" href="classbdm_1_1BM.html#4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>() - <a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
| 308 | <a name="l00338"></a>00338 } |
| 309 | <a name="l00339"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00339</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">logpred</a> (<span class="keyword">const</span> vec &dt)<span class="keyword"> const </span>{ |
| 310 | <a name="l00340"></a>00340 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> pred (<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>); |
| 311 | <a name="l00341"></a>00341 vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = pred.<a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>(); |
| 312 | <a name="l00342"></a>00342 |
| 313 | <a name="l00343"></a>00343 <span class="keywordtype">double</span> lll; |
| 314 | <a name="l00344"></a>00344 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> < 1.0) |
| 315 | <a name="l00345"></a>00345 {beta *= <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;lll = pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 316 | <a name="l00346"></a>00346 <span class="keywordflow">else</span> |
| 317 | <a name="l00347"></a>00347 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {lll = <a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
| 318 | <a name="l00348"></a>00348 <span class="keywordflow">else</span>{lll = pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
317 | | <a name="l00359"></a><a class="code" href="classbdm_1_1egamma.html">00359</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
318 | | <a name="l00360"></a>00360 { |
319 | | <a name="l00361"></a>00361 <span class="keyword">protected</span>: |
320 | | <a name="l00363"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00363</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
321 | | <a name="l00365"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00365</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
322 | | <a name="l00366"></a>00366 <span class="keyword">public</span> : |
323 | | <a name="l00369"></a>00369 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> (), <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> (0), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> (0) {}; |
324 | | <a name="l00370"></a>00370 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> (<span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b) {set_parameters (a, b);}; |
325 | | <a name="l00371"></a>00371 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b) {<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> = a, <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> = b;<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length();}; |
326 | | <a name="l00373"></a>00373 |
327 | | <a name="l00374"></a>00374 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
328 | | <a name="l00375"></a>00375 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="Evaluate normalized log-probability.">evallog</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
329 | | <a name="l00376"></a>00376 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
330 | | <a name="l00378"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00378</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns pointer to internal alpha. Potentially dengerous: use with care!">_alpha</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>;} |
331 | | <a name="l00380"></a><a class="code" href="classbdm_1_1egamma.html#c42cadd9cbd344caaa69b0b433cd16ca">00380</a> vec& <a class="code" href="classbdm_1_1egamma.html#c42cadd9cbd344caaa69b0b433cd16ca" title="Returns pointer to internal beta. Potentially dengerous: use with care!">_beta</a>() {<span class="keywordflow">return</span> beta;} |
332 | | <a name="l00381"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00381</a> vec <a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, beta);} |
333 | | <a name="l00382"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00382</a> vec <a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, elem_mult (beta, beta)); } |
334 | | <a name="l00383"></a>00383 |
335 | | <a name="l00392"></a><a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">00392</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
336 | | <a name="l00393"></a>00393 <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv</span> |
337 | | <a name="l00394"></a>00394 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, <span class="keyword">set</span>, <span class="stringliteral">"alpha"</span>, UI::compulsory); |
338 | | <a name="l00395"></a>00395 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (beta, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
339 | | <a name="l00396"></a>00396 <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>(); |
340 | | <a name="l00397"></a>00397 } |
341 | | <a name="l00398"></a><a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127">00398</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>() { |
342 | | <a name="l00399"></a>00399 it_assert (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length() == beta.length(), <span class="stringliteral">"parameters do not match"</span>); |
343 | | <a name="l00400"></a>00400 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length(); |
344 | | <a name="l00401"></a>00401 } |
345 | | <a name="l00402"></a>00402 }; |
346 | | <a name="l00403"></a>00403 <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> (egamma); |
347 | | <a name="l00404"></a>00404 SHAREDPTR ( egamma ); |
348 | | <a name="l00405"></a>00405 |
349 | | <a name="l00422"></a><a class="code" href="classbdm_1_1eigamma.html">00422</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> |
350 | | <a name="l00423"></a>00423 { |
351 | | <a name="l00424"></a>00424 <span class="keyword">protected</span>: |
352 | | <a name="l00425"></a>00425 <span class="keyword">public</span> : |
353 | | <a name="l00430"></a>00430 |
354 | | <a name="l00431"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00431</a> vec <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1.0 / <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">egamma::sample</a>();}; |
355 | | <a name="l00433"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00433</a> vec <a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div (<a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>, <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> - 1);} |
356 | | <a name="l00434"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00434</a> vec <a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{vec mea = <a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>(); <span class="keywordflow">return</span> elem_div (elem_mult (mea, mea), <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> - 2);} |
357 | | <a name="l00435"></a>00435 }; |
358 | | <a name="l00436"></a>00436 <span class="comment">/*</span> |
359 | | <a name="l00438"></a>00438 <span class="comment">class emix : public epdf {</span> |
360 | | <a name="l00439"></a>00439 <span class="comment">protected:</span> |
361 | | <a name="l00440"></a>00440 <span class="comment"> int n;</span> |
362 | | <a name="l00441"></a>00441 <span class="comment"> vec &w;</span> |
363 | | <a name="l00442"></a>00442 <span class="comment"> Array<epdf*> Coms;</span> |
364 | | <a name="l00443"></a>00443 <span class="comment">public:</span> |
365 | | <a name="l00445"></a>00445 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
366 | | <a name="l00446"></a>00446 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
367 | | <a name="l00447"></a>00447 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
368 | | <a name="l00448"></a>00448 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
369 | | <a name="l00449"></a>00449 <span class="comment">};</span> |
370 | | <a name="l00450"></a>00450 <span class="comment">*/</span> |
371 | | <a name="l00451"></a>00451 |
372 | | <a name="l00453"></a>00453 |
373 | | <a name="l00454"></a><a class="code" href="classbdm_1_1euni.html">00454</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</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> |
374 | | <a name="l00455"></a>00455 { |
375 | | <a name="l00456"></a>00456 <span class="keyword">protected</span>: |
376 | | <a name="l00458"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00458</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
377 | | <a name="l00460"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00460</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
378 | | <a name="l00462"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00462</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
379 | | <a name="l00464"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00464</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
380 | | <a name="l00466"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00466</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
381 | | <a name="l00467"></a>00467 <span class="keyword">public</span>: |
382 | | <a name="l00470"></a>00470 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> () : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> () {} |
383 | | <a name="l00471"></a>00471 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> (<span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0) {set_parameters (low0, high0);} |
384 | | <a name="l00472"></a>00472 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0) { |
385 | | <a name="l00473"></a>00473 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0 - low0; |
386 | | <a name="l00474"></a>00474 it_assert_debug (min (<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>) > 0.0, <span class="stringliteral">"bad support"</span>); |
387 | | <a name="l00475"></a>00475 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
388 | | <a name="l00476"></a>00476 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
389 | | <a name="l00477"></a>00477 <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> = prod (1.0 / <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>); |
390 | | <a name="l00478"></a>00478 <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a> = log (<a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>); |
391 | | <a name="l00479"></a>00479 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(); |
392 | | <a name="l00480"></a>00480 } |
393 | | <a name="l00482"></a>00482 |
394 | | <a name="l00483"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00483</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
395 | | <a name="l00484"></a>00484 <span class="keywordflow">if</span> (any (val < <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>) && any (val > <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>)) {<span class="keywordflow">return</span> inf;} |
396 | | <a name="l00485"></a>00485 <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
397 | | <a name="l00486"></a>00486 } |
398 | | <a name="l00487"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00487</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
399 | | <a name="l00488"></a>00488 vec smp (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
400 | | <a name="l00489"></a>00489 <span class="preprocessor">#pragma omp critical</span> |
401 | | <a name="l00490"></a>00490 <span class="preprocessor"></span> UniRNG.sample_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> , smp); |
402 | | <a name="l00491"></a>00491 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> + elem_mult (<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>, smp); |
403 | | <a name="l00492"></a>00492 } |
404 | | <a name="l00494"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00494</a> vec <a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226" title="set values of low and high ">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> -<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>) / 2.0;} |
405 | | <a name="l00495"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00495</a> vec <a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (pow (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, 2) + pow (<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>, 2) + elem_mult (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>)) / 3.0;} |
406 | | <a name="l00504"></a><a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">00504</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
407 | | <a name="l00505"></a>00505 <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
408 | | <a name="l00506"></a>00506 |
409 | | <a name="l00507"></a>00507 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, <span class="keyword">set</span>, <span class="stringliteral">"high"</span>, UI::compulsory); |
410 | | <a name="l00508"></a>00508 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>, <span class="keyword">set</span>, <span class="stringliteral">"low"</span>, UI::compulsory); |
411 | | <a name="l00509"></a>00509 } |
412 | | <a name="l00510"></a>00510 }; |
413 | | <a name="l00511"></a>00511 |
414 | | <a name="l00512"></a>00512 |
415 | | <a name="l00518"></a>00518 <span class="keyword">template</span> < <span class="keyword">class</span> sq_T, <span class="keyword">template</span> <<span class="keyword">typename</span>> <span class="keyword">class </span>TEpdf = enorm > |
416 | | <a name="l00519"></a><a class="code" href="classbdm_1_1mlnorm.html">00519</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> > |
417 | | <a name="l00520"></a>00520 { |
418 | | <a name="l00521"></a>00521 <span class="keyword">protected</span>: |
419 | | <a name="l00523"></a><a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42">00523</a> mat <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>; |
420 | | <a name="l00525"></a><a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6">00525</a> vec <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
421 | | <a name="l00526"></a>00526 <span class="comment">// vec& _mu; //cached epdf.mu; !!!!!! WHY NOT?</span> |
422 | | <a name="l00527"></a>00527 <span class="keyword">public</span>: |
423 | | <a name="l00530"></a>00530 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() {}; |
424 | | <a name="l00531"></a>00531 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> (<span class="keyword">const</span> mat &<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R) : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() { |
425 | | <a name="l00532"></a>00532 <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (A, mu0, R); |
426 | | <a name="l00533"></a>00533 } |
427 | | <a name="l00534"></a>00534 |
428 | | <a name="l00536"></a><a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5">00536</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0) { |
429 | | <a name="l00537"></a>00537 it_assert_debug (A0.rows() == mu0.length(), <span class="stringliteral">""</span>); |
430 | | <a name="l00538"></a>00538 it_assert_debug (A0.rows() == R0.rows(), <span class="stringliteral">""</span>); |
431 | | <a name="l00539"></a>00539 |
432 | | <a name="l00540"></a>00540 this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (A0.rows()), R0); |
433 | | <a name="l00541"></a>00541 <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
434 | | <a name="l00542"></a>00542 <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
435 | | <a name="l00543"></a>00543 this-><a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = A0.cols(); |
436 | | <a name="l00544"></a>00544 } |
437 | | <a name="l00547"></a><a class="code" href="classbdm_1_1mlnorm.html#c2895ae549ee76d961be98d7061bd110">00547</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#c2895ae549ee76d961be98d7061bd110">condition</a> (<span class="keyword">const</span> vec &cond) { |
438 | | <a name="l00548"></a>00548 this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
439 | | <a name="l00549"></a>00549 <span class="comment">//R is already assigned;</span> |
440 | | <a name="l00550"></a>00550 } |
441 | | <a name="l00551"></a>00551 |
442 | | <a name="l00553"></a><a class="code" href="classbdm_1_1mlnorm.html#6332e5200f3afa15db3f7f4bca09b17f">00553</a> vec& <a class="code" href="classbdm_1_1mlnorm.html#6332e5200f3afa15db3f7f4bca09b17f" title="access function">_mu_const</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>;} |
443 | | <a name="l00555"></a><a class="code" href="classbdm_1_1mlnorm.html#b256b547c5156b5898a3a1e5462f9540">00555</a> mat& <a class="code" href="classbdm_1_1mlnorm.html#b256b547c5156b5898a3a1e5462f9540" title="access function">_A</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>;} |
444 | | <a name="l00557"></a><a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e">00557</a> mat <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a>() { <span class="keywordflow">return</span> this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._R().to_mat(); } |
445 | | <a name="l00558"></a>00558 |
446 | | <a name="l00560"></a>00560 <span class="keyword">template</span><<span class="keyword">typename</span> sq_M> |
447 | | <a name="l00561"></a>00561 <span class="keyword">friend</span> std::ostream &operator<< (std::ostream &os, mlnorm<sq_M, enorm> &ml); |
448 | | <a name="l00562"></a>00562 |
449 | | <a name="l00563"></a><a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">00563</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
450 | | <a name="l00564"></a>00564 <a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">mpdf::from_setting</a> (<span class="keyword">set</span>); |
451 | | <a name="l00565"></a>00565 |
452 | | <a name="l00566"></a>00566 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">set</span>, <span class="stringliteral">"A"</span>, UI::compulsory); |
453 | | <a name="l00567"></a>00567 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, <span class="keyword">set</span>, <span class="stringliteral">"const"</span>, UI::compulsory); |
454 | | <a name="l00568"></a>00568 mat R0; |
455 | | <a name="l00569"></a>00569 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (R0, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::compulsory); |
456 | | <a name="l00570"></a>00570 <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, R0); |
457 | | <a name="l00571"></a>00571 }; |
458 | | <a name="l00572"></a>00572 }; |
459 | | <a name="l00573"></a>00573 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,ldmat); |
460 | | <a name="l00574"></a>00574 SHAREDPTR2 ( mlnorm, ldmat ); |
461 | | <a name="l00575"></a>00575 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,fsqmat); |
462 | | <a name="l00576"></a>00576 SHAREDPTR2 ( mlnorm, fsqmat ); |
463 | | <a name="l00577"></a>00577 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm, chmat); |
464 | | <a name="l00578"></a>00578 SHAREDPTR2 ( mlnorm, chmat ); |
465 | | <a name="l00579"></a>00579 |
466 | | <a name="l00581"></a>00581 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
467 | | <a name="l00582"></a><a class="code" href="classbdm_1_1mgnorm.html">00582</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgnorm.html" title="Mpdf with general function for mean value.">mgnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< enorm< sq_T > > |
468 | | <a name="l00583"></a>00583 { |
469 | | <a name="l00584"></a>00584 <span class="keyword">private</span>: |
470 | | <a name="l00585"></a>00585 <span class="comment">// vec &mu; WHY NOT?</span> |
471 | | <a name="l00586"></a>00586 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> g; |
472 | | <a name="l00587"></a>00587 |
473 | | <a name="l00588"></a>00588 <span class="keyword">public</span>: |
474 | | <a name="l00590"></a><a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d">00590</a> <a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d" title="default constructor">mgnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><sq_T> >() { } |
475 | | <a name="l00592"></a>00592 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b736332d20e418bf50d45836e129f339" title="set mean function">set_parameters</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> &g0, <span class="keyword">const</span> sq_T &R0); |
476 | | <a name="l00593"></a>00593 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d">condition</a> (<span class="keyword">const</span> vec &cond); |
477 | | <a name="l00594"></a>00594 |
478 | | <a name="l00595"></a>00595 |
479 | | <a name="l00623"></a><a class="code" href="classbdm_1_1mgnorm.html#d717dacc6a9eb967f8410994dc6dc6f9">00623</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#d717dacc6a9eb967f8410994dc6dc6f9">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
480 | | <a name="l00624"></a>00624 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> g = UI::build<fnc> (<span class="keyword">set</span>, <span class="stringliteral">"g"</span>, UI::compulsory); |
481 | | <a name="l00625"></a>00625 |
482 | | <a name="l00626"></a>00626 mat R; |
483 | | <a name="l00627"></a>00627 vec dR; |
484 | | <a name="l00628"></a>00628 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (dR, <span class="keyword">set</span>, <span class="stringliteral">"dR"</span>)) |
485 | | <a name="l00629"></a>00629 R = diag (dR); |
486 | | <a name="l00630"></a>00630 <span class="keywordflow">else</span> |
487 | | <a name="l00631"></a>00631 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (R, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::compulsory); |
488 | | <a name="l00632"></a>00632 |
489 | | <a name="l00633"></a>00633 <a class="code" href="classbdm_1_1mgnorm.html#b736332d20e418bf50d45836e129f339" title="set mean function">set_parameters</a> (g, R); |
490 | | <a name="l00634"></a>00634 } |
491 | | <a name="l00635"></a>00635 }; |
492 | | <a name="l00636"></a>00636 |
493 | | <a name="l00637"></a>00637 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mgnorm, chmat); |
494 | | <a name="l00638"></a>00638 SHAREDPTR2 ( mgnorm, chmat ); |
495 | | <a name="l00639"></a>00639 |
496 | | <a name="l00640"></a>00640 |
497 | | <a name="l00648"></a><a class="code" href="classbdm_1_1mlstudent.html">00648</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><ldmat, enorm> |
498 | | <a name="l00649"></a>00649 { |
499 | | <a name="l00650"></a>00650 <span class="keyword">protected</span>: |
500 | | <a name="l00652"></a><a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657">00652</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>; |
501 | | <a name="l00654"></a><a class="code" href="classbdm_1_1mlstudent.html#72e9bda4d6684e07faafc4b2192daf39">00654</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a>; |
502 | | <a name="l00656"></a><a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8">00656</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
503 | | <a name="l00657"></a>00657 <span class="keyword">public</span>: |
504 | | <a name="l00658"></a>00658 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> () : <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><<a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a>> (), |
505 | | <a name="l00659"></a>00659 <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> (), <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a>()) {} |
506 | | <a name="l00661"></a><a class="code" href="classbdm_1_1mlstudent.html#4cdf79aac1b2165c0290e73810a0e4a3">00661</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#4cdf79aac1b2165c0290e73810a0e4a3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0) { |
507 | | <a name="l00662"></a>00662 it_assert_debug (A0.rows() == mu0.length(), <span class="stringliteral">""</span>); |
508 | | <a name="l00663"></a>00663 it_assert_debug (R0.<a class="code" href="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>() == A0.rows(), <span class="stringliteral">""</span>); |
509 | | <a name="l00664"></a>00664 |
510 | | <a name="l00665"></a>00665 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> (mu0, <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>); <span class="comment">//</span> |
511 | | <a name="l00666"></a>00666 <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
512 | | <a name="l00667"></a>00667 <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
513 | | <a name="l00668"></a>00668 <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a> = R0; |
514 | | <a name="l00669"></a>00669 <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> = Lambda0; |
515 | | <a name="l00670"></a>00670 } |
516 | | <a name="l00671"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00671</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> (<span class="keyword">const</span> vec &cond) { |
517 | | <a name="l00672"></a>00672 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1enorm.html#766127847e9482aea9226ea157295ea2">_mu</a>() = <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
518 | | <a name="l00673"></a>00673 <span class="keywordtype">double</span> zeta; |
519 | | <a name="l00674"></a>00674 <span class="comment">//ugly hack!</span> |
520 | | <a name="l00675"></a>00675 <span class="keywordflow">if</span> ( (cond.length() + 1) == <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>()) { |
521 | | <a name="l00676"></a>00676 zeta = <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#f743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (concat (cond, vec_1 (1.0))); |
522 | | <a name="l00677"></a>00677 } <span class="keywordflow">else</span> { |
523 | | <a name="l00678"></a>00678 zeta = <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#f743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (cond); |
524 | | <a name="l00679"></a>00679 } |
525 | | <a name="l00680"></a>00680 <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a> = <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
526 | | <a name="l00681"></a>00681 <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a> *= (1 + zeta);<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
527 | | <a name="l00682"></a>00682 }; |
528 | | <a name="l00683"></a>00683 |
529 | | <a name="l00684"></a>00684 }; |
530 | | <a name="l00694"></a><a class="code" href="classbdm_1_1mgamma.html">00694</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><egamma> |
531 | | <a name="l00695"></a>00695 { |
532 | | <a name="l00696"></a>00696 <span class="keyword">protected</span>: |
533 | | <a name="l00697"></a>00697 |
534 | | <a name="l00699"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00699</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
535 | | <a name="l00700"></a>00700 |
536 | | <a name="l00702"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00702</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>; |
537 | | <a name="l00703"></a>00703 |
538 | | <a name="l00704"></a>00704 <span class="keyword">public</span>: |
539 | | <a name="l00706"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00706</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a>>(), <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> (0), |
540 | | <a name="l00707"></a>00707 <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>()) { |
541 | | <a name="l00708"></a>00708 } |
542 | | <a name="l00709"></a>00709 |
543 | | <a name="l00711"></a>00711 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> (<span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">const</span> vec &beta0); |
544 | | <a name="l00712"></a>00712 |
545 | | <a name="l00713"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00713</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">condition</a> (<span class="keyword">const</span> vec &val) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> = <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> / val;}; |
546 | | <a name="l00723"></a><a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">00723</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
547 | | <a name="l00724"></a>00724 <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">mpdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
548 | | <a name="l00725"></a>00725 vec betatmp; <span class="comment">// ugly but necessary</span> |
549 | | <a name="l00726"></a>00726 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (betatmp, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
550 | | <a name="l00727"></a>00727 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">set</span>, <span class="stringliteral">"k"</span>, UI::compulsory); |
551 | | <a name="l00728"></a>00728 <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> (<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, betatmp); |
552 | | <a name="l00729"></a>00729 } |
553 | | <a name="l00730"></a>00730 }; |
554 | | <a name="l00731"></a>00731 <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> (mgamma); |
555 | | <a name="l00732"></a>00732 SHAREDPTR (mgamma); |
556 | | <a name="l00733"></a>00733 |
557 | | <a name="l00743"></a><a class="code" href="classbdm_1_1migamma.html">00743</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eigamma> |
558 | | <a name="l00744"></a>00744 { |
559 | | <a name="l00745"></a>00745 <span class="keyword">protected</span>: |
560 | | <a name="l00747"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00747</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
561 | | <a name="l00748"></a>00748 |
562 | | <a name="l00750"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00750</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>; |
| 320 | <a name="l00350"></a>00350 beta += dt; |
| 321 | <a name="l00351"></a>00351 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>() - lll; |
| 322 | <a name="l00352"></a>00352 } |
| 323 | <a name="l00353"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00353</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* B) { |
| 324 | <a name="l00354"></a>00354 <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* E = <span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> (B); |
| 325 | <a name="l00355"></a>00355 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
| 326 | <a name="l00356"></a>00356 <span class="keyword">const</span> vec &Eb = E-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;<span class="comment">//const_cast<multiBM*> ( E )->_beta();</span> |
| 327 | <a name="l00357"></a>00357 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> *= (sum (Eb) / sum (<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>)); |
| 328 | <a name="l00358"></a>00358 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 329 | <a name="l00359"></a>00359 } |
| 330 | <a name="l00361"></a><a class="code" href="classbdm_1_1multiBM.html#31ff93f89473f099e489b9e1dc8d9513">00361</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>& <a class="code" href="classbdm_1_1multiBM.html#31ff93f89473f099e489b9e1dc8d9513" title="reimplemnetation of BM::posterior()">posterior</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
| 331 | <a name="l00363"></a><a class="code" href="classbdm_1_1multiBM.html#7a480eace4446661bacca94c57499f01">00363</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#7a480eace4446661bacca94c57499f01" title="constructor function">set_parameters</a> (<span class="keyword">const</span> vec &beta0) { |
| 332 | <a name="l00364"></a>00364 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#a06af2376976a33e1eceaed7e8da75a5">set_parameters</a> (beta0); |
| 333 | <a name="l00365"></a>00365 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a>) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 334 | <a name="l00366"></a>00366 } |
| 335 | <a name="l00367"></a>00367 }; |
| 336 | <a name="l00368"></a>00368 |
| 337 | <a name="l00378"></a><a class="code" href="classbdm_1_1egamma.html">00378</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
| 338 | <a name="l00379"></a>00379 { |
| 339 | <a name="l00380"></a>00380 <span class="keyword">protected</span>: |
| 340 | <a name="l00382"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00382</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
| 341 | <a name="l00384"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00384</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
| 342 | <a name="l00385"></a>00385 <span class="keyword">public</span> : |
| 343 | <a name="l00388"></a>00388 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> (), <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> (0), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> (0) {}; |
| 344 | <a name="l00389"></a>00389 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> (<span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b) {set_parameters (a, b);}; |
| 345 | <a name="l00390"></a>00390 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b) {<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> = a, <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> = b;<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length();}; |
| 346 | <a name="l00392"></a>00392 |
| 347 | <a name="l00393"></a>00393 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 348 | <a name="l00394"></a>00394 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="Evaluate normalized log-probability.">evallog</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
| 349 | <a name="l00395"></a>00395 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
| 350 | <a name="l00397"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00397</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns pointer to internal alpha. Potentially dengerous: use with care!">_alpha</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>;} |
| 351 | <a name="l00399"></a><a class="code" href="classbdm_1_1egamma.html#c42cadd9cbd344caaa69b0b433cd16ca">00399</a> vec& <a class="code" href="classbdm_1_1egamma.html#c42cadd9cbd344caaa69b0b433cd16ca" title="Returns pointer to internal beta. Potentially dengerous: use with care!">_beta</a>() {<span class="keywordflow">return</span> beta;} |
| 352 | <a name="l00400"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00400</a> vec <a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, beta);} |
| 353 | <a name="l00401"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00401</a> vec <a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, elem_mult (beta, beta)); } |
| 354 | <a name="l00402"></a>00402 |
| 355 | <a name="l00411"></a><a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">00411</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 356 | <a name="l00412"></a>00412 <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv</span> |
| 357 | <a name="l00413"></a>00413 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, <span class="keyword">set</span>, <span class="stringliteral">"alpha"</span>, UI::compulsory); |
| 358 | <a name="l00414"></a>00414 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (beta, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
| 359 | <a name="l00415"></a>00415 <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>(); |
| 360 | <a name="l00416"></a>00416 } |
| 361 | <a name="l00417"></a><a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127">00417</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>() { |
| 362 | <a name="l00418"></a>00418 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length() == beta.length(), <span class="stringliteral">"parameters do not match"</span>); |
| 363 | <a name="l00419"></a>00419 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length(); |
| 364 | <a name="l00420"></a>00420 } |
| 365 | <a name="l00421"></a>00421 }; |
| 366 | <a name="l00422"></a>00422 <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> (egamma); |
| 367 | <a name="l00423"></a>00423 SHAREDPTR ( egamma ); |
| 368 | <a name="l00424"></a>00424 |
| 369 | <a name="l00441"></a><a class="code" href="classbdm_1_1eigamma.html">00441</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> |
| 370 | <a name="l00442"></a>00442 { |
| 371 | <a name="l00443"></a>00443 <span class="keyword">protected</span>: |
| 372 | <a name="l00444"></a>00444 <span class="keyword">public</span> : |
| 373 | <a name="l00449"></a>00449 |
| 374 | <a name="l00450"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00450</a> vec <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1.0 / <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">egamma::sample</a>();}; |
| 375 | <a name="l00452"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00452</a> vec <a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div (<a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>, <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> - 1);} |
| 376 | <a name="l00453"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00453</a> vec <a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{vec mea = <a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>(); <span class="keywordflow">return</span> elem_div (elem_mult (mea, mea), <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> - 2);} |
| 377 | <a name="l00454"></a>00454 }; |
| 378 | <a name="l00455"></a>00455 <span class="comment">/*</span> |
| 379 | <a name="l00457"></a>00457 <span class="comment">class emix : public epdf {</span> |
| 380 | <a name="l00458"></a>00458 <span class="comment">protected:</span> |
| 381 | <a name="l00459"></a>00459 <span class="comment"> int n;</span> |
| 382 | <a name="l00460"></a>00460 <span class="comment"> vec &w;</span> |
| 383 | <a name="l00461"></a>00461 <span class="comment"> Array<epdf*> Coms;</span> |
| 384 | <a name="l00462"></a>00462 <span class="comment">public:</span> |
| 385 | <a name="l00464"></a>00464 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
| 386 | <a name="l00465"></a>00465 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
| 387 | <a name="l00466"></a>00466 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
| 388 | <a name="l00467"></a>00467 <span class="comment">};</span> |
| 389 | <a name="l00468"></a>00468 <span class="comment">*/</span> |
| 390 | <a name="l00469"></a>00469 |
| 391 | <a name="l00471"></a>00471 |
| 392 | <a name="l00472"></a><a class="code" href="classbdm_1_1euni.html">00472</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</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> |
| 393 | <a name="l00473"></a>00473 { |
| 394 | <a name="l00474"></a>00474 <span class="keyword">protected</span>: |
| 395 | <a name="l00476"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00476</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
| 396 | <a name="l00478"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00478</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
| 397 | <a name="l00480"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00480</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
| 398 | <a name="l00482"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00482</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
| 399 | <a name="l00484"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00484</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
| 400 | <a name="l00485"></a>00485 <span class="keyword">public</span>: |
| 401 | <a name="l00488"></a>00488 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> () : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> () {} |
| 402 | <a name="l00489"></a>00489 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> (<span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0) {set_parameters (low0, high0);} |
| 403 | <a name="l00490"></a>00490 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0) { |
| 404 | <a name="l00491"></a>00491 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0 - low0; |
| 405 | <a name="l00492"></a>00492 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (min (<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>) > 0.0, <span class="stringliteral">"bad support"</span>); |
| 406 | <a name="l00493"></a>00493 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
| 407 | <a name="l00494"></a>00494 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
| 408 | <a name="l00495"></a>00495 <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> = prod (1.0 / <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>); |
| 409 | <a name="l00496"></a>00496 <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a> = log (<a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>); |
| 410 | <a name="l00497"></a>00497 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(); |
| 411 | <a name="l00498"></a>00498 } |
| 412 | <a name="l00500"></a>00500 |
| 413 | <a name="l00501"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00501</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
| 414 | <a name="l00502"></a>00502 <span class="keywordflow">if</span> (any (val < <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>) && any (val > <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>)) {<span class="keywordflow">return</span> inf;} |
| 415 | <a name="l00503"></a>00503 <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
| 416 | <a name="l00504"></a>00504 } |
| 417 | <a name="l00505"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00505</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 418 | <a name="l00506"></a>00506 vec smp (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 419 | <a name="l00507"></a>00507 <span class="preprocessor">#pragma omp critical</span> |
| 420 | <a name="l00508"></a>00508 <span class="preprocessor"></span> UniRNG.sample_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> , smp); |
| 421 | <a name="l00509"></a>00509 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> + elem_mult (<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>, smp); |
| 422 | <a name="l00510"></a>00510 } |
| 423 | <a name="l00512"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00512</a> vec <a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226" title="set values of low and high ">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> -<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>) / 2.0;} |
| 424 | <a name="l00513"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00513</a> vec <a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (pow (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, 2) + pow (<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>, 2) + elem_mult (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>)) / 3.0;} |
| 425 | <a name="l00522"></a><a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">00522</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 426 | <a name="l00523"></a>00523 <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
| 427 | <a name="l00524"></a>00524 |
| 428 | <a name="l00525"></a>00525 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, <span class="keyword">set</span>, <span class="stringliteral">"high"</span>, UI::compulsory); |
| 429 | <a name="l00526"></a>00526 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>, <span class="keyword">set</span>, <span class="stringliteral">"low"</span>, UI::compulsory); |
| 430 | <a name="l00527"></a>00527 } |
| 431 | <a name="l00528"></a>00528 }; |
| 432 | <a name="l00529"></a>00529 |
| 433 | <a name="l00530"></a>00530 |
| 434 | <a name="l00536"></a>00536 <span class="keyword">template</span> < <span class="keyword">class</span> sq_T, <span class="keyword">template</span> <<span class="keyword">typename</span>> <span class="keyword">class </span>TEpdf = enorm > |
| 435 | <a name="l00537"></a><a class="code" href="classbdm_1_1mlnorm.html">00537</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> > |
| 436 | <a name="l00538"></a>00538 { |
| 437 | <a name="l00539"></a>00539 <span class="keyword">protected</span>: |
| 438 | <a name="l00541"></a><a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42">00541</a> mat <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>; |
| 439 | <a name="l00543"></a><a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6">00543</a> vec <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
| 440 | <a name="l00544"></a>00544 <span class="comment">// vec& _mu; //cached epdf.mu; !!!!!! WHY NOT?</span> |
| 441 | <a name="l00545"></a>00545 <span class="keyword">public</span>: |
| 442 | <a name="l00548"></a>00548 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() {}; |
| 443 | <a name="l00549"></a>00549 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> (<span class="keyword">const</span> mat &<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R) : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() { |
| 444 | <a name="l00550"></a>00550 <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (A, mu0, R); |
| 445 | <a name="l00551"></a>00551 } |
| 446 | <a name="l00552"></a>00552 |
| 447 | <a name="l00554"></a><a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5">00554</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0) { |
| 448 | <a name="l00555"></a>00555 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (A0.rows() == mu0.length(), <span class="stringliteral">"mlnorm: A vs. mu mismatch"</span>); |
| 449 | <a name="l00556"></a>00556 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (A0.rows() == R0.rows(), <span class="stringliteral">"mlnorm: A vs. R mismatch"</span>); |
| 450 | <a name="l00557"></a>00557 |
| 451 | <a name="l00558"></a>00558 this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (A0.rows()), R0); |
| 452 | <a name="l00559"></a>00559 <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
| 453 | <a name="l00560"></a>00560 <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
| 454 | <a name="l00561"></a>00561 this-><a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = A0.cols(); |
| 455 | <a name="l00562"></a>00562 } |
| 456 | <a name="l00565"></a><a class="code" href="classbdm_1_1mlnorm.html#c2895ae549ee76d961be98d7061bd110">00565</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#c2895ae549ee76d961be98d7061bd110">condition</a> (<span class="keyword">const</span> vec &cond) { |
| 457 | <a name="l00566"></a>00566 this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
| 458 | <a name="l00567"></a>00567 <span class="comment">//R is already assigned;</span> |
| 459 | <a name="l00568"></a>00568 } |
| 460 | <a name="l00569"></a>00569 |
| 461 | <a name="l00571"></a><a class="code" href="classbdm_1_1mlnorm.html#6332e5200f3afa15db3f7f4bca09b17f">00571</a> vec& <a class="code" href="classbdm_1_1mlnorm.html#6332e5200f3afa15db3f7f4bca09b17f" title="access function">_mu_const</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>;} |
| 462 | <a name="l00573"></a><a class="code" href="classbdm_1_1mlnorm.html#b256b547c5156b5898a3a1e5462f9540">00573</a> mat& <a class="code" href="classbdm_1_1mlnorm.html#b256b547c5156b5898a3a1e5462f9540" title="access function">_A</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>;} |
| 463 | <a name="l00575"></a><a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e">00575</a> mat <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a>() { <span class="keywordflow">return</span> this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._R().to_mat(); } |
| 464 | <a name="l00576"></a>00576 |
| 465 | <a name="l00578"></a>00578 <span class="keyword">template</span><<span class="keyword">typename</span> sq_M> |
| 466 | <a name="l00579"></a>00579 <span class="keyword">friend</span> std::ostream &operator<< (std::ostream &os, mlnorm<sq_M, enorm> &ml); |
| 467 | <a name="l00580"></a>00580 |
| 468 | <a name="l00581"></a><a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">00581</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 469 | <a name="l00582"></a>00582 <a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">mpdf::from_setting</a> (<span class="keyword">set</span>); |
| 470 | <a name="l00583"></a>00583 |
| 471 | <a name="l00584"></a>00584 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">set</span>, <span class="stringliteral">"A"</span>, UI::compulsory); |
| 472 | <a name="l00585"></a>00585 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, <span class="keyword">set</span>, <span class="stringliteral">"const"</span>, UI::compulsory); |
| 473 | <a name="l00586"></a>00586 mat R0; |
| 474 | <a name="l00587"></a>00587 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (R0, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::compulsory); |
| 475 | <a name="l00588"></a>00588 <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, R0); |
| 476 | <a name="l00589"></a>00589 }; |
| 477 | <a name="l00590"></a>00590 }; |
| 478 | <a name="l00591"></a>00591 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,ldmat); |
| 479 | <a name="l00592"></a>00592 SHAREDPTR2 ( mlnorm, ldmat ); |
| 480 | <a name="l00593"></a>00593 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,fsqmat); |
| 481 | <a name="l00594"></a>00594 SHAREDPTR2 ( mlnorm, fsqmat ); |
| 482 | <a name="l00595"></a>00595 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm, chmat); |
| 483 | <a name="l00596"></a>00596 SHAREDPTR2 ( mlnorm, chmat ); |
| 484 | <a name="l00597"></a>00597 |
| 485 | <a name="l00599"></a>00599 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 486 | <a name="l00600"></a><a class="code" href="classbdm_1_1mgnorm.html">00600</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgnorm.html" title="Mpdf with general function for mean value.">mgnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< enorm< sq_T > > |
| 487 | <a name="l00601"></a>00601 { |
| 488 | <a name="l00602"></a>00602 <span class="keyword">private</span>: |
| 489 | <a name="l00603"></a>00603 <span class="comment">// vec &mu; WHY NOT?</span> |
| 490 | <a name="l00604"></a>00604 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> g; |
| 491 | <a name="l00605"></a>00605 |
| 492 | <a name="l00606"></a>00606 <span class="keyword">public</span>: |
| 493 | <a name="l00608"></a><a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d">00608</a> <a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d" title="default constructor">mgnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><sq_T> >() { } |
| 494 | <a name="l00610"></a>00610 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b736332d20e418bf50d45836e129f339" title="set mean function">set_parameters</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> &g0, <span class="keyword">const</span> sq_T &R0); |
| 495 | <a name="l00611"></a>00611 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d">condition</a> (<span class="keyword">const</span> vec &cond); |
| 496 | <a name="l00612"></a>00612 |
| 497 | <a name="l00613"></a>00613 |
| 498 | <a name="l00641"></a><a class="code" href="classbdm_1_1mgnorm.html#d717dacc6a9eb967f8410994dc6dc6f9">00641</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#d717dacc6a9eb967f8410994dc6dc6f9">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 499 | <a name="l00642"></a>00642 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> g = UI::build<fnc> (<span class="keyword">set</span>, <span class="stringliteral">"g"</span>, UI::compulsory); |
| 500 | <a name="l00643"></a>00643 |
| 501 | <a name="l00644"></a>00644 mat R; |
| 502 | <a name="l00645"></a>00645 vec dR; |
| 503 | <a name="l00646"></a>00646 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (dR, <span class="keyword">set</span>, <span class="stringliteral">"dR"</span>)) |
| 504 | <a name="l00647"></a>00647 R = diag (dR); |
| 505 | <a name="l00648"></a>00648 <span class="keywordflow">else</span> |
| 506 | <a name="l00649"></a>00649 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (R, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::compulsory); |
| 507 | <a name="l00650"></a>00650 |
| 508 | <a name="l00651"></a>00651 <a class="code" href="classbdm_1_1mgnorm.html#b736332d20e418bf50d45836e129f339" title="set mean function">set_parameters</a> (g, R); |
| 509 | <a name="l00652"></a>00652 } |
| 510 | <a name="l00653"></a>00653 }; |
| 511 | <a name="l00654"></a>00654 |
| 512 | <a name="l00655"></a>00655 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mgnorm, chmat); |
| 513 | <a name="l00656"></a>00656 SHAREDPTR2 ( mgnorm, chmat ); |
| 514 | <a name="l00657"></a>00657 |
| 515 | <a name="l00658"></a>00658 |
| 516 | <a name="l00666"></a><a class="code" href="classbdm_1_1mlstudent.html">00666</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><ldmat, enorm> |
| 517 | <a name="l00667"></a>00667 { |
| 518 | <a name="l00668"></a>00668 <span class="keyword">protected</span>: |
| 519 | <a name="l00670"></a><a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657">00670</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>; |
| 520 | <a name="l00672"></a><a class="code" href="classbdm_1_1mlstudent.html#72e9bda4d6684e07faafc4b2192daf39">00672</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a>; |
| 521 | <a name="l00674"></a><a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8">00674</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
| 522 | <a name="l00675"></a>00675 <span class="keyword">public</span>: |
| 523 | <a name="l00676"></a>00676 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> () : <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><<a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a>> (), |
| 524 | <a name="l00677"></a>00677 <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> (), <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a>()) {} |
| 525 | <a name="l00679"></a><a class="code" href="classbdm_1_1mlstudent.html#4cdf79aac1b2165c0290e73810a0e4a3">00679</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#4cdf79aac1b2165c0290e73810a0e4a3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0) { |
| 526 | <a name="l00680"></a>00680 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (A0.rows() == mu0.length(), <span class="stringliteral">"mlstudent: A vs. mu mismatch"</span>); |
| 527 | <a name="l00681"></a>00681 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (R0.<a class="code" href="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>() == A0.rows(), <span class="stringliteral">"mlstudent: A vs. R mismatch"</span>); |
| 528 | <a name="l00682"></a>00682 |
| 529 | <a name="l00683"></a>00683 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> (mu0, R0);<span class="comment">// was Lambda, why?</span> |
| 530 | <a name="l00684"></a>00684 <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
| 531 | <a name="l00685"></a>00685 <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
| 532 | <a name="l00686"></a>00686 <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a> = R0; |
| 533 | <a name="l00687"></a>00687 <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> = Lambda0; |
| 534 | <a name="l00688"></a>00688 } |
| 535 | <a name="l00689"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00689</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> (<span class="keyword">const</span> vec &cond) { |
| 536 | <a name="l00690"></a>00690 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1enorm.html#766127847e9482aea9226ea157295ea2">_mu</a>() = <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
| 537 | <a name="l00691"></a>00691 <span class="keywordtype">double</span> zeta; |
| 538 | <a name="l00692"></a>00692 <span class="comment">//ugly hack!</span> |
| 539 | <a name="l00693"></a>00693 <span class="keywordflow">if</span> ( (cond.length() + 1) == <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>()) { |
| 540 | <a name="l00694"></a>00694 zeta = <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#f743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (concat (cond, vec_1 (1.0))); |
| 541 | <a name="l00695"></a>00695 } <span class="keywordflow">else</span> { |
| 542 | <a name="l00696"></a>00696 zeta = <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#f743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (cond); |
| 543 | <a name="l00697"></a>00697 } |
| 544 | <a name="l00698"></a>00698 <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a> = <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
| 545 | <a name="l00699"></a>00699 <a class="code" href="classbdm_1_1mlnorm.html#564715dea56f7bbff0083aec295ce97e" title="access function">_R</a> *= (1 + zeta);<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
| 546 | <a name="l00700"></a>00700 }; |
| 547 | <a name="l00701"></a>00701 |
| 548 | <a name="l00702"></a>00702 }; |
| 549 | <a name="l00712"></a><a class="code" href="classbdm_1_1mgamma.html">00712</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><egamma> |
| 550 | <a name="l00713"></a>00713 { |
| 551 | <a name="l00714"></a>00714 <span class="keyword">protected</span>: |
| 552 | <a name="l00715"></a>00715 |
| 553 | <a name="l00717"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00717</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
| 554 | <a name="l00718"></a>00718 |
| 555 | <a name="l00720"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00720</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>; |
| 556 | <a name="l00721"></a>00721 |
| 557 | <a name="l00722"></a>00722 <span class="keyword">public</span>: |
| 558 | <a name="l00724"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00724</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a>>(), <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> (0), |
| 559 | <a name="l00725"></a>00725 <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>()) { |
| 560 | <a name="l00726"></a>00726 } |
| 561 | <a name="l00727"></a>00727 |
| 562 | <a name="l00729"></a>00729 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> (<span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">const</span> vec &beta0); |
| 563 | <a name="l00730"></a>00730 |
| 564 | <a name="l00731"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00731</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">condition</a> (<span class="keyword">const</span> vec &val) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> = <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> / val;}; |
| 565 | <a name="l00741"></a><a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">00741</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 566 | <a name="l00742"></a>00742 <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">mpdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
| 567 | <a name="l00743"></a>00743 vec betatmp; <span class="comment">// ugly but necessary</span> |
| 568 | <a name="l00744"></a>00744 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (betatmp, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
| 569 | <a name="l00745"></a>00745 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">set</span>, <span class="stringliteral">"k"</span>, UI::compulsory); |
| 570 | <a name="l00746"></a>00746 <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> (<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, betatmp); |
| 571 | <a name="l00747"></a>00747 } |
| 572 | <a name="l00748"></a>00748 }; |
| 573 | <a name="l00749"></a>00749 <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> (mgamma); |
| 574 | <a name="l00750"></a>00750 SHAREDPTR (mgamma); |
589 | | <a name="l00782"></a>00782 |
590 | | <a name="l00794"></a><a class="code" href="classbdm_1_1mgamma__fix.html">00794</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma__fix.html" title="Gamma random walk around a fixed point.">mgamma_fix</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> |
591 | | <a name="l00795"></a>00795 { |
592 | | <a name="l00796"></a>00796 <span class="keyword">protected</span>: |
593 | | <a name="l00798"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa">00798</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>; |
594 | | <a name="l00800"></a><a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2">00800</a> vec <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>; |
595 | | <a name="l00801"></a>00801 <span class="keyword">public</span>: |
596 | | <a name="l00803"></a><a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d">00803</a> <a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d" title="Constructor.">mgamma_fix</a> () : <a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> (), <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a> () {}; |
597 | | <a name="l00805"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2">00805</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2" title="Set value of k.">set_parameters</a> (<span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0) { |
598 | | <a name="l00806"></a>00806 <a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2" title="Set value of k.">mgamma::set_parameters</a> (k0, ref0); |
599 | | <a name="l00807"></a>00807 <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a> = pow (ref0, 1.0 - l0);<a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a> = l0; |
600 | | <a name="l00808"></a>00808 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
601 | | <a name="l00809"></a>00809 }; |
602 | | <a name="l00810"></a>00810 |
603 | | <a name="l00811"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">00811</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">condition</a> (<span class="keyword">const</span> vec &val) {vec mean = elem_mult (<a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>, pow (val, <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>)); <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> = <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> / mean;}; |
604 | | <a name="l00812"></a>00812 }; |
605 | | <a name="l00813"></a>00813 |
606 | | <a name="l00814"></a>00814 |
607 | | <a name="l00827"></a><a class="code" href="classbdm_1_1migamma__ref.html">00827</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma__ref.html" title="Inverse-Gamma random walk around a fixed point.">migamma_ref</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> |
608 | | <a name="l00828"></a>00828 { |
609 | | <a name="l00829"></a>00829 <span class="keyword">protected</span>: |
610 | | <a name="l00831"></a><a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d">00831</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>; |
611 | | <a name="l00833"></a><a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6">00833</a> vec <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>; |
612 | | <a name="l00834"></a>00834 <span class="keyword">public</span>: |
613 | | <a name="l00836"></a><a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f">00836</a> <a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f" title="Constructor.">migamma_ref</a> () : <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> (), <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a> () {}; |
614 | | <a name="l00838"></a><a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800">00838</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">set_parameters</a> (<span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0) { |
615 | | <a name="l00839"></a>00839 <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">migamma::set_parameters</a> (ref0.length(), k0); |
616 | | <a name="l00840"></a>00840 <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a> = pow (ref0, 1.0 - l0); |
617 | | <a name="l00841"></a>00841 <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a> = l0; |
618 | | <a name="l00842"></a>00842 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
619 | | <a name="l00843"></a>00843 }; |
620 | | <a name="l00844"></a>00844 |
621 | | <a name="l00845"></a><a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">00845</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">condition</a> (<span class="keyword">const</span> vec &val) { |
622 | | <a name="l00846"></a>00846 vec mean = elem_mult (<a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>, pow (val, <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>)); |
623 | | <a name="l00847"></a>00847 <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">migamma::condition</a> (mean); |
624 | | <a name="l00848"></a>00848 }; |
625 | | <a name="l00849"></a>00849 |
626 | | <a name="l00870"></a>00870 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#9e7e0f7d2aa9ecca8ec1af8cbcb5ef1d">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>); |
627 | | <a name="l00871"></a>00871 |
628 | | <a name="l00872"></a>00872 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
629 | | <a name="l00873"></a>00873 }; |
630 | | <a name="l00874"></a>00874 |
631 | | <a name="l00875"></a>00875 |
632 | | <a name="l00876"></a>00876 <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> (migamma_ref); |
633 | | <a name="l00877"></a>00877 SHAREDPTR (migamma_ref); |
634 | | <a name="l00878"></a>00878 |
635 | | <a name="l00888"></a><a class="code" href="classbdm_1_1elognorm.html">00888</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1elognorm.html">elognorm</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><ldmat> |
636 | | <a name="l00889"></a>00889 { |
637 | | <a name="l00890"></a>00890 <span class="keyword">public</span>: |
638 | | <a name="l00891"></a><a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba">00891</a> vec <a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> exp (<a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<ldmat>::sample</a>());}; |
639 | | <a name="l00892"></a><a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea">00892</a> vec <a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec var = <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">enorm<ldmat>::variance</a>();<span class="keywordflow">return</span> exp (<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> - 0.5*var);}; |
| 592 | <a name="l00782"></a>00782 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> &m) : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a>>(), |
| 593 | <a name="l00783"></a>00783 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> (0), |
| 594 | <a name="l00784"></a>00784 <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>()), |
| 595 | <a name="l00785"></a>00785 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a>()) { |
| 596 | <a name="l00786"></a>00786 } |
| 597 | <a name="l00788"></a>00788 |
| 598 | <a name="l00790"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00790</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151" title="Set value of k.">set_parameters</a> (<span class="keywordtype">int</span> len, <span class="keywordtype">double</span> k0) { |
| 599 | <a name="l00791"></a>00791 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> = k0; |
| 600 | <a name="l00792"></a>00792 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1egamma.html#749f82293ff23a8319c1bf52489d2ed2">set_parameters</a> ( (1.0 / (<a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>*<a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>) + 2.0) *ones (len) <span class="comment">/*alpha*/</span>, ones (len) <span class="comment">/*beta*/</span>); |
| 601 | <a name="l00793"></a>00793 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
| 602 | <a name="l00794"></a>00794 }; |
| 603 | <a name="l00795"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00795</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">condition</a> (<span class="keyword">const</span> vec &val) { |
| 604 | <a name="l00796"></a>00796 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> = elem_mult (val, (<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> - 1.0)); |
| 605 | <a name="l00797"></a>00797 }; |
| 606 | <a name="l00798"></a>00798 }; |
| 607 | <a name="l00799"></a>00799 |
| 608 | <a name="l00800"></a>00800 |
| 609 | <a name="l00812"></a><a class="code" href="classbdm_1_1mgamma__fix.html">00812</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma__fix.html" title="Gamma random walk around a fixed point.">mgamma_fix</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> |
| 610 | <a name="l00813"></a>00813 { |
| 611 | <a name="l00814"></a>00814 <span class="keyword">protected</span>: |
| 612 | <a name="l00816"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa">00816</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>; |
| 613 | <a name="l00818"></a><a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2">00818</a> vec <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>; |
| 614 | <a name="l00819"></a>00819 <span class="keyword">public</span>: |
| 615 | <a name="l00821"></a><a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d">00821</a> <a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d" title="Constructor.">mgamma_fix</a> () : <a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> (), <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a> () {}; |
| 616 | <a name="l00823"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2">00823</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2" title="Set value of k.">set_parameters</a> (<span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0) { |
| 617 | <a name="l00824"></a>00824 <a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2" title="Set value of k.">mgamma::set_parameters</a> (k0, ref0); |
| 618 | <a name="l00825"></a>00825 <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a> = pow (ref0, 1.0 - l0);<a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a> = l0; |
| 619 | <a name="l00826"></a>00826 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
| 620 | <a name="l00827"></a>00827 }; |
| 621 | <a name="l00828"></a>00828 |
| 622 | <a name="l00829"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">00829</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">condition</a> (<span class="keyword">const</span> vec &val) {vec mean = elem_mult (<a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>, pow (val, <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>)); <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> = <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> / mean;}; |
| 623 | <a name="l00830"></a>00830 }; |
| 624 | <a name="l00831"></a>00831 |
| 625 | <a name="l00832"></a>00832 |
| 626 | <a name="l00845"></a><a class="code" href="classbdm_1_1migamma__ref.html">00845</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma__ref.html" title="Inverse-Gamma random walk around a fixed point.">migamma_ref</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> |
| 627 | <a name="l00846"></a>00846 { |
| 628 | <a name="l00847"></a>00847 <span class="keyword">protected</span>: |
| 629 | <a name="l00849"></a><a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d">00849</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>; |
| 630 | <a name="l00851"></a><a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6">00851</a> vec <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>; |
| 631 | <a name="l00852"></a>00852 <span class="keyword">public</span>: |
| 632 | <a name="l00854"></a><a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f">00854</a> <a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f" title="Constructor.">migamma_ref</a> () : <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> (), <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a> () {}; |
| 633 | <a name="l00856"></a><a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800">00856</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">set_parameters</a> (<span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0) { |
| 634 | <a name="l00857"></a>00857 <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">migamma::set_parameters</a> (ref0.length(), k0); |
| 635 | <a name="l00858"></a>00858 <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a> = pow (ref0, 1.0 - l0); |
| 636 | <a name="l00859"></a>00859 <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a> = l0; |
| 637 | <a name="l00860"></a>00860 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
| 638 | <a name="l00861"></a>00861 }; |
| 639 | <a name="l00862"></a>00862 |
| 640 | <a name="l00863"></a><a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">00863</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">condition</a> (<span class="keyword">const</span> vec &val) { |
| 641 | <a name="l00864"></a>00864 vec mean = elem_mult (<a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>, pow (val, <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>)); |
| 642 | <a name="l00865"></a>00865 <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">migamma::condition</a> (mean); |
| 643 | <a name="l00866"></a>00866 }; |
| 644 | <a name="l00867"></a>00867 |
| 645 | <a name="l00888"></a>00888 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#9e7e0f7d2aa9ecca8ec1af8cbcb5ef1d">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>); |
| 646 | <a name="l00889"></a>00889 |
| 647 | <a name="l00890"></a>00890 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
| 648 | <a name="l00891"></a>00891 }; |
| 649 | <a name="l00892"></a>00892 |
641 | | <a name="l00894"></a>00894 }; |
642 | | <a name="l00895"></a>00895 |
643 | | <a name="l00907"></a><a class="code" href="classbdm_1_1mlognorm.html">00907</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlognorm.html" title="Log-Normal random walk.">mlognorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><elognorm> |
644 | | <a name="l00908"></a>00908 { |
645 | | <a name="l00909"></a>00909 <span class="keyword">protected</span>: |
646 | | <a name="l00911"></a><a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a">00911</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
647 | | <a name="l00912"></a>00912 |
648 | | <a name="l00914"></a><a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2">00914</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
649 | | <a name="l00915"></a>00915 <span class="keyword">public</span>: |
650 | | <a name="l00917"></a><a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41">00917</a> <a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1elognorm.html">elognorm</a>>(), |
651 | | <a name="l00918"></a>00918 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> (0), |
652 | | <a name="l00919"></a>00919 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu()) { |
653 | | <a name="l00920"></a>00920 } |
654 | | <a name="l00921"></a>00921 |
655 | | <a name="l00923"></a><a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f">00923</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f" title="Set value of k.">set_parameters</a> (<span class="keywordtype">int</span> size, <span class="keywordtype">double</span> k) { |
656 | | <a name="l00924"></a>00924 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5 * log (k * k + 1); |
657 | | <a name="l00925"></a>00925 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> (zeros (size), 2*<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye (size)); |
658 | | <a name="l00926"></a>00926 |
659 | | <a name="l00927"></a>00927 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
660 | | <a name="l00928"></a>00928 }; |
661 | | <a name="l00929"></a>00929 |
662 | | <a name="l00930"></a><a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">00930</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">condition</a> (<span class="keyword">const</span> vec &val) { |
663 | | <a name="l00931"></a>00931 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> = log (val) - <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>;<span class="comment">//elem_mult ( refl,pow ( val,l ) );</span> |
664 | | <a name="l00932"></a>00932 }; |
665 | | <a name="l00933"></a>00933 |
666 | | <a name="l00952"></a>00952 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#49e45ea13a869da607ef9be7a229128a">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>); |
667 | | <a name="l00953"></a>00953 |
668 | | <a name="l00954"></a>00954 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
669 | | <a name="l00955"></a>00955 |
670 | | <a name="l00956"></a>00956 }; |
671 | | <a name="l00957"></a>00957 |
672 | | <a name="l00958"></a>00958 <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> (mlognorm); |
673 | | <a name="l00959"></a>00959 SHAREDPTR (mlognorm); |
674 | | <a name="l00960"></a>00960 |
675 | | <a name="l00964"></a><a class="code" href="classbdm_1_1eWishartCh.html">00964</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</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> |
676 | | <a name="l00965"></a>00965 { |
677 | | <a name="l00966"></a>00966 <span class="keyword">protected</span>: |
678 | | <a name="l00968"></a><a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490">00968</a> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>; |
679 | | <a name="l00970"></a><a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f">00970</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; |
680 | | <a name="l00972"></a><a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3">00972</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>; |
681 | | <a name="l00973"></a>00973 <span class="keyword">public</span>: |
682 | | <a name="l00975"></a><a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0">00975</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (<span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) {<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a> = <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> (Y0);<a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a> = delta0; <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> = <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>(); <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> * <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; } |
683 | | <a name="l00977"></a><a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339">00977</a> mat <a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()<span class="keyword"> const </span>{ |
684 | | <a name="l00978"></a>00978 mat X = zeros (<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>, <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>); |
685 | | <a name="l00979"></a>00979 |
686 | | <a name="l00980"></a>00980 <span class="comment">//sample diagonal</span> |
687 | | <a name="l00981"></a>00981 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>;i++) { |
688 | | <a name="l00982"></a>00982 GamRNG.setup (0.5* (<a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a> - i) , 0.5); <span class="comment">// no +1 !! index if from 0</span> |
689 | | <a name="l00983"></a>00983 <span class="preprocessor">#pragma omp critical</span> |
690 | | <a name="l00984"></a>00984 <span class="preprocessor"></span> X (i, i) = sqrt (GamRNG()); |
691 | | <a name="l00985"></a>00985 } |
692 | | <a name="l00986"></a>00986 <span class="comment">//do the rest</span> |
693 | | <a name="l00987"></a>00987 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < p;i++) { |
694 | | <a name="l00988"></a>00988 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = i + 1;j < p;j++) { |
695 | | <a name="l00989"></a>00989 <span class="preprocessor">#pragma omp critical</span> |
696 | | <a name="l00990"></a>00990 <span class="preprocessor"></span> X (i, j) = NorRNG.sample(); |
697 | | <a name="l00991"></a>00991 } |
698 | | <a name="l00992"></a>00992 } |
699 | | <a name="l00993"></a>00993 <span class="keywordflow">return</span> X*<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>();<span class="comment">// return upper triangular part of the decomposition</span> |
700 | | <a name="l00994"></a>00994 } |
701 | | <a name="l00995"></a><a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a">00995</a> vec <a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a" title="Returns a sample, from density .">sample</a> ()<span class="keyword"> const </span>{ |
702 | | <a name="l00996"></a>00996 <span class="keywordflow">return</span> vec (<a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()._data(), <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>*<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>); |
703 | | <a name="l00997"></a>00997 } |
704 | | <a name="l00999"></a><a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981">00999</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> (<span class="keyword">const</span> mat &Ch0) {copy_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, Ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data());} |
705 | | <a name="l01001"></a><a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a">01001</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a" title="fast access function y0 will be copied into Y.Ch.">_setY</a> (<span class="keyword">const</span> vec &ch0) {copy_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); } |
706 | | <a name="l01003"></a><a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e">01003</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& <a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>;} |
707 | | <a name="l01004"></a>01004 }; |
708 | | <a name="l01005"></a>01005 |
709 | | <a name="l01007"></a>01007 |
710 | | <a name="l01009"></a><a class="code" href="classbdm_1_1eiWishartCh.html">01009</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eiWishartCh.html" title="Inverse Wishart on Choleski decomposition.">eiWishartCh</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> |
711 | | <a name="l01010"></a>01010 { |
712 | | <a name="l01011"></a>01011 <span class="keyword">protected</span>: |
713 | | <a name="l01013"></a><a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a">01013</a> <a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</a> <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>; |
714 | | <a name="l01015"></a><a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd">01015</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>; |
715 | | <a name="l01017"></a><a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464">01017</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a>; |
716 | | <a name="l01018"></a>01018 <span class="keyword">public</span>: |
717 | | <a name="l01020"></a><a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3">01020</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) { |
718 | | <a name="l01021"></a>01021 <a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> = delta0; |
719 | | <a name="l01022"></a>01022 <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (inv (Y0), delta0); |
720 | | <a name="l01023"></a>01023 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a> = Y0.rows(); |
721 | | <a name="l01024"></a>01024 } |
722 | | <a name="l01025"></a><a class="code" href="classbdm_1_1eiWishartCh.html#2f668192cc9c2e3a5b7e608164685a3e">01025</a> vec <a class="code" href="classbdm_1_1eiWishartCh.html#2f668192cc9c2e3a5b7e608164685a3e" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{mat iCh; iCh = inv (<a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()); <span class="keywordflow">return</span> vec (iCh._data(), <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>);} |
723 | | <a name="l01027"></a><a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5">01027</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<span class="keyword">const</span> vec &y0) { |
724 | | <a name="l01028"></a>01028 mat Ch (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
725 | | <a name="l01029"></a>01029 mat iCh (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
726 | | <a name="l01030"></a>01030 copy_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, y0._data(), Ch._data()); |
727 | | <a name="l01031"></a>01031 |
728 | | <a name="l01032"></a>01032 iCh = inv (Ch); |
729 | | <a name="l01033"></a>01033 <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> (iCh); |
730 | | <a name="l01034"></a>01034 } |
731 | | <a name="l01035"></a><a class="code" href="classbdm_1_1eiWishartCh.html#a6ddbd815b8b666dd542e97f009f89bb">01035</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#a6ddbd815b8b666dd542e97f009f89bb">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
732 | | <a name="l01036"></a>01036 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> X (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
733 | | <a name="l01037"></a>01037 <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& Y = <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>(); |
734 | | <a name="l01038"></a>01038 |
735 | | <a name="l01039"></a>01039 copy_vector (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>*<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, val._data(), X.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); |
736 | | <a name="l01040"></a>01040 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> iX (p);X.<a class="code" href="classbdm_1_1chmat.html#cbf3389db96dff41fb2e9532d59b13c0" title="Inversion in the same form, i.e. cholesky.">inv</a> (iX); |
737 | | <a name="l01041"></a>01041 <span class="comment">// compute</span> |
738 | | <a name="l01042"></a>01042 <span class="comment">// \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)},</span> |
739 | | <a name="l01043"></a>01043 mat M = Y.<a class="code" href="classbdm_1_1chmat.html#4b4c5d4dbb8a3d585b68d936cb6df31b" title="Conversion to full matrix.">to_mat</a>() * iX.to_mat(); |
740 | | <a name="l01044"></a>01044 |
741 | | <a name="l01045"></a>01045 <span class="keywordtype">double</span> log1 = 0.5 * p * (2 * Y.<a class="code" href="classbdm_1_1chmat.html#949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * (<a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> + p + 1) * (2 * X.<a class="code" href="classbdm_1_1chmat.html#949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * trace (M); |
742 | | <a name="l01046"></a>01046 <span class="comment">//Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!!</span> |
743 | | <a name="l01047"></a>01047 |
744 | | <a name="l01048"></a>01048 <span class="comment">/* if (0) {</span> |
745 | | <a name="l01049"></a>01049 <span class="comment"> mat XX=X.to_mat();</span> |
746 | | <a name="l01050"></a>01050 <span class="comment"> mat YY=Y.to_mat();</span> |
747 | | <a name="l01051"></a>01051 <span class="comment"></span> |
748 | | <a name="l01052"></a>01052 <span class="comment"> double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX));</span> |
749 | | <a name="l01053"></a>01053 <span class="comment"> cout << log1 << "," << log2 << endl;</span> |
750 | | <a name="l01054"></a>01054 <span class="comment"> }*/</span> |
751 | | <a name="l01055"></a>01055 <span class="keywordflow">return</span> log1; |
752 | | <a name="l01056"></a>01056 }; |
753 | | <a name="l01057"></a>01057 |
754 | | <a name="l01058"></a>01058 }; |
755 | | <a name="l01059"></a>01059 |
756 | | <a name="l01061"></a><a class="code" href="classbdm_1_1rwiWishartCh.html">01061</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eiWishartCh> |
757 | | <a name="l01062"></a>01062 { |
758 | | <a name="l01063"></a>01063 <span class="keyword">protected</span>: |
759 | | <a name="l01065"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb">01065</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>; |
760 | | <a name="l01067"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a">01067</a> vec <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a>; |
761 | | <a name="l01069"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861">01069</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>; |
762 | | <a name="l01071"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663">01071</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>; |
763 | | <a name="l01072"></a>01072 |
764 | | <a name="l01073"></a>01073 <span class="keyword">public</span>: |
765 | | <a name="l01074"></a>01074 <a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a>() : <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> (0) {} |
766 | | <a name="l01076"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#28549ee3ce1ff8509360171ea3cf717c">01076</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#28549ee3ce1ff8509360171ea3cf717c" title="constructor function">set_parameters</a> (<span class="keywordtype">int</span> p0, <span class="keywordtype">double</span> k, vec ref0, <span class="keywordtype">double</span> l0) { |
767 | | <a name="l01077"></a>01077 <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> = p0; |
768 | | <a name="l01078"></a>01078 <span class="keywordtype">double</span> delta = 2 / (k * k) + <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> + 3; |
769 | | <a name="l01079"></a>01079 <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> = sqrt (delta - <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> - 1); |
770 | | <a name="l01080"></a>01080 <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> = l0; |
771 | | <a name="l01081"></a>01081 <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> = pow (ref0, 1 - <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>); |
772 | | <a name="l01082"></a>01082 |
773 | | <a name="l01083"></a>01083 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (eye (<a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>), delta); |
774 | | <a name="l01084"></a>01084 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); |
775 | | <a name="l01085"></a>01085 } |
776 | | <a name="l01086"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#ac087ba6c885d3faeda9171229f9b4e6">01086</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#ac087ba6c885d3faeda9171229f9b4e6">condition</a> (<span class="keyword">const</span> vec &c) { |
777 | | <a name="l01087"></a>01087 vec z = c; |
778 | | <a name="l01088"></a>01088 <span class="keywordtype">int</span> ri = 0; |
779 | | <a name="l01089"></a>01089 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>*<a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>;i += (p + 1)) {<span class="comment">//trace diagonal element</span> |
780 | | <a name="l01090"></a>01090 z (i) = pow (z (i), <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>) * <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> (ri); |
781 | | <a name="l01091"></a>01091 ri++; |
782 | | <a name="l01092"></a>01092 } |
783 | | <a name="l01093"></a>01093 |
784 | | <a name="l01094"></a>01094 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>*z); |
785 | | <a name="l01095"></a>01095 } |
786 | | <a name="l01096"></a>01096 }; |
787 | | <a name="l01097"></a>01097 |
788 | | <a name="l01099"></a>01099 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
789 | | <a name="l01105"></a><a class="code" href="classbdm_1_1eEmp.html">01105</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</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> |
790 | | <a name="l01106"></a>01106 { |
791 | | <a name="l01107"></a>01107 <span class="keyword">protected</span> : |
792 | | <a name="l01109"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">01109</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
793 | | <a name="l01111"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">01111</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
794 | | <a name="l01113"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">01113</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
795 | | <a name="l01114"></a>01114 <span class="keyword">public</span>: |
796 | | <a name="l01117"></a>01117 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> () : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> (), <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (), <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> () {}; |
797 | | <a name="l01119"></a><a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076">01119</a> <a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076" title="copy constructor">eEmp</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &e) : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> (e), <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (e.<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>), <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (e.<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>) {}; |
798 | | <a name="l01121"></a>01121 |
799 | | <a name="l01123"></a>01123 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#e7f8f98310c1de51bd5c8a1c87528f72" title="Set samples and weights.">set_statistics</a> (<span class="keyword">const</span> vec &w0, <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> &pdf0); |
800 | | <a name="l01125"></a><a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95">01125</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95" title="Set samples and weights.">set_statistics</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> &pdf0 , <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>) {<a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95" title="Set samples and weights.">set_statistics</a> (ones (n) / n, pdf0);}; |
801 | | <a name="l01127"></a>01127 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b62d802b8ef39f7c4dcbeb366c90951a" title="Set sample.">set_samples</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>* pdf0); |
802 | | <a name="l01129"></a><a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1">01129</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> (<span class="keywordtype">int</span> n0, <span class="keywordtype">bool</span> copy = <span class="keyword">true</span>) {<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> = n0; <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>.set_size (n0, copy);<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>.set_size (n0, copy);}; |
803 | | <a name="l01131"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">01131</a> vec& <a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
804 | | <a name="l01133"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">01133</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714" title="Potentially dangerous, use with care.">_w</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
805 | | <a name="l01135"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">01135</a> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
806 | | <a name="l01137"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">01137</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2" title="access function">_samples</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
807 | | <a name="l01139"></a>01139 ivec <a class="code" href="classbdm_1_1eEmp.html#f06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> (RESAMPLING_METHOD method = SYSTEMATIC); |
808 | | <a name="l01141"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">01141</a> vec <a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270" title="inherited operation : NOT implemneted">sample</a>()<span class="keyword"> const </span>{it_error (<span class="stringliteral">"Not implemented"</span>);<span class="keywordflow">return</span> 0;} |
809 | | <a name="l01143"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">01143</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09" title="inherited operation : NOT implemneted">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{it_error (<span class="stringliteral">"Not implemented"</span>);<span class="keywordflow">return</span> 0.0;} |
810 | | <a name="l01144"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">01144</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
811 | | <a name="l01145"></a>01145 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
812 | | <a name="l01146"></a>01146 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) {pom += <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) * <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (i);} |
813 | | <a name="l01147"></a>01147 <span class="keywordflow">return</span> pom; |
814 | | <a name="l01148"></a>01148 } |
815 | | <a name="l01149"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">01149</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
816 | | <a name="l01150"></a>01150 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
817 | | <a name="l01151"></a>01151 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) {pom += pow (<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i), 2) * <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (i);} |
818 | | <a name="l01152"></a>01152 <span class="keywordflow">return</span> pom -pow (<a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(), 2); |
819 | | <a name="l01153"></a>01153 } |
820 | | <a name="l01155"></a><a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f">01155</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f" title="For this class, qbounds are minimum and maximum value of the population!">qbounds</a> (vec &lb, vec &ub, <span class="keywordtype">double</span> perc = 0.95)<span class="keyword"> const </span>{ |
821 | | <a name="l01156"></a>01156 <span class="comment">// lb in inf so than it will be pushed below;</span> |
822 | | <a name="l01157"></a>01157 lb.set_size (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
823 | | <a name="l01158"></a>01158 ub.set_size (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
824 | | <a name="l01159"></a>01159 lb = std::numeric_limits<double>::infinity(); |
825 | | <a name="l01160"></a>01160 ub = -std::numeric_limits<double>::infinity(); |
826 | | <a name="l01161"></a>01161 <span class="keywordtype">int</span> j; |
827 | | <a name="l01162"></a>01162 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) { |
828 | | <a name="l01163"></a>01163 <span class="keywordflow">for</span> (j = 0;j < <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>; j++) { |
829 | | <a name="l01164"></a>01164 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j) < lb (j)) {lb (j) = <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j);} |
830 | | <a name="l01165"></a>01165 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j) > ub (j)) {ub (j) = <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j);} |
831 | | <a name="l01166"></a>01166 } |
832 | | <a name="l01167"></a>01167 } |
833 | | <a name="l01168"></a>01168 } |
834 | | <a name="l01169"></a>01169 }; |
835 | | <a name="l01170"></a>01170 |
836 | | <a name="l01171"></a>01171 |
837 | | <a name="l01173"></a>01173 |
838 | | <a name="l01174"></a>01174 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
839 | | <a name="l01175"></a>01175 <span class="keywordtype">void</span> enorm<sq_T>::set_parameters (<span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0) |
840 | | <a name="l01176"></a>01176 { |
841 | | <a name="l01177"></a>01177 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
842 | | <a name="l01178"></a>01178 mu = mu0; |
843 | | <a name="l01179"></a>01179 R = R0; |
844 | | <a name="l01180"></a>01180 <a class="code" href="classbdm_1_1root.html#1c314bd6d6dacb8ba78ea5eb88fd9516" title="This method TODO.">validate</a>(); |
845 | | <a name="l01181"></a>01181 }; |
846 | | <a name="l01182"></a>01182 |
847 | | <a name="l01183"></a>01183 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
848 | | <a name="l01184"></a><a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">01184</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">enorm<sq_T>::from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) |
849 | | <a name="l01185"></a>01185 { |
850 | | <a name="l01186"></a>01186 <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">//reads rv</span> |
851 | | <a name="l01187"></a>01187 |
852 | | <a name="l01188"></a>01188 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>, <span class="keyword">set</span>, <span class="stringliteral">"mu"</span>, UI::compulsory); |
853 | | <a name="l01189"></a>01189 mat Rtmp;<span class="comment">// necessary for conversion</span> |
854 | | <a name="l01190"></a>01190 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (Rtmp, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::compulsory); |
855 | | <a name="l01191"></a>01191 <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> = Rtmp; <span class="comment">// conversion</span> |
856 | | <a name="l01192"></a>01192 <a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea" title="This method TODO.">validate</a>(); |
857 | | <a name="l01193"></a>01193 } |
858 | | <a name="l01194"></a>01194 |
859 | | <a name="l01195"></a>01195 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
860 | | <a name="l01196"></a><a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2">01196</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">enorm<sq_T>::dupdate</a> (mat &v, <span class="keywordtype">double</span> nu) |
861 | | <a name="l01197"></a>01197 { |
862 | | <a name="l01198"></a>01198 <span class="comment">//</span> |
863 | | <a name="l01199"></a>01199 }; |
864 | | <a name="l01200"></a>01200 |
865 | | <a name="l01201"></a>01201 <span class="comment">// template<class sq_T></span> |
866 | | <a name="l01202"></a>01202 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
867 | | <a name="l01203"></a>01203 <span class="comment">// //</span> |
868 | | <a name="l01204"></a>01204 <span class="comment">// };</span> |
| 651 | <a name="l00894"></a>00894 <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> (migamma_ref); |
| 652 | <a name="l00895"></a>00895 SHAREDPTR (migamma_ref); |
| 653 | <a name="l00896"></a>00896 |
| 654 | <a name="l00906"></a><a class="code" href="classbdm_1_1elognorm.html">00906</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1elognorm.html">elognorm</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><ldmat> |
| 655 | <a name="l00907"></a>00907 { |
| 656 | <a name="l00908"></a>00908 <span class="keyword">public</span>: |
| 657 | <a name="l00909"></a><a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba">00909</a> vec <a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> exp (<a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<ldmat>::sample</a>());}; |
| 658 | <a name="l00910"></a><a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea">00910</a> vec <a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec var = <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">enorm<ldmat>::variance</a>();<span class="keywordflow">return</span> exp (<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> - 0.5*var);}; |
| 659 | <a name="l00911"></a>00911 |
| 660 | <a name="l00912"></a>00912 }; |
| 661 | <a name="l00913"></a>00913 |
| 662 | <a name="l00925"></a><a class="code" href="classbdm_1_1mlognorm.html">00925</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlognorm.html" title="Log-Normal random walk.">mlognorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><elognorm> |
| 663 | <a name="l00926"></a>00926 { |
| 664 | <a name="l00927"></a>00927 <span class="keyword">protected</span>: |
| 665 | <a name="l00929"></a><a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a">00929</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
| 666 | <a name="l00930"></a>00930 |
| 667 | <a name="l00932"></a><a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2">00932</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
| 668 | <a name="l00933"></a>00933 <span class="keyword">public</span>: |
| 669 | <a name="l00935"></a><a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41">00935</a> <a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1elognorm.html">elognorm</a>>(), |
| 670 | <a name="l00936"></a>00936 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> (0), |
| 671 | <a name="l00937"></a>00937 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu()) { |
| 672 | <a name="l00938"></a>00938 } |
| 673 | <a name="l00939"></a>00939 |
| 674 | <a name="l00941"></a><a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f">00941</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f" title="Set value of k.">set_parameters</a> (<span class="keywordtype">int</span> size, <span class="keywordtype">double</span> k) { |
| 675 | <a name="l00942"></a>00942 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5 * log (k * k + 1); |
| 676 | <a name="l00943"></a>00943 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> (zeros (size), 2*<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye (size)); |
| 677 | <a name="l00944"></a>00944 |
| 678 | <a name="l00945"></a>00945 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
| 679 | <a name="l00946"></a>00946 }; |
| 680 | <a name="l00947"></a>00947 |
| 681 | <a name="l00948"></a><a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">00948</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">condition</a> (<span class="keyword">const</span> vec &val) { |
| 682 | <a name="l00949"></a>00949 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> = log (val) - <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>;<span class="comment">//elem_mult ( refl,pow ( val,l ) );</span> |
| 683 | <a name="l00950"></a>00950 }; |
| 684 | <a name="l00951"></a>00951 |
| 685 | <a name="l00970"></a>00970 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#49e45ea13a869da607ef9be7a229128a">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>); |
| 686 | <a name="l00971"></a>00971 |
| 687 | <a name="l00972"></a>00972 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
| 688 | <a name="l00973"></a>00973 |
| 689 | <a name="l00974"></a>00974 }; |
| 690 | <a name="l00975"></a>00975 |
| 691 | <a name="l00976"></a>00976 <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> (mlognorm); |
| 692 | <a name="l00977"></a>00977 SHAREDPTR (mlognorm); |
| 693 | <a name="l00978"></a>00978 |
| 694 | <a name="l00982"></a><a class="code" href="classbdm_1_1eWishartCh.html">00982</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</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> |
| 695 | <a name="l00983"></a>00983 { |
| 696 | <a name="l00984"></a>00984 <span class="keyword">protected</span>: |
| 697 | <a name="l00986"></a><a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490">00986</a> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>; |
| 698 | <a name="l00988"></a><a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f">00988</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; |
| 699 | <a name="l00990"></a><a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3">00990</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>; |
| 700 | <a name="l00991"></a>00991 <span class="keyword">public</span>: |
| 701 | <a name="l00993"></a><a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0">00993</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (<span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) {<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a> = <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> (Y0);<a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a> = delta0; <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> = <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>(); <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> * <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; } |
| 702 | <a name="l00995"></a><a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339">00995</a> mat <a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()<span class="keyword"> const </span>{ |
| 703 | <a name="l00996"></a>00996 mat X = zeros (<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>, <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>); |
| 704 | <a name="l00997"></a>00997 |
| 705 | <a name="l00998"></a>00998 <span class="comment">//sample diagonal</span> |
| 706 | <a name="l00999"></a>00999 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>;i++) { |
| 707 | <a name="l01000"></a>01000 GamRNG.setup (0.5* (<a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a> - i) , 0.5); <span class="comment">// no +1 !! index if from 0</span> |
| 708 | <a name="l01001"></a>01001 <span class="preprocessor">#pragma omp critical</span> |
| 709 | <a name="l01002"></a>01002 <span class="preprocessor"></span> X (i, i) = sqrt (GamRNG()); |
| 710 | <a name="l01003"></a>01003 } |
| 711 | <a name="l01004"></a>01004 <span class="comment">//do the rest</span> |
| 712 | <a name="l01005"></a>01005 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < p;i++) { |
| 713 | <a name="l01006"></a>01006 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = i + 1;j < p;j++) { |
| 714 | <a name="l01007"></a>01007 <span class="preprocessor">#pragma omp critical</span> |
| 715 | <a name="l01008"></a>01008 <span class="preprocessor"></span> X (i, j) = NorRNG.sample(); |
| 716 | <a name="l01009"></a>01009 } |
| 717 | <a name="l01010"></a>01010 } |
| 718 | <a name="l01011"></a>01011 <span class="keywordflow">return</span> X*<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>();<span class="comment">// return upper triangular part of the decomposition</span> |
| 719 | <a name="l01012"></a>01012 } |
| 720 | <a name="l01013"></a><a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a">01013</a> vec <a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a" title="Returns a sample, from density .">sample</a> ()<span class="keyword"> const </span>{ |
| 721 | <a name="l01014"></a>01014 <span class="keywordflow">return</span> vec (<a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()._data(), <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>*<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>); |
| 722 | <a name="l01015"></a>01015 } |
| 723 | <a name="l01017"></a><a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981">01017</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> (<span class="keyword">const</span> mat &Ch0) {copy_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, Ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data());} |
| 724 | <a name="l01019"></a><a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a">01019</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a" title="fast access function y0 will be copied into Y.Ch.">_setY</a> (<span class="keyword">const</span> vec &ch0) {copy_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); } |
| 725 | <a name="l01021"></a><a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e">01021</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& <a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>;} |
| 726 | <a name="l01022"></a>01022 }; |
| 727 | <a name="l01023"></a>01023 |
| 728 | <a name="l01025"></a>01025 |
| 729 | <a name="l01027"></a><a class="code" href="classbdm_1_1eiWishartCh.html">01027</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eiWishartCh.html" title="Inverse Wishart on Choleski decomposition.">eiWishartCh</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> |
| 730 | <a name="l01028"></a>01028 { |
| 731 | <a name="l01029"></a>01029 <span class="keyword">protected</span>: |
| 732 | <a name="l01031"></a><a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a">01031</a> <a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</a> <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>; |
| 733 | <a name="l01033"></a><a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd">01033</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>; |
| 734 | <a name="l01035"></a><a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464">01035</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a>; |
| 735 | <a name="l01036"></a>01036 <span class="keyword">public</span>: |
| 736 | <a name="l01038"></a><a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3">01038</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) { |
| 737 | <a name="l01039"></a>01039 <a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> = delta0; |
| 738 | <a name="l01040"></a>01040 <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (inv (Y0), delta0); |
| 739 | <a name="l01041"></a>01041 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a> = Y0.rows(); |
| 740 | <a name="l01042"></a>01042 } |
| 741 | <a name="l01043"></a><a class="code" href="classbdm_1_1eiWishartCh.html#2f668192cc9c2e3a5b7e608164685a3e">01043</a> vec <a class="code" href="classbdm_1_1eiWishartCh.html#2f668192cc9c2e3a5b7e608164685a3e" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{mat iCh; iCh = inv (<a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()); <span class="keywordflow">return</span> vec (iCh._data(), <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>);} |
| 742 | <a name="l01045"></a><a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5">01045</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<span class="keyword">const</span> vec &y0) { |
| 743 | <a name="l01046"></a>01046 mat Ch (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
| 744 | <a name="l01047"></a>01047 mat iCh (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
| 745 | <a name="l01048"></a>01048 copy_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, y0._data(), Ch._data()); |
| 746 | <a name="l01049"></a>01049 |
| 747 | <a name="l01050"></a>01050 iCh = inv (Ch); |
| 748 | <a name="l01051"></a>01051 <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> (iCh); |
| 749 | <a name="l01052"></a>01052 } |
| 750 | <a name="l01053"></a><a class="code" href="classbdm_1_1eiWishartCh.html#a6ddbd815b8b666dd542e97f009f89bb">01053</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#a6ddbd815b8b666dd542e97f009f89bb">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
| 751 | <a name="l01054"></a>01054 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> X (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
| 752 | <a name="l01055"></a>01055 <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& Y = <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>(); |
| 753 | <a name="l01056"></a>01056 |
| 754 | <a name="l01057"></a>01057 copy_vector (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>*<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, val._data(), X.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); |
| 755 | <a name="l01058"></a>01058 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> iX (p);X.<a class="code" href="classbdm_1_1chmat.html#cbf3389db96dff41fb2e9532d59b13c0" title="Inversion in the same form, i.e. cholesky.">inv</a> (iX); |
| 756 | <a name="l01059"></a>01059 <span class="comment">// compute</span> |
| 757 | <a name="l01060"></a>01060 <span class="comment">// \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)},</span> |
| 758 | <a name="l01061"></a>01061 mat M = Y.<a class="code" href="classbdm_1_1chmat.html#4b4c5d4dbb8a3d585b68d936cb6df31b" title="Conversion to full matrix.">to_mat</a>() * iX.to_mat(); |
| 759 | <a name="l01062"></a>01062 |
| 760 | <a name="l01063"></a>01063 <span class="keywordtype">double</span> log1 = 0.5 * p * (2 * Y.<a class="code" href="classbdm_1_1chmat.html#949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * (<a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> + p + 1) * (2 * X.<a class="code" href="classbdm_1_1chmat.html#949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * trace (M); |
| 761 | <a name="l01064"></a>01064 <span class="comment">//Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!!</span> |
| 762 | <a name="l01065"></a>01065 |
| 763 | <a name="l01066"></a>01066 <span class="comment">/* if (0) {</span> |
| 764 | <a name="l01067"></a>01067 <span class="comment"> mat XX=X.to_mat();</span> |
| 765 | <a name="l01068"></a>01068 <span class="comment"> mat YY=Y.to_mat();</span> |
| 766 | <a name="l01069"></a>01069 <span class="comment"></span> |
| 767 | <a name="l01070"></a>01070 <span class="comment"> double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX));</span> |
| 768 | <a name="l01071"></a>01071 <span class="comment"> cout << log1 << "," << log2 << endl;</span> |
| 769 | <a name="l01072"></a>01072 <span class="comment"> }*/</span> |
| 770 | <a name="l01073"></a>01073 <span class="keywordflow">return</span> log1; |
| 771 | <a name="l01074"></a>01074 }; |
| 772 | <a name="l01075"></a>01075 |
| 773 | <a name="l01076"></a>01076 }; |
| 774 | <a name="l01077"></a>01077 |
| 775 | <a name="l01079"></a><a class="code" href="classbdm_1_1rwiWishartCh.html">01079</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eiWishartCh> |
| 776 | <a name="l01080"></a>01080 { |
| 777 | <a name="l01081"></a>01081 <span class="keyword">protected</span>: |
| 778 | <a name="l01083"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb">01083</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>; |
| 779 | <a name="l01085"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a">01085</a> vec <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a>; |
| 780 | <a name="l01087"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861">01087</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>; |
| 781 | <a name="l01089"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663">01089</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>; |
| 782 | <a name="l01090"></a>01090 |
| 783 | <a name="l01091"></a>01091 <span class="keyword">public</span>: |
| 784 | <a name="l01092"></a>01092 <a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a>() : <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> (0) {} |
| 785 | <a name="l01094"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#28549ee3ce1ff8509360171ea3cf717c">01094</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#28549ee3ce1ff8509360171ea3cf717c" title="constructor function">set_parameters</a> (<span class="keywordtype">int</span> p0, <span class="keywordtype">double</span> k, vec ref0, <span class="keywordtype">double</span> l0) { |
| 786 | <a name="l01095"></a>01095 <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> = p0; |
| 787 | <a name="l01096"></a>01096 <span class="keywordtype">double</span> delta = 2 / (k * k) + <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> + 3; |
| 788 | <a name="l01097"></a>01097 <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> = sqrt (delta - <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> - 1); |
| 789 | <a name="l01098"></a>01098 <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> = l0; |
| 790 | <a name="l01099"></a>01099 <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> = pow (ref0, 1 - <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>); |
| 791 | <a name="l01100"></a>01100 |
| 792 | <a name="l01101"></a>01101 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (eye (<a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>), delta); |
| 793 | <a name="l01102"></a>01102 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); |
| 794 | <a name="l01103"></a>01103 } |
| 795 | <a name="l01104"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#ac087ba6c885d3faeda9171229f9b4e6">01104</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#ac087ba6c885d3faeda9171229f9b4e6">condition</a> (<span class="keyword">const</span> vec &c) { |
| 796 | <a name="l01105"></a>01105 vec z = c; |
| 797 | <a name="l01106"></a>01106 <span class="keywordtype">int</span> ri = 0; |
| 798 | <a name="l01107"></a>01107 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>*<a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>;i += (p + 1)) {<span class="comment">//trace diagonal element</span> |
| 799 | <a name="l01108"></a>01108 z (i) = pow (z (i), <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>) * <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> (ri); |
| 800 | <a name="l01109"></a>01109 ri++; |
| 801 | <a name="l01110"></a>01110 } |
| 802 | <a name="l01111"></a>01111 |
| 803 | <a name="l01112"></a>01112 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>*z); |
| 804 | <a name="l01113"></a>01113 } |
| 805 | <a name="l01114"></a>01114 }; |
| 806 | <a name="l01115"></a>01115 |
| 807 | <a name="l01117"></a>01117 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
| 808 | <a name="l01123"></a><a class="code" href="classbdm_1_1eEmp.html">01123</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</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> |
| 809 | <a name="l01124"></a>01124 { |
| 810 | <a name="l01125"></a>01125 <span class="keyword">protected</span> : |
| 811 | <a name="l01127"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">01127</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
| 812 | <a name="l01129"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">01129</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
| 813 | <a name="l01131"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">01131</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
| 814 | <a name="l01132"></a>01132 <span class="keyword">public</span>: |
| 815 | <a name="l01135"></a>01135 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> () : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> (), <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (), <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> () {}; |
| 816 | <a name="l01137"></a><a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076">01137</a> <a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076" title="copy constructor">eEmp</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &e) : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> (e), <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (e.<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>), <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (e.<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>) {}; |
| 817 | <a name="l01139"></a>01139 |
| 818 | <a name="l01141"></a>01141 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#e7f8f98310c1de51bd5c8a1c87528f72" title="Set samples and weights.">set_statistics</a> (<span class="keyword">const</span> vec &w0, <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> &pdf0); |
| 819 | <a name="l01143"></a><a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95">01143</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95" title="Set samples and weights.">set_statistics</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> &pdf0 , <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>) {<a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95" title="Set samples and weights.">set_statistics</a> (ones (n) / n, pdf0);}; |
| 820 | <a name="l01145"></a>01145 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b62d802b8ef39f7c4dcbeb366c90951a" title="Set sample.">set_samples</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>* pdf0); |
| 821 | <a name="l01147"></a><a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1">01147</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> (<span class="keywordtype">int</span> n0, <span class="keywordtype">bool</span> copy = <span class="keyword">true</span>) {<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> = n0; <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>.set_size (n0, copy);<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>.set_size (n0, copy);}; |
| 822 | <a name="l01149"></a><a class="code" href="classbdm_1_1eEmp.html#37937007a3a676cf653a7de412674481">01149</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#37937007a3a676cf653a7de412674481" title="Set samples.">set_parameters</a> (<span class="keyword">const</span> Array<vec> &Av) { |
| 823 | <a name="l01150"></a>01150 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a>(Av.size()>0,<span class="stringliteral">"Empty samples"</span>); |
| 824 | <a name="l01151"></a>01151 <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> = Av.size(); |
| 825 | <a name="l01152"></a>01152 <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">epdf::set_parameters</a>(Av(0).length()); |
| 826 | <a name="l01153"></a>01153 <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>=1/n*ones(n); |
| 827 | <a name="l01154"></a>01154 <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>=Av; |
| 828 | <a name="l01155"></a>01155 }; |
| 829 | <a name="l01157"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">01157</a> vec& <a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
| 830 | <a name="l01159"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">01159</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714" title="Potentially dangerous, use with care.">_w</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
| 831 | <a name="l01161"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">01161</a> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
| 832 | <a name="l01163"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">01163</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2" title="access function">_samples</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
| 833 | <a name="l01165"></a>01165 ivec <a class="code" href="classbdm_1_1eEmp.html#f06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> (RESAMPLING_METHOD method = SYSTEMATIC); |
| 834 | <a name="l01166"></a>01166 |
| 835 | <a name="l01168"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">01168</a> vec <a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270" title="inherited operation : NOT implemented">sample</a>()<span class="keyword"> const </span>{ |
| 836 | <a name="l01169"></a>01169 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
| 837 | <a name="l01170"></a>01170 <span class="keywordflow">return</span> vec(); |
| 838 | <a name="l01171"></a>01171 } |
| 839 | <a name="l01172"></a>01172 |
| 840 | <a name="l01174"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">01174</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09" title="inherited operation : NOT implemented">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
| 841 | <a name="l01175"></a>01175 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
| 842 | <a name="l01176"></a>01176 <span class="keywordflow">return</span> 0.0; |
| 843 | <a name="l01177"></a>01177 } |
| 844 | <a name="l01178"></a>01178 |
| 845 | <a name="l01179"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">01179</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 846 | <a name="l01180"></a>01180 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 847 | <a name="l01181"></a>01181 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) {pom += <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) * <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (i);} |
| 848 | <a name="l01182"></a>01182 <span class="keywordflow">return</span> pom; |
| 849 | <a name="l01183"></a>01183 } |
| 850 | <a name="l01184"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">01184</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
| 851 | <a name="l01185"></a>01185 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 852 | <a name="l01186"></a>01186 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) {pom += pow (<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i), 2) * <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (i);} |
| 853 | <a name="l01187"></a>01187 <span class="keywordflow">return</span> pom -pow (<a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(), 2); |
| 854 | <a name="l01188"></a>01188 } |
| 855 | <a name="l01190"></a><a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f">01190</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f" title="For this class, qbounds are minimum and maximum value of the population!">qbounds</a> (vec &lb, vec &ub, <span class="keywordtype">double</span> perc = 0.95)<span class="keyword"> const </span>{ |
| 856 | <a name="l01191"></a>01191 <span class="comment">// lb in inf so than it will be pushed below;</span> |
| 857 | <a name="l01192"></a>01192 lb.set_size (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 858 | <a name="l01193"></a>01193 ub.set_size (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 859 | <a name="l01194"></a>01194 lb = std::numeric_limits<double>::infinity(); |
| 860 | <a name="l01195"></a>01195 ub = -std::numeric_limits<double>::infinity(); |
| 861 | <a name="l01196"></a>01196 <span class="keywordtype">int</span> j; |
| 862 | <a name="l01197"></a>01197 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) { |
| 863 | <a name="l01198"></a>01198 <span class="keywordflow">for</span> (j = 0;j < <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>; j++) { |
| 864 | <a name="l01199"></a>01199 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j) < lb (j)) {lb (j) = <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j);} |
| 865 | <a name="l01200"></a>01200 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j) > ub (j)) {ub (j) = <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j);} |
| 866 | <a name="l01201"></a>01201 } |
| 867 | <a name="l01202"></a>01202 } |
| 868 | <a name="l01203"></a>01203 } |
| 869 | <a name="l01204"></a>01204 }; |