173 | | <a name="l00246"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00246</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>;} |
174 | | <a name="l00248"></a><a class="code" href="classbdm_1_1eDirich.html#a06af2376976a33e1eceaed7e8da75a5">00248</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eDirich.html#a06af2376976a33e1eceaed7e8da75a5" title="Set internal parameters.">set_parameters</a> ( <span class="keyword">const</span> vec &beta0 ) { |
175 | | <a name="l00249"></a>00249 <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>= beta0; |
176 | | <a name="l00250"></a>00250 <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(); |
177 | | <a name="l00251"></a>00251 <a class="code" href="classbdm_1_1eDirich.html#ee9db192a6f0ab7b29c33b2a18a5e1b4" title="speedup variable">gamma</a> = sum ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ); |
178 | | <a name="l00252"></a>00252 } |
179 | | <a name="l00253"></a>00253 }; |
180 | | <a name="l00254"></a>00254 |
181 | | <a name="l00256"></a><a class="code" href="classbdm_1_1multiBM.html">00256</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> { |
182 | | <a name="l00257"></a>00257 <span class="keyword">protected</span>: |
183 | | <a name="l00259"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00259</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>; |
184 | | <a name="l00261"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00261</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
185 | | <a name="l00262"></a>00262 <span class="keyword">public</span>: |
186 | | <a name="l00264"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00264</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() ) {<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>();}<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;}} |
187 | | <a name="l00266"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00266</a> <a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf" title="Default 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() ) {} |
188 | | <a name="l00268"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00268</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>;} |
189 | | <a name="l00269"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00269</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 ) { |
190 | | <a name="l00270"></a>00270 <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>();} |
191 | | <a name="l00271"></a>00271 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>+=dt; |
192 | | <a name="l00272"></a>00272 <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>;} |
193 | | <a name="l00273"></a>00273 } |
194 | | <a name="l00274"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00274</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>{ |
195 | | <a name="l00275"></a>00275 <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> ); |
196 | | <a name="l00276"></a>00276 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>(); |
197 | | <a name="l00277"></a>00277 |
198 | | <a name="l00278"></a>00278 <span class="keywordtype">double</span> lll; |
199 | | <a name="l00279"></a>00279 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) |
200 | | <a name="l00280"></a>00280 {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>();} |
201 | | <a name="l00281"></a>00281 <span class="keywordflow">else</span> |
202 | | <a name="l00282"></a>00282 <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>;} |
203 | | <a name="l00283"></a>00283 <span class="keywordflow">else</span>{lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
204 | | <a name="l00284"></a>00284 |
205 | | <a name="l00285"></a>00285 beta+=dt; |
206 | | <a name="l00286"></a>00286 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-lll; |
207 | | <a name="l00287"></a>00287 } |
208 | | <a name="l00288"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00288</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 ) { |
209 | | <a name="l00289"></a>00289 <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 ); |
210 | | <a name="l00290"></a>00290 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
211 | | <a name="l00291"></a>00291 <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> |
212 | | <a name="l00292"></a>00292 <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> ) ); |
213 | | <a name="l00293"></a>00293 <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>();} |
214 | | <a name="l00294"></a>00294 } |
215 | | <a name="l00295"></a>00295 <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>& _epdf()<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>;}; |
216 | | <a name="l00296"></a>00296 <span class="keyword">const</span> eDirich* _e()<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>;}; |
217 | | <a name="l00297"></a>00297 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) { |
218 | | <a name="l00298"></a>00298 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters ( beta0 ); |
219 | | <a name="l00299"></a>00299 <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>.lognc();} |
220 | | <a name="l00300"></a>00300 } |
221 | | <a name="l00301"></a>00301 }; |
222 | | <a name="l00302"></a>00302 |
223 | | <a name="l00312"></a><a class="code" href="classbdm_1_1egamma.html">00312</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> { |
224 | | <a name="l00313"></a>00313 <span class="keyword">protected</span>: |
225 | | <a name="l00315"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00315</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
226 | | <a name="l00317"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00317</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
227 | | <a name="l00318"></a>00318 <span class="keyword">public</span> : |
228 | | <a name="l00320"></a><a class="code" href="classbdm_1_1egamma.html#131197f3dfad99355a01d30903279653">00320</a> <a class="code" href="classbdm_1_1egamma.html#131197f3dfad99355a01d30903279653" title="Default constructor.">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>(), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>() {}; |
229 | | <a name="l00322"></a><a class="code" href="classbdm_1_1egamma.html#749f82293ff23a8319c1bf52489d2ed2">00322</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#749f82293ff23a8319c1bf52489d2ed2" title="Sets parameters.">set_parameters</a> ( <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();}; |
230 | | <a name="l00323"></a>00323 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
231 | | <a name="l00325"></a>00325 <span class="comment">// mat sample ( int N ) const;</span> |
232 | | <a name="l00326"></a>00326 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="TODO: is it used anywhere?">evallog</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
233 | | <a name="l00327"></a>00327 <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>; |
234 | | <a name="l00329"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00329</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns poiter to alpha and beta. 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>;} |
235 | | <a name="l00330"></a>00330 vec& _beta() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>;} |
236 | | <a name="l00331"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00331</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>,<a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> );} |
237 | | <a name="l00332"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00332</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 ( <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>,<a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> ) ); } |
238 | | <a name="l00333"></a>00333 }; |
239 | | <a name="l00334"></a>00334 |
240 | | <a name="l00349"></a><a class="code" href="classbdm_1_1eigamma.html">00349</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_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> { |
241 | | <a name="l00350"></a>00350 <span class="keyword">protected</span>: |
242 | | <a name="l00352"></a><a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96">00352</a> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>; |
243 | | <a name="l00354"></a><a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6">00354</a> vec &<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>; |
244 | | <a name="l00356"></a><a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6">00356</a> vec &<a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a>; |
245 | | <a name="l00357"></a>00357 <span class="keyword">public</span> : |
246 | | <a name="l00359"></a><a class="code" href="classbdm_1_1eigamma.html#b496396f3511ce87d7ae3830ba94262c">00359</a> <a class="code" href="classbdm_1_1eigamma.html#b496396f3511ce87d7ae3830ba94262c" title="Default constructor.">eigamma</a> ( ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>(),<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a> ( <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>._alpha() ), <a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a> ( <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>._beta() ) {}; |
247 | | <a name="l00361"></a><a class="code" href="classbdm_1_1eigamma.html#09e616c95f31acddf7dfef96d1c5d645">00361</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eigamma.html#09e616c95f31acddf7dfef96d1c5d645" title="Sets parameters.">set_parameters</a> ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ) {<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>=a,<a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a>=b;}; |
248 | | <a name="l00362"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00362</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#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.<a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>();}; |
249 | | <a name="l00364"></a>00364 <span class="comment">// mat sample ( int N ) const;</span> |
250 | | <a name="l00365"></a><a class="code" href="classbdm_1_1eigamma.html#9e26c80c8e6708bfcf2e684958af6f91">00365</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eigamma.html#9e26c80c8e6708bfcf2e684958af6f91" title="TODO: is it used anywhere?">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.<a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="TODO: is it used anywhere?">evallog</a> ( val );}; |
251 | | <a name="l00366"></a><a class="code" href="classbdm_1_1eigamma.html#a52ac6d523e2fe05642d1f50fe66aec2">00366</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eigamma.html#a52ac6d523e2fe05642d1f50fe66aec2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.<a class="code" href="classbdm_1_1egamma.html#9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a>();}; |
252 | | <a name="l00368"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00368</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_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a>,<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>-1 );} |
253 | | <a name="l00369"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00369</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_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>-2 );} |
254 | | <a name="l00370"></a>00370 vec& _alpha() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>;} |
255 | | <a name="l00371"></a>00371 vec& _beta() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a>;} |
256 | | <a name="l00372"></a>00372 }; |
257 | | <a name="l00373"></a>00373 <span class="comment">/*</span> |
258 | | <a name="l00375"></a>00375 <span class="comment">class emix : public epdf {</span> |
259 | | <a name="l00376"></a>00376 <span class="comment">protected:</span> |
260 | | <a name="l00377"></a>00377 <span class="comment"> int n;</span> |
261 | | <a name="l00378"></a>00378 <span class="comment"> vec &w;</span> |
262 | | <a name="l00379"></a>00379 <span class="comment"> Array<epdf*> Coms;</span> |
263 | | <a name="l00380"></a>00380 <span class="comment">public:</span> |
264 | | <a name="l00382"></a>00382 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
265 | | <a name="l00383"></a>00383 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
266 | | <a name="l00384"></a>00384 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
267 | | <a name="l00385"></a>00385 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
268 | | <a name="l00386"></a>00386 <span class="comment">};</span> |
269 | | <a name="l00387"></a>00387 <span class="comment">*/</span> |
270 | | <a name="l00388"></a>00388 |
271 | | <a name="l00390"></a>00390 |
272 | | <a name="l00391"></a><a class="code" href="classbdm_1_1euni.html">00391</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> { |
273 | | <a name="l00392"></a>00392 <span class="keyword">protected</span>: |
274 | | <a name="l00394"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00394</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
275 | | <a name="l00396"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00396</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
276 | | <a name="l00398"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00398</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
277 | | <a name="l00400"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00400</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
278 | | <a name="l00402"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00402</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
279 | | <a name="l00403"></a>00403 <span class="keyword">public</span>: |
280 | | <a name="l00405"></a><a class="code" href="classbdm_1_1euni.html#8887b088e3ab0b01e96b88237d707b97">00405</a> <a class="code" href="classbdm_1_1euni.html#8887b088e3ab0b01e96b88237d707b97" title="Defualt constructor.">euni</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ) {} |
281 | | <a name="l00406"></a>00406 <span class="keywordtype">double</span> eval ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>;} |
282 | | <a name="l00407"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00407</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>;} |
283 | | <a name="l00408"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00408</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
284 | | <a name="l00409"></a>00409 vec smp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
285 | | <a name="l00410"></a>00410 <span class="preprocessor">#pragma omp critical</span> |
286 | | <a name="l00411"></a>00411 <span class="preprocessor"></span> <a class="code" href="namespacebdm.html#96288dbda6916cd442af735f66a9f40b" title="Global Uniform_RNG.">UniRNG</a>.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ,smp ); |
287 | | <a name="l00412"></a>00412 <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 ); |
288 | | <a name="l00413"></a>00413 } |
289 | | <a name="l00415"></a><a class="code" href="classbdm_1_1euni.html#8e130b323c62b42f1699537f99af6f09">00415</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#8e130b323c62b42f1699537f99af6f09" title="set values of low and high ">set_parameters</a> ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) { |
290 | | <a name="l00416"></a>00416 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0-low0; |
291 | | <a name="l00417"></a>00417 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> ); |
292 | | <a name="l00418"></a>00418 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
293 | | <a name="l00419"></a>00419 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
294 | | <a name="l00420"></a>00420 <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> ); |
295 | | <a name="l00421"></a>00421 <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> ); |
296 | | <a name="l00422"></a>00422 <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(); |
297 | | <a name="l00423"></a>00423 } |
298 | | <a name="l00424"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00424</a> vec <a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226" title="return expected value">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;} |
299 | | <a name="l00425"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00425</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;} |
300 | | <a name="l00426"></a>00426 }; |
301 | | <a name="l00427"></a>00427 |
| 212 | <a name="l00245"></a><a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2">00245</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>{ |
| 213 | <a name="l00246"></a>00246 <span class="keywordtype">double</span> tmp; |
| 214 | <a name="l00247"></a>00247 <span class="keywordtype">double</span> gam=sum ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ); |
| 215 | <a name="l00248"></a>00248 <span class="keywordtype">double</span> lgb=0.0; |
| 216 | <a name="l00249"></a>00249 <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 ) );} |
| 217 | <a name="l00250"></a>00250 tmp= lgb-lgamma ( gam ); |
| 218 | <a name="l00251"></a>00251 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
| 219 | <a name="l00252"></a>00252 <span class="keywordflow">return</span> tmp; |
| 220 | <a name="l00253"></a>00253 }; |
| 221 | <a name="l00255"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00255</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>;} |
| 222 | <a name="l00257"></a>00257 }; |
| 223 | <a name="l00258"></a>00258 |
| 224 | <a name="l00260"></a><a class="code" href="classbdm_1_1multiBM.html">00260</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> { |
| 225 | <a name="l00261"></a>00261 <span class="keyword">protected</span>: |
| 226 | <a name="l00263"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00263</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>; |
| 227 | <a name="l00265"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00265</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
| 228 | <a name="l00266"></a>00266 <span class="keyword">public</span>: |
| 229 | <a name="l00268"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00268</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() ) {<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>();}<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;}} |
| 230 | <a name="l00270"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00270</a> <a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf" title="Default 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() ) {} |
| 231 | <a name="l00272"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00272</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>;} |
| 232 | <a name="l00273"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00273</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 ) { |
| 233 | <a name="l00274"></a>00274 <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>();} |
| 234 | <a name="l00275"></a>00275 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>+=dt; |
| 235 | <a name="l00276"></a>00276 <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>;} |
| 236 | <a name="l00277"></a>00277 } |
| 237 | <a name="l00278"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00278</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>{ |
| 238 | <a name="l00279"></a>00279 <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> ); |
| 239 | <a name="l00280"></a>00280 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>(); |
| 240 | <a name="l00281"></a>00281 |
| 241 | <a name="l00282"></a>00282 <span class="keywordtype">double</span> lll; |
| 242 | <a name="l00283"></a>00283 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) |
| 243 | <a name="l00284"></a>00284 {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>();} |
| 244 | <a name="l00285"></a>00285 <span class="keywordflow">else</span> |
| 245 | <a name="l00286"></a>00286 <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>;} |
| 246 | <a name="l00287"></a>00287 <span class="keywordflow">else</span>{lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 247 | <a name="l00288"></a>00288 |
| 248 | <a name="l00289"></a>00289 beta+=dt; |
| 249 | <a name="l00290"></a>00290 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-lll; |
| 250 | <a name="l00291"></a>00291 } |
| 251 | <a name="l00292"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00292</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 ) { |
| 252 | <a name="l00293"></a>00293 <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 ); |
| 253 | <a name="l00294"></a>00294 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
| 254 | <a name="l00295"></a>00295 <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> |
| 255 | <a name="l00296"></a>00296 <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> ) ); |
| 256 | <a name="l00297"></a>00297 <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>();} |
| 257 | <a name="l00298"></a>00298 } |
| 258 | <a name="l00299"></a>00299 <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>& posterior()<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>;}; |
| 259 | <a name="l00300"></a>00300 <span class="keyword">const</span> eDirich* _e()<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>;}; |
| 260 | <a name="l00301"></a>00301 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) { |
| 261 | <a name="l00302"></a>00302 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters ( beta0 ); |
| 262 | <a name="l00303"></a>00303 <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>.lognc();} |
| 263 | <a name="l00304"></a>00304 } |
| 264 | <a name="l00305"></a>00305 }; |
| 265 | <a name="l00306"></a>00306 |
| 266 | <a name="l00316"></a><a class="code" href="classbdm_1_1egamma.html">00316</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> { |
| 267 | <a name="l00317"></a>00317 <span class="keyword">protected</span>: |
| 268 | <a name="l00319"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00319</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
| 269 | <a name="l00321"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00321</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
| 270 | <a name="l00322"></a>00322 <span class="keyword">public</span> : |
| 271 | <a name="l00325"></a>00325 <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>(), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>() {}; |
| 272 | <a name="l00326"></a>00326 <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 );}; |
| 273 | <a name="l00327"></a>00327 <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();}; |
| 274 | <a name="l00329"></a>00329 |
| 275 | <a name="l00330"></a>00330 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 276 | <a name="l00332"></a>00332 <span class="comment">// mat sample ( int N ) const;</span> |
| 277 | <a name="l00333"></a>00333 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="TODO: is it used anywhere?">evallog</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
| 278 | <a name="l00334"></a>00334 <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>; |
| 279 | <a name="l00336"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00336</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns poiter to alpha and beta. 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>;} |
| 280 | <a name="l00337"></a>00337 vec& _beta() {<span class="keywordflow">return</span> beta;} |
| 281 | <a name="l00338"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00338</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 );} |
| 282 | <a name="l00339"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00339</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 ) ); } |
| 283 | <a name="l00340"></a>00340 }; |
| 284 | <a name="l00341"></a>00341 |
| 285 | <a name="l00356"></a><a class="code" href="classbdm_1_1eigamma.html">00356</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_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> { |
| 286 | <a name="l00357"></a>00357 <span class="keyword">protected</span>: |
| 287 | <a name="l00359"></a><a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96">00359</a> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>; |
| 288 | <a name="l00361"></a><a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6">00361</a> vec &<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>; |
| 289 | <a name="l00363"></a><a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6">00363</a> vec &<a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a>; |
| 290 | <a name="l00364"></a>00364 <span class="keyword">public</span> : |
| 291 | <a name="l00367"></a>00367 <a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> ( ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>(),<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a> ( <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>._alpha() ), <a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a> ( <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>._beta() ) {}; |
| 292 | <a name="l00368"></a>00368 <a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ):<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>(),<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a> ( <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>._alpha() ), <a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a> ( <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>._beta() ) {<a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.<a class="code" href="classbdm_1_1egamma.html#749f82293ff23a8319c1bf52489d2ed2">set_parameters</a> ( a,b );}; |
| 293 | <a name="l00369"></a>00369 <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_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.set_parameters ( a,b );}; |
| 294 | <a name="l00371"></a>00371 |
| 295 | <a name="l00372"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00372</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#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.<a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>();}; |
| 296 | <a name="l00374"></a>00374 <span class="comment">// mat sample ( int N ) const;</span> |
| 297 | <a name="l00375"></a><a class="code" href="classbdm_1_1eigamma.html#9e26c80c8e6708bfcf2e684958af6f91">00375</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eigamma.html#9e26c80c8e6708bfcf2e684958af6f91" title="TODO: is it used anywhere?">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.<a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="TODO: is it used anywhere?">evallog</a> ( val );}; |
| 298 | <a name="l00376"></a><a class="code" href="classbdm_1_1eigamma.html#a52ac6d523e2fe05642d1f50fe66aec2">00376</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eigamma.html#a52ac6d523e2fe05642d1f50fe66aec2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#3e5c03201f073033a7db894fa15ddb96" title="internal egamma">eg</a>.<a class="code" href="classbdm_1_1egamma.html#9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a>();}; |
| 299 | <a name="l00378"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00378</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_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a>,<a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>-1 );} |
| 300 | <a name="l00379"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00379</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_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>-2 );} |
| 301 | <a name="l00380"></a>00380 vec& _alpha() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#494fafd76d9448395efe160c9ba11ab6" title="Vector .">alpha</a>;} |
| 302 | <a name="l00381"></a>00381 vec& _beta() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eigamma.html#e32ff12ba6b2fdc22068c35dace23fa6" title="Vector (in fact it is 1/beta as used in definition of iG).">beta</a>;} |
| 303 | <a name="l00382"></a>00382 }; |
| 304 | <a name="l00383"></a>00383 <span class="comment">/*</span> |
| 305 | <a name="l00385"></a>00385 <span class="comment">class emix : public epdf {</span> |
| 306 | <a name="l00386"></a>00386 <span class="comment">protected:</span> |
| 307 | <a name="l00387"></a>00387 <span class="comment"> int n;</span> |
| 308 | <a name="l00388"></a>00388 <span class="comment"> vec &w;</span> |
| 309 | <a name="l00389"></a>00389 <span class="comment"> Array<epdf*> Coms;</span> |
| 310 | <a name="l00390"></a>00390 <span class="comment">public:</span> |
| 311 | <a name="l00392"></a>00392 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
| 312 | <a name="l00393"></a>00393 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
| 313 | <a name="l00394"></a>00394 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
| 314 | <a name="l00395"></a>00395 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
| 315 | <a name="l00396"></a>00396 <span class="comment">};</span> |
| 316 | <a name="l00397"></a>00397 <span class="comment">*/</span> |
| 317 | <a name="l00398"></a>00398 |
| 318 | <a name="l00400"></a>00400 |
| 319 | <a name="l00401"></a><a class="code" href="classbdm_1_1euni.html">00401</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> { |
| 320 | <a name="l00402"></a>00402 <span class="keyword">protected</span>: |
| 321 | <a name="l00404"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00404</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
| 322 | <a name="l00406"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00406</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
| 323 | <a name="l00408"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00408</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
| 324 | <a name="l00410"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00410</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
| 325 | <a name="l00412"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00412</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
| 326 | <a name="l00413"></a>00413 <span class="keyword">public</span>: |
| 327 | <a name="l00416"></a>00416 <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> ( ) {} |
| 328 | <a name="l00417"></a>00417 <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 );} |
| 329 | <a name="l00418"></a>00418 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) { |
| 330 | <a name="l00419"></a>00419 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0-low0; |
| 331 | <a name="l00420"></a>00420 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> ); |
| 332 | <a name="l00421"></a>00421 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
| 333 | <a name="l00422"></a>00422 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
| 334 | <a name="l00423"></a>00423 <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> ); |
| 335 | <a name="l00424"></a>00424 <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> ); |
| 336 | <a name="l00425"></a>00425 <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(); |
| 337 | <a name="l00426"></a>00426 } |
303 | | <a name="l00434"></a>00434 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
304 | | <a name="l00435"></a><a class="code" href="classbdm_1_1mlnorm.html">00435</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_1mEF.html" title="Exponential family model.">mEF</a> { |
305 | | <a name="l00436"></a>00436 <span class="keyword">protected</span>: |
306 | | <a name="l00438"></a><a class="code" href="classbdm_1_1mlnorm.html#150ad6acb223b0a0abeaf92346686dcd">00438</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
307 | | <a name="l00439"></a>00439 mat A; |
308 | | <a name="l00440"></a>00440 vec mu_const; |
309 | | <a name="l00441"></a>00441 vec& _mu; <span class="comment">//cached epdf.mu;</span> |
310 | | <a name="l00442"></a>00442 <span class="keyword">public</span>: |
311 | | <a name="l00444"></a>00444 <a class="code" href="classbdm_1_1mlnorm.html#2dcc06a3dd71f038efbe14dc34d937ae" title="Constructor.">mlnorm</a> ( ); |
312 | | <a name="l00446"></a>00446 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">set_parameters</a> ( <span class="keyword">const</span> mat &A, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R ); |
313 | | <a name="l00447"></a>00447 <span class="comment">// //!Generate one sample of the posterior</span> |
314 | | <a name="l00448"></a>00448 <span class="comment">// vec samplecond (const vec &cond, double &lik );</span> |
315 | | <a name="l00449"></a>00449 <span class="comment">// //!Generate matrix of samples of the posterior</span> |
316 | | <a name="l00450"></a>00450 <span class="comment">// mat samplecond (const vec &cond, vec &lik, int n );</span> |
317 | | <a name="l00452"></a>00452 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2" title="Set value of rvc . Result of this operation is stored in epdf use function _ep to...">condition</a> ( <span class="keyword">const</span> vec &cond ); |
318 | | <a name="l00453"></a>00453 |
319 | | <a name="l00455"></a><a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced">00455</a> vec& <a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced" title="access function">_mu_const</a>() {<span class="keywordflow">return</span> mu_const;} |
320 | | <a name="l00457"></a><a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614">00457</a> mat& <a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614" title="access function">_A</a>() {<span class="keywordflow">return</span> A;} |
321 | | <a name="l00459"></a><a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604">00459</a> mat <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R().to_mat();} |
322 | | <a name="l00460"></a>00460 |
323 | | <a name="l00461"></a>00461 <span class="keyword">template</span><<span class="keyword">class</span> sq_M> |
324 | | <a name="l00462"></a>00462 <span class="keyword">friend</span> std::ostream &operator<< ( std::ostream &os, mlnorm<sq_M> &ml ); |
325 | | <a name="l00463"></a>00463 }; |
326 | | <a name="l00464"></a>00464 |
327 | | <a name="l00472"></a><a class="code" href="classbdm_1_1mlstudent.html">00472</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> { |
328 | | <a name="l00473"></a>00473 <span class="keyword">protected</span>: |
329 | | <a name="l00474"></a>00474 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Lambda; |
330 | | <a name="l00475"></a>00475 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>; |
331 | | <a name="l00476"></a>00476 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Re; |
332 | | <a name="l00477"></a>00477 <span class="keyword">public</span>: |
333 | | <a name="l00478"></a>00478 <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<ldmat></a> (), |
334 | | <a name="l00479"></a>00479 Lambda (), <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R() ) {} |
335 | | <a name="l00480"></a>00480 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0 ) { |
336 | | <a name="l00481"></a>00481 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
337 | | <a name="l00482"></a>00482 it_assert_debug ( R0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ==A0.rows(),<span class="stringliteral">""</span> ); |
338 | | <a name="l00483"></a>00483 |
339 | | <a name="l00484"></a>00484 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( mu0,Lambda ); <span class="comment">//</span> |
340 | | <a name="l00485"></a>00485 A = A0; |
341 | | <a name="l00486"></a>00486 mu_const = mu0; |
342 | | <a name="l00487"></a>00487 Re=R0; |
343 | | <a name="l00488"></a>00488 Lambda = Lambda0; |
344 | | <a name="l00489"></a>00489 } |
345 | | <a name="l00490"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00490</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d" title="Set value of rvc . Result of this operation is stored in epdf use function _ep to...">condition</a> ( <span class="keyword">const</span> vec &cond ) { |
346 | | <a name="l00491"></a>00491 _mu = A*cond + mu_const; |
347 | | <a name="l00492"></a>00492 <span class="keywordtype">double</span> zeta; |
348 | | <a name="l00493"></a>00493 <span class="comment">//ugly hack!</span> |
349 | | <a name="l00494"></a>00494 <span class="keywordflow">if</span> ( ( cond.length() +1 ) ==Lambda.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ) { |
350 | | <a name="l00495"></a>00495 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( <a class="code" href="namespacebdm.html#b9016687c0e874ca5cdcf75ae28811aa" title="Concat two random variables.">concat</a> ( cond, vec_1 ( 1.0 ) ) ); |
351 | | <a name="l00496"></a>00496 } |
352 | | <a name="l00497"></a>00497 <span class="keywordflow">else</span> { |
353 | | <a name="l00498"></a>00498 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( cond ); |
354 | | <a name="l00499"></a>00499 } |
355 | | <a name="l00500"></a>00500 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> = Re; |
356 | | <a name="l00501"></a>00501 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>*= ( 1+zeta );<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
357 | | <a name="l00502"></a>00502 }; |
358 | | <a name="l00503"></a>00503 |
359 | | <a name="l00504"></a>00504 }; |
360 | | <a name="l00514"></a><a class="code" href="classbdm_1_1mgamma.html">00514</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_1mEF.html" title="Exponential family model.">mEF</a> { |
361 | | <a name="l00515"></a>00515 <span class="keyword">protected</span>: |
362 | | <a name="l00517"></a><a class="code" href="classbdm_1_1mgamma.html#bdc9f1e9e03c09e91103fee269864438">00517</a> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
363 | | <a name="l00519"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00519</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
364 | | <a name="l00521"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00521</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>; |
365 | | <a name="l00522"></a>00522 |
366 | | <a name="l00523"></a>00523 <span class="keyword">public</span>: |
367 | | <a name="l00525"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00525</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</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_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</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_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
368 | | <a name="l00527"></a>00527 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#0b486f7e52a3d8a39adbcbd325461c0d" 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> ); |
369 | | <a name="l00528"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00528</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/val;}; |
370 | | <a name="l00529"></a>00529 }; |
371 | | <a name="l00530"></a>00530 |
372 | | <a name="l00540"></a><a class="code" href="classbdm_1_1migamma.html">00540</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_1mEF.html" title="Exponential family model.">mEF</a> { |
373 | | <a name="l00541"></a>00541 <span class="keyword">protected</span>: |
374 | | <a name="l00543"></a><a class="code" href="classbdm_1_1migamma.html#a31b39d4179551b593c9e0d7d756783a">00543</a> <a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
375 | | <a name="l00545"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00545</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
376 | | <a name="l00547"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00547</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>; |
377 | | <a name="l00549"></a><a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5">00549</a> vec &<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>; |
378 | | <a name="l00550"></a>00550 |
379 | | <a name="l00551"></a>00551 <span class="keyword">public</span>: |
380 | | <a name="l00554"></a>00554 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</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_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
381 | | <a name="l00555"></a>00555 <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_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( m.<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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</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_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
382 | | <a name="l00557"></a>00557 |
383 | | <a name="l00559"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00559</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 ) { |
384 | | <a name="l00560"></a>00560 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>=k0; |
385 | | <a name="l00561"></a>00561 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( ( 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> ); |
386 | | <a name="l00562"></a>00562 }; |
387 | | <a name="l00563"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00563</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) { |
388 | | <a name="l00564"></a>00564 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>=elem_mult ( val, ( <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>-1.0 ) ); |
389 | | <a name="l00565"></a>00565 }; |
390 | | <a name="l00566"></a>00566 }; |
391 | | <a name="l00567"></a>00567 |
392 | | <a name="l00579"></a><a class="code" href="classbdm_1_1mgamma__fix.html">00579</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> { |
393 | | <a name="l00580"></a>00580 <span class="keyword">protected</span>: |
394 | | <a name="l00582"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa">00582</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>; |
395 | | <a name="l00584"></a><a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2">00584</a> vec <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>; |
396 | | <a name="l00585"></a>00585 <span class="keyword">public</span>: |
397 | | <a name="l00587"></a><a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d">00587</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> () {}; |
398 | | <a name="l00589"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2">00589</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 ) { |
399 | | <a name="l00590"></a>00590 <a class="code" href="classbdm_1_1mgamma.html#0b486f7e52a3d8a39adbcbd325461c0d" title="Set value of k.">mgamma::set_parameters</a> ( k0 ); |
400 | | <a name="l00591"></a>00591 <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; |
401 | | <a name="l00592"></a>00592 }; |
402 | | <a name="l00593"></a>00593 |
403 | | <a name="l00594"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">00594</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">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 epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/mean;}; |
404 | | <a name="l00595"></a>00595 }; |
405 | | <a name="l00596"></a>00596 |
406 | | <a name="l00597"></a>00597 |
407 | | <a name="l00610"></a><a class="code" href="classbdm_1_1migamma__fix.html">00610</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma__fix.html" title="Inverse-Gamma random walk around a fixed point.">migamma_fix</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> { |
408 | | <a name="l00611"></a>00611 <span class="keyword">protected</span>: |
409 | | <a name="l00613"></a><a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e">00613</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e" title="parameter l">l</a>; |
410 | | <a name="l00615"></a><a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780">00615</a> vec <a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a>; |
411 | | <a name="l00616"></a>00616 <span class="keyword">public</span>: |
412 | | <a name="l00618"></a><a class="code" href="classbdm_1_1migamma__fix.html#42a61f9468b2c435386f47ae8a5ddf7e">00618</a> <a class="code" href="classbdm_1_1migamma__fix.html#42a61f9468b2c435386f47ae8a5ddf7e" title="Constructor.">migamma_fix</a> ( ) : <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> (),<a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a> ( ) {}; |
413 | | <a name="l00620"></a><a class="code" href="classbdm_1_1migamma__fix.html#17f9ce1068660a4e8c05173bef7d7440">00620</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__fix.html#17f9ce1068660a4e8c05173bef7d7440" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0 ) { |
414 | | <a name="l00621"></a>00621 <a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151" title="Set value of k.">migamma::set_parameters</a> (ref0.length(), k0 ); |
415 | | <a name="l00622"></a>00622 <a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a>=pow ( ref0,1.0-l0 ); |
416 | | <a name="l00623"></a>00623 <a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e" title="parameter l">l</a>=l0; |
417 | | <a name="l00624"></a>00624 }; |
418 | | <a name="l00625"></a>00625 |
419 | | <a name="l00626"></a><a class="code" href="classbdm_1_1migamma__fix.html#cfbabd293795d44aae1b7c874e57c4b8">00626</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__fix.html#cfbabd293795d44aae1b7c874e57c4b8" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) { |
420 | | <a name="l00627"></a>00627 vec mean=elem_mult ( <a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a>,pow ( val,<a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e" title="parameter l">l</a> ) ); |
421 | | <a name="l00628"></a>00628 <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">migamma::condition</a> ( mean ); |
422 | | <a name="l00629"></a>00629 }; |
423 | | <a name="l00630"></a>00630 }; |
424 | | <a name="l00632"></a><a class="code" href="namespacebdm.html#33aac0be76ded31d2e3081c5a3f6c418">00632</a> <span class="keyword">enum</span> <a class="code" href="namespacebdm.html#33aac0be76ded31d2e3081c5a3f6c418" title="Switch between various resampling methods.">RESAMPLING_METHOD</a> { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
425 | | <a name="l00638"></a><a class="code" href="classbdm_1_1eEmp.html">00638</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> { |
426 | | <a name="l00639"></a>00639 <span class="keyword">protected</span> : |
427 | | <a name="l00641"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">00641</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
428 | | <a name="l00643"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">00643</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
429 | | <a name="l00645"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">00645</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
430 | | <a name="l00646"></a>00646 <span class="keyword">public</span>: |
431 | | <a name="l00648"></a><a class="code" href="classbdm_1_1eEmp.html#34d7f929fbab6c1e4ce318c56a6399c7">00648</a> <a class="code" href="classbdm_1_1eEmp.html#34d7f929fbab6c1e4ce318c56a6399c7" title="Default constructor.">eEmp</a> ( <span class="keywordtype">int</span> n0 ) :<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#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> ( n0 ),<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> ),<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> ) {}; |
432 | | <a name="l00650"></a>00650 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#82320074a9b0ad7e1bb33a6e885b65d7" title="Set samples and weights.">set_parameters</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 ); |
433 | | <a name="l00652"></a>00652 <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 ); |
434 | | <a name="l00654"></a><a class="code" href="classbdm_1_1eEmp.html#dccd02eaa4c45e858a6351723686ac85">00654</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#dccd02eaa4c45e858a6351723686ac85" title="Set sample.">set_n</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#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 );}; |
435 | | <a name="l00656"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">00656</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>;}; |
436 | | <a name="l00658"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">00658</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" 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>;}; |
437 | | <a name="l00660"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">00660</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>;}; |
438 | | <a name="l00662"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">00662</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" 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>;}; |
439 | | <a name="l00664"></a>00664 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> ( <a class="code" href="namespacebdm.html#33aac0be76ded31d2e3081c5a3f6c418" title="Switch between various resampling methods.">RESAMPLING_METHOD</a> method = SYSTEMATIC ); |
440 | | <a name="l00666"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">00666</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;} |
441 | | <a name="l00668"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">00668</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;} |
442 | | <a name="l00669"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">00669</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
443 | | <a name="l00670"></a>00670 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
444 | | <a name="l00671"></a>00671 <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 );} |
445 | | <a name="l00672"></a>00672 <span class="keywordflow">return</span> pom; |
446 | | <a name="l00673"></a>00673 } |
447 | | <a name="l00674"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">00674</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
448 | | <a name="l00675"></a>00675 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
449 | | <a name="l00676"></a>00676 <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 );} |
450 | | <a name="l00677"></a>00677 <span class="keywordflow">return</span> pom-pow ( <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(),2 ); |
451 | | <a name="l00678"></a>00678 } |
452 | | <a name="l00679"></a>00679 }; |
453 | | <a name="l00680"></a>00680 |
454 | | <a name="l00681"></a>00681 |
455 | | <a name="l00683"></a>00683 |
456 | | <a name="l00684"></a>00684 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
457 | | <a name="l00685"></a>00685 enorm<sq_T>::enorm ( ) :eEF ( ), mu ( ),R ( ) {}; |
458 | | <a name="l00686"></a>00686 |
459 | | <a name="l00687"></a>00687 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
460 | | <a name="l00688"></a>00688 <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 ) { |
461 | | <a name="l00689"></a>00689 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
462 | | <a name="l00690"></a>00690 mu = mu0; |
463 | | <a name="l00691"></a>00691 R = R0; |
464 | | <a name="l00692"></a>00692 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = mu0.length(); |
465 | | <a name="l00693"></a>00693 }; |
466 | | <a name="l00694"></a>00694 |
467 | | <a name="l00695"></a>00695 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
468 | | <a name="l00696"></a><a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2">00696</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::dupdate</a> ( mat &v, <span class="keywordtype">double</span> nu ) { |
469 | | <a name="l00697"></a>00697 <span class="comment">//</span> |
470 | | <a name="l00698"></a>00698 }; |
471 | | <a name="l00699"></a>00699 |
472 | | <a name="l00700"></a>00700 <span class="comment">// template<class sq_T></span> |
473 | | <a name="l00701"></a>00701 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
474 | | <a name="l00702"></a>00702 <span class="comment">// //</span> |
475 | | <a name="l00703"></a>00703 <span class="comment">// };</span> |
476 | | <a name="l00704"></a>00704 |
477 | | <a name="l00705"></a>00705 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
478 | | <a name="l00706"></a><a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766">00706</a> vec <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::sample</a>()<span class="keyword"> const </span>{ |
479 | | <a name="l00707"></a>00707 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
480 | | <a name="l00708"></a>00708 <span class="preprocessor">#pragma omp critical</span> |
481 | | <a name="l00709"></a>00709 <span class="preprocessor"></span> <a class="code" href="namespacebdm.html#c959a7382efbcc31af4b58cf0f0f951a" title="Global Normal_RNG.">NorRNG</a>.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
482 | | <a name="l00710"></a>00710 vec smp = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
483 | | <a name="l00711"></a>00711 |
484 | | <a name="l00712"></a>00712 smp += <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
485 | | <a name="l00713"></a>00713 <span class="keywordflow">return</span> smp; |
486 | | <a name="l00714"></a>00714 }; |
487 | | <a name="l00715"></a>00715 |
488 | | <a name="l00716"></a>00716 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
489 | | <a name="l00717"></a>00717 mat <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::sample</a> ( <span class="keywordtype">int</span> N )<span class="keyword"> const </span>{ |
490 | | <a name="l00718"></a>00718 mat X ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,N ); |
491 | | <a name="l00719"></a>00719 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
492 | | <a name="l00720"></a>00720 vec pom; |
493 | | <a name="l00721"></a>00721 <span class="keywordtype">int</span> i; |
494 | | <a name="l00722"></a>00722 |
495 | | <a name="l00723"></a>00723 <span class="keywordflow">for</span> ( i=0;i<N;i++ ) { |
496 | | <a name="l00724"></a>00724 <span class="preprocessor">#pragma omp critical</span> |
497 | | <a name="l00725"></a>00725 <span class="preprocessor"></span> <a class="code" href="namespacebdm.html#c959a7382efbcc31af4b58cf0f0f951a" title="Global Normal_RNG.">NorRNG</a>.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
498 | | <a name="l00726"></a>00726 pom = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
499 | | <a name="l00727"></a>00727 pom +=<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
500 | | <a name="l00728"></a>00728 X.set_col ( i, pom ); |
501 | | <a name="l00729"></a>00729 } |
| 339 | <a name="l00429"></a>00429 <span class="keywordtype">double</span> eval ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>;} |
| 340 | <a name="l00430"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00430</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>;} |
| 341 | <a name="l00431"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00431</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 342 | <a name="l00432"></a>00432 vec smp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 343 | <a name="l00433"></a>00433 <span class="preprocessor">#pragma omp critical</span> |
| 344 | <a name="l00434"></a>00434 <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 ); |
| 345 | <a name="l00435"></a>00435 <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 ); |
| 346 | <a name="l00436"></a>00436 } |
| 347 | <a name="l00438"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00438</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;} |
| 348 | <a name="l00439"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00439</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;} |
| 349 | <a name="l00440"></a>00440 }; |
| 350 | <a name="l00441"></a>00441 |
| 351 | <a name="l00442"></a>00442 |
| 352 | <a name="l00448"></a>00448 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 353 | <a name="l00449"></a><a class="code" href="classbdm_1_1mlnorm.html">00449</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_1mEF.html" title="Exponential family model.">mEF</a> { |
| 354 | <a name="l00450"></a>00450 <span class="keyword">protected</span>: |
| 355 | <a name="l00452"></a><a class="code" href="classbdm_1_1mlnorm.html#150ad6acb223b0a0abeaf92346686dcd">00452</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
| 356 | <a name="l00453"></a>00453 mat A; |
| 357 | <a name="l00454"></a>00454 vec mu_const; |
| 358 | <a name="l00455"></a>00455 vec& _mu; <span class="comment">//cached epdf.mu;</span> |
| 359 | <a name="l00456"></a>00456 <span class="keyword">public</span>: |
| 360 | <a name="l00459"></a>00459 <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_1mEF.html" title="Exponential family model.">mEF</a> (),<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ),A ( ),_mu ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._mu() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a> =&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; }; |
| 361 | <a name="l00460"></a>00460 <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, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ),_mu ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._mu() ) { |
| 362 | <a name="l00461"></a>00461 <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</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_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">set_parameters</a> ( A,mu0,R ); |
| 363 | <a name="l00462"></a>00462 }; |
| 364 | <a name="l00464"></a>00464 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">set_parameters</a> ( <span class="keyword">const</span> mat &A, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R ); |
| 365 | <a name="l00467"></a>00467 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">condition</a> ( <span class="keyword">const</span> vec &cond ); |
| 366 | <a name="l00468"></a>00468 |
| 367 | <a name="l00470"></a><a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced">00470</a> vec& <a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced" title="access function">_mu_const</a>() {<span class="keywordflow">return</span> mu_const;} |
| 368 | <a name="l00472"></a><a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614">00472</a> mat& <a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614" title="access function">_A</a>() {<span class="keywordflow">return</span> A;} |
| 369 | <a name="l00474"></a><a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604">00474</a> mat <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R().to_mat();} |
| 370 | <a name="l00475"></a>00475 |
| 371 | <a name="l00476"></a>00476 <span class="keyword">template</span><<span class="keyword">class</span> sq_M> |
| 372 | <a name="l00477"></a>00477 <span class="keyword">friend</span> std::ostream &operator<< ( std::ostream &os, mlnorm<sq_M> &ml ); |
| 373 | <a name="l00478"></a>00478 }; |
| 374 | <a name="l00479"></a>00479 |
| 375 | <a name="l00487"></a><a class="code" href="classbdm_1_1mlstudent.html">00487</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> { |
| 376 | <a name="l00488"></a>00488 <span class="keyword">protected</span>: |
| 377 | <a name="l00489"></a>00489 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Lambda; |
| 378 | <a name="l00490"></a>00490 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>; |
| 379 | <a name="l00491"></a>00491 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Re; |
| 380 | <a name="l00492"></a>00492 <span class="keyword">public</span>: |
| 381 | <a name="l00493"></a>00493 <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<ldmat></a> (), |
| 382 | <a name="l00494"></a>00494 Lambda (), <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R() ) {} |
| 383 | <a name="l00495"></a>00495 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0 ) { |
| 384 | <a name="l00496"></a>00496 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
| 385 | <a name="l00497"></a>00497 it_assert_debug ( R0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ==A0.rows(),<span class="stringliteral">""</span> ); |
| 386 | <a name="l00498"></a>00498 |
| 387 | <a name="l00499"></a>00499 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( mu0,Lambda ); <span class="comment">//</span> |
| 388 | <a name="l00500"></a>00500 A = A0; |
| 389 | <a name="l00501"></a>00501 mu_const = mu0; |
| 390 | <a name="l00502"></a>00502 Re=R0; |
| 391 | <a name="l00503"></a>00503 Lambda = Lambda0; |
| 392 | <a name="l00504"></a>00504 } |
| 393 | <a name="l00505"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00505</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> ( <span class="keyword">const</span> vec &cond ) { |
| 394 | <a name="l00506"></a>00506 _mu = A*cond + mu_const; |
| 395 | <a name="l00507"></a>00507 <span class="keywordtype">double</span> zeta; |
| 396 | <a name="l00508"></a>00508 <span class="comment">//ugly hack!</span> |
| 397 | <a name="l00509"></a>00509 <span class="keywordflow">if</span> ( ( cond.length() +1 ) ==Lambda.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ) { |
| 398 | <a name="l00510"></a>00510 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( concat ( cond, vec_1 ( 1.0 ) ) ); |
| 399 | <a name="l00511"></a>00511 } |
| 400 | <a name="l00512"></a>00512 <span class="keywordflow">else</span> { |
| 401 | <a name="l00513"></a>00513 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( cond ); |
| 402 | <a name="l00514"></a>00514 } |
| 403 | <a name="l00515"></a>00515 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> = Re; |
| 404 | <a name="l00516"></a>00516 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>*= ( 1+zeta );<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
| 405 | <a name="l00517"></a>00517 }; |
| 406 | <a name="l00518"></a>00518 |
| 407 | <a name="l00519"></a>00519 }; |
| 408 | <a name="l00529"></a><a class="code" href="classbdm_1_1mgamma.html">00529</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_1mEF.html" title="Exponential family model.">mEF</a> { |
| 409 | <a name="l00530"></a>00530 <span class="keyword">protected</span>: |
| 410 | <a name="l00532"></a><a class="code" href="classbdm_1_1mgamma.html#bdc9f1e9e03c09e91103fee269864438">00532</a> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
| 411 | <a name="l00534"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00534</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
| 412 | <a name="l00536"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00536</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>; |
| 413 | <a name="l00537"></a>00537 |
| 414 | <a name="l00538"></a>00538 <span class="keyword">public</span>: |
| 415 | <a name="l00540"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00540</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</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_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</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_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
| 416 | <a name="l00542"></a>00542 <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 ); |
| 417 | <a name="l00543"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00543</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/val;}; |
| 418 | <a name="l00544"></a>00544 }; |
| 419 | <a name="l00545"></a>00545 |
| 420 | <a name="l00555"></a><a class="code" href="classbdm_1_1migamma.html">00555</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_1mEF.html" title="Exponential family model.">mEF</a> { |
| 421 | <a name="l00556"></a>00556 <span class="keyword">protected</span>: |
| 422 | <a name="l00558"></a><a class="code" href="classbdm_1_1migamma.html#a31b39d4179551b593c9e0d7d756783a">00558</a> <a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
| 423 | <a name="l00560"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00560</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
| 424 | <a name="l00562"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00562</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>; |
| 425 | <a name="l00564"></a><a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5">00564</a> vec &<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>; |
| 426 | <a name="l00565"></a>00565 |
| 427 | <a name="l00566"></a>00566 <span class="keyword">public</span>: |
| 428 | <a name="l00569"></a>00569 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</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_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
| 429 | <a name="l00570"></a>00570 <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_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( m.<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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</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_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</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_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
| 430 | <a name="l00572"></a>00572 |
| 431 | <a name="l00574"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00574</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 ) { |
| 432 | <a name="l00575"></a>00575 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>=k0; |
| 433 | <a name="l00576"></a>00576 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( ( 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> ); |
| 434 | <a name="l00577"></a>00577 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
| 435 | <a name="l00578"></a>00578 }; |
| 436 | <a name="l00579"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00579</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) { |
| 437 | <a name="l00580"></a>00580 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>=elem_mult ( val, ( <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>-1.0 ) ); |
| 438 | <a name="l00581"></a>00581 }; |
| 439 | <a name="l00582"></a>00582 }; |
| 440 | <a name="l00583"></a>00583 |
| 441 | <a name="l00595"></a><a class="code" href="classbdm_1_1mgamma__fix.html">00595</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> { |
| 442 | <a name="l00596"></a>00596 <span class="keyword">protected</span>: |
| 443 | <a name="l00598"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa">00598</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>; |
| 444 | <a name="l00600"></a><a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2">00600</a> vec <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>; |
| 445 | <a name="l00601"></a>00601 <span class="keyword">public</span>: |
| 446 | <a name="l00603"></a><a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d">00603</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> () {}; |
| 447 | <a name="l00605"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2">00605</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 ) { |
| 448 | <a name="l00606"></a>00606 <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">mgamma::set_parameters</a> ( k0, ref0 ); |
| 449 | <a name="l00607"></a>00607 <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; |
| 450 | <a name="l00608"></a>00608 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=dimension(); |
| 451 | <a name="l00609"></a>00609 }; |
| 452 | <a name="l00610"></a>00610 |
| 453 | <a name="l00611"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">00611</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">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 epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/mean;}; |
| 454 | <a name="l00612"></a>00612 }; |
| 455 | <a name="l00613"></a>00613 |
| 456 | <a name="l00614"></a>00614 |
| 457 | <a name="l00627"></a><a class="code" href="classbdm_1_1migamma__fix.html">00627</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma__fix.html" title="Inverse-Gamma random walk around a fixed point.">migamma_fix</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> { |
| 458 | <a name="l00628"></a>00628 <span class="keyword">protected</span>: |
| 459 | <a name="l00630"></a><a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e">00630</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e" title="parameter l">l</a>; |
| 460 | <a name="l00632"></a><a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780">00632</a> vec <a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a>; |
| 461 | <a name="l00633"></a>00633 <span class="keyword">public</span>: |
| 462 | <a name="l00635"></a><a class="code" href="classbdm_1_1migamma__fix.html#42a61f9468b2c435386f47ae8a5ddf7e">00635</a> <a class="code" href="classbdm_1_1migamma__fix.html#42a61f9468b2c435386f47ae8a5ddf7e" title="Constructor.">migamma_fix</a> ( ) : <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> (),<a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a> ( ) {}; |
| 463 | <a name="l00637"></a><a class="code" href="classbdm_1_1migamma__fix.html#17f9ce1068660a4e8c05173bef7d7440">00637</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__fix.html#17f9ce1068660a4e8c05173bef7d7440" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0 ) { |
| 464 | <a name="l00638"></a>00638 <a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151" title="Set value of k.">migamma::set_parameters</a> ( ref0.length(), k0 ); |
| 465 | <a name="l00639"></a>00639 <a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a>=pow ( ref0,1.0-l0 ); |
| 466 | <a name="l00640"></a>00640 <a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e" title="parameter l">l</a>=l0; |
| 467 | <a name="l00641"></a>00641 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
| 468 | <a name="l00642"></a>00642 }; |
| 469 | <a name="l00643"></a>00643 |
| 470 | <a name="l00644"></a><a class="code" href="classbdm_1_1migamma__fix.html#cfbabd293795d44aae1b7c874e57c4b8">00644</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__fix.html#cfbabd293795d44aae1b7c874e57c4b8" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) { |
| 471 | <a name="l00645"></a>00645 vec mean=elem_mult ( <a class="code" href="classbdm_1_1migamma__fix.html#5d453e5a2bdfc9a16c8acb8842dc9780" title="reference vector">refl</a>,pow ( val,<a class="code" href="classbdm_1_1migamma__fix.html#e1c344accac36d7ccc3ffa502e8d2f4e" title="parameter l">l</a> ) ); |
| 472 | <a name="l00646"></a>00646 <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">migamma::condition</a> ( mean ); |
| 473 | <a name="l00647"></a>00647 }; |
| 474 | <a name="l00648"></a>00648 }; |
| 475 | <a name="l00650"></a>00650 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
| 476 | <a name="l00656"></a><a class="code" href="classbdm_1_1eEmp.html">00656</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> { |
| 477 | <a name="l00657"></a>00657 <span class="keyword">protected</span> : |
| 478 | <a name="l00659"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">00659</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
| 479 | <a name="l00661"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">00661</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
| 480 | <a name="l00663"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">00663</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
| 481 | <a name="l00664"></a>00664 <span class="keyword">public</span>: |
| 482 | <a name="l00667"></a>00667 <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> ( ) {}; |
| 483 | <a name="l00668"></a>00668 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">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>) {}; |
| 484 | <a name="l00670"></a>00670 |
| 485 | <a name="l00672"></a>00672 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#82320074a9b0ad7e1bb33a6e885b65d7" title="Set samples and weights.">set_parameters</a> ( <span class="keyword">const</span> vec &w0, <span class="keyword">const</span> epdf* pdf0 ); |
| 486 | <a name="l00674"></a>00674 <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> epdf* pdf0 ); |
| 487 | <a name="l00676"></a><a class="code" href="classbdm_1_1eEmp.html#dccd02eaa4c45e858a6351723686ac85">00676</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#dccd02eaa4c45e858a6351723686ac85" title="Set sample.">set_n</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#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 );}; |
| 488 | <a name="l00678"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">00678</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>;}; |
| 489 | <a name="l00680"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">00680</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" 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>;}; |
| 490 | <a name="l00682"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">00682</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>;}; |
| 491 | <a name="l00684"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">00684</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" 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>;}; |
| 492 | <a name="l00686"></a>00686 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 ); |
| 493 | <a name="l00688"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">00688</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;} |
| 494 | <a name="l00690"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">00690</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;} |
| 495 | <a name="l00691"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">00691</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 496 | <a name="l00692"></a>00692 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 497 | <a name="l00693"></a>00693 <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 );} |
| 498 | <a name="l00694"></a>00694 <span class="keywordflow">return</span> pom; |
| 499 | <a name="l00695"></a>00695 } |
| 500 | <a name="l00696"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">00696</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
| 501 | <a name="l00697"></a>00697 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 502 | <a name="l00698"></a>00698 <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 );} |
| 503 | <a name="l00699"></a>00699 <span class="keywordflow">return</span> pom-pow ( <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(),2 ); |
| 504 | <a name="l00700"></a>00700 } |
| 505 | <a name="l00701"></a>00701 }; |
| 506 | <a name="l00702"></a>00702 |
| 507 | <a name="l00703"></a>00703 |
| 508 | <a name="l00705"></a>00705 |
| 509 | <a name="l00706"></a>00706 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 510 | <a name="l00707"></a>00707 <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 ) { |
| 511 | <a name="l00708"></a>00708 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
| 512 | <a name="l00709"></a>00709 mu = mu0; |
| 513 | <a name="l00710"></a>00710 R = R0; |
| 514 | <a name="l00711"></a>00711 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = mu0.length(); |
| 515 | <a name="l00712"></a>00712 }; |
| 516 | <a name="l00713"></a>00713 |
| 517 | <a name="l00714"></a>00714 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 518 | <a name="l00715"></a><a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2">00715</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::dupdate</a> ( mat &v, <span class="keywordtype">double</span> nu ) { |
| 519 | <a name="l00716"></a>00716 <span class="comment">//</span> |
| 520 | <a name="l00717"></a>00717 }; |
| 521 | <a name="l00718"></a>00718 |
| 522 | <a name="l00719"></a>00719 <span class="comment">// template<class sq_T></span> |
| 523 | <a name="l00720"></a>00720 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
| 524 | <a name="l00721"></a>00721 <span class="comment">// //</span> |
| 525 | <a name="l00722"></a>00722 <span class="comment">// };</span> |
| 526 | <a name="l00723"></a>00723 |
| 527 | <a name="l00724"></a>00724 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 528 | <a name="l00725"></a><a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766">00725</a> vec <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::sample</a>()<span class="keyword"> const </span>{ |
| 529 | <a name="l00726"></a>00726 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 530 | <a name="l00727"></a>00727 <span class="preprocessor">#pragma omp critical</span> |
| 531 | <a name="l00728"></a>00728 <span class="preprocessor"></span> NorRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
| 532 | <a name="l00729"></a>00729 vec smp = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
534 | | <a name="l00762"></a><a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f">00762</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T>::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 ) { |
535 | | <a name="l00763"></a>00763 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
536 | | <a name="l00764"></a>00764 it_assert_debug ( A0.rows() ==R0.rows(),<span class="stringliteral">""</span> ); |
537 | | <a name="l00765"></a>00765 |
538 | | <a name="l00766"></a>00766 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( A.rows() ),R0 ); |
539 | | <a name="l00767"></a>00767 A = A0; |
540 | | <a name="l00768"></a>00768 mu_const = mu0; |
541 | | <a name="l00769"></a>00769 } |
542 | | <a name="l00770"></a>00770 |
543 | | <a name="l00771"></a>00771 <span class="comment">// template<class sq_T></span> |
544 | | <a name="l00772"></a>00772 <span class="comment">// vec mlnorm<sq_T>::samplecond (const vec &cond, double &lik ) {</span> |
545 | | <a name="l00773"></a>00773 <span class="comment">// this->condition ( cond );</span> |
546 | | <a name="l00774"></a>00774 <span class="comment">// vec smp = epdf.sample();</span> |
547 | | <a name="l00775"></a>00775 <span class="comment">// lik = epdf.eval ( smp );</span> |
548 | | <a name="l00776"></a>00776 <span class="comment">// return smp;</span> |
549 | | <a name="l00777"></a>00777 <span class="comment">// }</span> |
550 | | <a name="l00778"></a>00778 |
551 | | <a name="l00779"></a>00779 <span class="comment">// template<class sq_T></span> |
552 | | <a name="l00780"></a>00780 <span class="comment">// mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) {</span> |
553 | | <a name="l00781"></a>00781 <span class="comment">// int i;</span> |
554 | | <a name="l00782"></a>00782 <span class="comment">// int dim = rv.count();</span> |
555 | | <a name="l00783"></a>00783 <span class="comment">// mat Smp ( dim,n );</span> |
556 | | <a name="l00784"></a>00784 <span class="comment">// vec smp ( dim );</span> |
557 | | <a name="l00785"></a>00785 <span class="comment">// this->condition ( cond );</span> |
558 | | <a name="l00786"></a>00786 <span class="comment">//</span> |
559 | | <a name="l00787"></a>00787 <span class="comment">// for ( i=0; i<n; i++ ) {</span> |
560 | | <a name="l00788"></a>00788 <span class="comment">// smp = epdf.sample();</span> |
561 | | <a name="l00789"></a>00789 <span class="comment">// lik ( i ) = epdf.eval ( smp );</span> |
562 | | <a name="l00790"></a>00790 <span class="comment">// Smp.set_col ( i ,smp );</span> |
563 | | <a name="l00791"></a>00791 <span class="comment">// }</span> |
564 | | <a name="l00792"></a>00792 <span class="comment">//</span> |
565 | | <a name="l00793"></a>00793 <span class="comment">// return Smp;</span> |
566 | | <a name="l00794"></a>00794 <span class="comment">// }</span> |
567 | | <a name="l00795"></a>00795 |
568 | | <a name="l00796"></a>00796 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
569 | | <a name="l00797"></a><a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">00797</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T>::condition</a> ( <span class="keyword">const</span> vec &cond ) { |
570 | | <a name="l00798"></a>00798 _mu = A*cond + mu_const; |
571 | | <a name="l00799"></a>00799 <span class="comment">//R is already assigned;</span> |
572 | | <a name="l00800"></a>00800 } |
573 | | <a name="l00801"></a>00801 |
574 | | <a name="l00802"></a>00802 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
575 | | <a name="l00803"></a><a class="code" href="classbdm_1_1enorm.html#cd02d76e9d4f96bdd3fa6b604e273039">00803</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_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::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>{ |
576 | | <a name="l00804"></a>00804 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
577 | | <a name="l00805"></a>00805 |
578 | | <a name="l00806"></a>00806 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,irvn ); |
579 | | <a name="l00807"></a>00807 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* tmp = <span class="keyword">new</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> ( ); |
580 | | <a name="l00808"></a>00808 tmp-><a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
581 | | <a name="l00809"></a>00809 tmp-><a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ), Rn ); |
582 | | <a name="l00810"></a>00810 <span class="keywordflow">return</span> tmp; |
583 | | <a name="l00811"></a>00811 } |
584 | | <a name="l00812"></a>00812 |
585 | | <a name="l00813"></a>00813 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
586 | | <a name="l00814"></a><a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26">00814</a> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::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>{ |
587 | | <a name="l00815"></a>00815 |
588 | | <a name="l00816"></a>00816 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(),<span class="stringliteral">""</span> ); |
589 | | <a name="l00817"></a>00817 |
590 | | <a name="l00818"></a>00818 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvc = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#aec44dabdf0a6d90fbae95e1356eda39" title="Subtract another variable from the current one.">subt</a> ( rvn ); |
591 | | <a name="l00819"></a>00819 it_assert_debug ( ( rvc.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() +rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ==<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ),<span class="stringliteral">"wrong rvn"</span> ); |
592 | | <a name="l00820"></a>00820 <span class="comment">//Permutation vector of the new R</span> |
593 | | <a name="l00821"></a>00821 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
594 | | <a name="l00822"></a>00822 ivec irvc = rvc.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
595 | | <a name="l00823"></a>00823 ivec perm=<a class="code" href="namespacebdm.html#b9016687c0e874ca5cdcf75ae28811aa" title="Concat two random variables.">concat</a> ( irvn , irvc ); |
596 | | <a name="l00824"></a>00824 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,perm ); |
597 | | <a name="l00825"></a>00825 |
598 | | <a name="l00826"></a>00826 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
599 | | <a name="l00827"></a>00827 mat S=Rn.to_mat(); |
600 | | <a name="l00828"></a>00828 <span class="comment">//fixme</span> |
601 | | <a name="l00829"></a>00829 <span class="keywordtype">int</span> n=rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>()-1; |
602 | | <a name="l00830"></a>00830 <span class="keywordtype">int</span> end=<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows()-1; |
603 | | <a name="l00831"></a>00831 mat S11 = S.get ( 0,n, 0, n ); |
604 | | <a name="l00832"></a>00832 mat S12 = S.get ( 0, n , rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
605 | | <a name="l00833"></a>00833 mat S22 = S.get ( rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end, rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
| 565 | <a name="l00762"></a><a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3">00762</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
| 566 | <a name="l00763"></a>00763 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
| 567 | <a name="l00764"></a>00764 <span class="keywordtype">double</span> tmp=-0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.invqform ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>-val ) );<span class="comment">// - lognc();</span> |
| 568 | <a name="l00765"></a>00765 <span class="keywordflow">return</span> tmp; |
| 569 | <a name="l00766"></a>00766 }; |
| 570 | <a name="l00767"></a>00767 |
| 571 | <a name="l00768"></a>00768 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 572 | <a name="l00769"></a><a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32">00769</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::lognc</a> ()<span class="keyword"> const </span>{ |
| 573 | <a name="l00770"></a>00770 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
| 574 | <a name="l00771"></a>00771 <span class="keywordtype">double</span> tmp=0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.cols() * 1.83787706640935 +<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.logdet() ); |
| 575 | <a name="l00772"></a>00772 <span class="keywordflow">return</span> tmp; |
| 576 | <a name="l00773"></a>00773 }; |
| 577 | <a name="l00774"></a>00774 |
| 578 | <a name="l00775"></a>00775 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 579 | <a name="l00776"></a><a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f">00776</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T>::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 ) { |
| 580 | <a name="l00777"></a>00777 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
| 581 | <a name="l00778"></a>00778 it_assert_debug ( A0.rows() ==R0.rows(),<span class="stringliteral">""</span> ); |
| 582 | <a name="l00779"></a>00779 |
| 583 | <a name="l00780"></a>00780 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( A0.rows() ),R0 ); |
| 584 | <a name="l00781"></a>00781 A = A0; |
| 585 | <a name="l00782"></a>00782 mu_const = mu0; |
| 586 | <a name="l00783"></a>00783 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=A0.cols(); |
| 587 | <a name="l00784"></a>00784 } |
| 588 | <a name="l00785"></a>00785 |
| 589 | <a name="l00786"></a>00786 <span class="comment">// template<class sq_T></span> |
| 590 | <a name="l00787"></a>00787 <span class="comment">// vec mlnorm<sq_T>::samplecond (const vec &cond, double &lik ) {</span> |
| 591 | <a name="l00788"></a>00788 <span class="comment">// this->condition ( cond );</span> |
| 592 | <a name="l00789"></a>00789 <span class="comment">// vec smp = epdf.sample();</span> |
| 593 | <a name="l00790"></a>00790 <span class="comment">// lik = epdf.eval ( smp );</span> |
| 594 | <a name="l00791"></a>00791 <span class="comment">// return smp;</span> |
| 595 | <a name="l00792"></a>00792 <span class="comment">// }</span> |
| 596 | <a name="l00793"></a>00793 |
| 597 | <a name="l00794"></a>00794 <span class="comment">// template<class sq_T></span> |
| 598 | <a name="l00795"></a>00795 <span class="comment">// mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) {</span> |
| 599 | <a name="l00796"></a>00796 <span class="comment">// int i;</span> |
| 600 | <a name="l00797"></a>00797 <span class="comment">// int dim = rv.count();</span> |
| 601 | <a name="l00798"></a>00798 <span class="comment">// mat Smp ( dim,n );</span> |
| 602 | <a name="l00799"></a>00799 <span class="comment">// vec smp ( dim );</span> |
| 603 | <a name="l00800"></a>00800 <span class="comment">// this->condition ( cond );</span> |
| 604 | <a name="l00801"></a>00801 <span class="comment">//</span> |
| 605 | <a name="l00802"></a>00802 <span class="comment">// for ( i=0; i<n; i++ ) {</span> |
| 606 | <a name="l00803"></a>00803 <span class="comment">// smp = epdf.sample();</span> |
| 607 | <a name="l00804"></a>00804 <span class="comment">// lik ( i ) = epdf.eval ( smp );</span> |
| 608 | <a name="l00805"></a>00805 <span class="comment">// Smp.set_col ( i ,smp );</span> |
| 609 | <a name="l00806"></a>00806 <span class="comment">// }</span> |
| 610 | <a name="l00807"></a>00807 <span class="comment">//</span> |
| 611 | <a name="l00808"></a>00808 <span class="comment">// return Smp;</span> |
| 612 | <a name="l00809"></a>00809 <span class="comment">// }</span> |
| 613 | <a name="l00810"></a>00810 |
| 614 | <a name="l00811"></a>00811 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 615 | <a name="l00812"></a><a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">00812</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T>::condition</a> ( <span class="keyword">const</span> vec &cond ) { |
| 616 | <a name="l00813"></a>00813 _mu = A*cond + mu_const; |
| 617 | <a name="l00814"></a>00814 <span class="comment">//R is already assigned;</span> |
| 618 | <a name="l00815"></a>00815 } |
| 619 | <a name="l00816"></a>00816 |
| 620 | <a name="l00817"></a>00817 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 621 | <a name="l00818"></a><a class="code" href="classbdm_1_1enorm.html#cd02d76e9d4f96bdd3fa6b604e273039">00818</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_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::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>{ |
| 622 | <a name="l00819"></a>00819 it_assert_debug(<a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(), <span class="stringliteral">"rv description is not assigned"</span>); |
| 623 | <a name="l00820"></a>00820 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
| 624 | <a name="l00821"></a>00821 |
| 625 | <a name="l00822"></a>00822 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,irvn ); <span class="comment">//select rows and columns of R</span> |
| 626 | <a name="l00823"></a>00823 |
| 627 | <a name="l00824"></a>00824 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* tmp = <span class="keyword">new</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>; |
| 628 | <a name="l00825"></a>00825 tmp-><a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
| 629 | <a name="l00826"></a>00826 tmp-><a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ), Rn ); |
| 630 | <a name="l00827"></a>00827 <span class="keywordflow">return</span> tmp; |
| 631 | <a name="l00828"></a>00828 } |
| 632 | <a name="l00829"></a>00829 |
| 633 | <a name="l00830"></a>00830 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 634 | <a name="l00831"></a><a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26">00831</a> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T>::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>{ |
| 635 | <a name="l00832"></a>00832 |
| 636 | <a name="l00833"></a>00833 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(),<span class="stringliteral">"rvs are not assigned"</span> ); |