1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: libEF.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>libEF.h</h1><a href="libEF_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef EF_H</span> |
---|
67 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define EF_H</span> |
---|
68 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
69 | <a name="l00016"></a>00016 |
---|
70 | <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="libBM_8h.html" title="Bayesian Models (bm) that use Bayes rule to learn from observations.">libBM.h</a>"</span> |
---|
71 | <a name="l00018"></a>00018 <span class="preprocessor">#include "../math/chmat.h"</span> |
---|
72 | <a name="l00019"></a>00019 <span class="comment">//#include <std></span> |
---|
73 | <a name="l00020"></a>00020 |
---|
74 | <a name="l00021"></a>00021 <span class="keyword">namespace </span>bdm { |
---|
75 | <a name="l00022"></a>00022 |
---|
76 | <a name="l00023"></a>00023 |
---|
77 | <a name="l00025"></a>00025 <span class="keyword">extern</span> Uniform_RNG UniRNG; |
---|
78 | <a name="l00027"></a>00027 <span class="keyword">extern</span> Normal_RNG NorRNG; |
---|
79 | <a name="l00029"></a>00029 <span class="keyword">extern</span> <a class="code" href="classitpp_1_1Gamma__RNG.html" title="Gamma distribution.">Gamma_RNG</a> GamRNG; |
---|
80 | <a name="l00030"></a>00030 |
---|
81 | <a name="l00037"></a><a class="code" href="classbdm_1_1eEF.html">00037</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</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> { |
---|
82 | <a name="l00038"></a>00038 <span class="keyword">public</span>: |
---|
83 | <a name="l00039"></a>00039 <span class="comment">// eEF() :epdf() {};</span> |
---|
84 | <a name="l00041"></a><a class="code" href="classbdm_1_1eEF.html#d5459d472d0feca7cf1fb5f65c4b9ef4">00041</a> <span class="comment"></span> <a class="code" href="classbdm_1_1eEF.html#d5459d472d0feca7cf1fb5f65c4b9ef4" title="default constructor">eEF</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ) {}; |
---|
85 | <a name="l00043"></a>00043 <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEF.html#cd678fc9b02007a4b8d6692e746f1bf8" title="logarithm of the normalizing constant, ">lognc</a>() <span class="keyword">const</span> =0; |
---|
86 | <a name="l00045"></a><a class="code" href="classbdm_1_1eEF.html#deef7d6273ba4d5a5cf0bbd91ec7277a">00045</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEF.html#deef7d6273ba4d5a5cf0bbd91ec7277a" title="TODO decide if it is really needed.">dupdate</a> ( mat &v ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
87 | <a name="l00047"></a><a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6">00047</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6" title="Evaluate normalized log-probability.">evallog_nn</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;}; |
---|
88 | <a name="l00049"></a><a class="code" href="classbdm_1_1eEF.html#a36d06ecdd6f4c79dc122510eaccc692">00049</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEF.html#a36d06ecdd6f4c79dc122510eaccc692" title="Evaluate normalized log-probability.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordtype">double</span> tmp;tmp= <a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6" title="Evaluate normalized log-probability.">evallog_nn</a> ( val )-<a class="code" href="classbdm_1_1eEF.html#cd678fc9b02007a4b8d6692e746f1bf8" title="logarithm of the normalizing constant, ">lognc</a>();it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); <span class="keywordflow">return</span> tmp;} |
---|
89 | <a name="l00051"></a><a class="code" href="classbdm_1_1eEF.html#79a7c8ea8c02e45d410bd1d7ffd72b41">00051</a> <span class="keyword">virtual</span> vec <a class="code" href="classbdm_1_1eEF.html#79a7c8ea8c02e45d410bd1d7ffd72b41" title="Evaluate normalized log-probability for many samples.">evallog</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
---|
90 | <a name="l00052"></a>00052 vec x ( Val.cols() ); |
---|
91 | <a name="l00053"></a>00053 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<Val.cols();i++ ) {x ( i ) =<a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6" title="Evaluate normalized log-probability.">evallog_nn</a> ( Val.get_col ( i ) ) ;} |
---|
92 | <a name="l00054"></a>00054 <span class="keywordflow">return</span> x-<a class="code" href="classbdm_1_1eEF.html#cd678fc9b02007a4b8d6692e746f1bf8" title="logarithm of the normalizing constant, ">lognc</a>(); |
---|
93 | <a name="l00055"></a>00055 } |
---|
94 | <a name="l00057"></a><a class="code" href="classbdm_1_1eEF.html#cf38af29e8e3d650c640509a52396053">00057</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEF.html#cf38af29e8e3d650c640509a52396053" title="Power of the density, used e.g. to flatten the density.">pow</a> ( <span class="keywordtype">double</span> p ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
95 | <a name="l00058"></a>00058 }; |
---|
96 | <a name="l00059"></a>00059 |
---|
97 | <a name="l00066"></a><a class="code" href="classbdm_1_1mEF.html">00066</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
---|
98 | <a name="l00067"></a>00067 |
---|
99 | <a name="l00068"></a>00068 <span class="keyword">public</span>: |
---|
100 | <a name="l00070"></a><a class="code" href="classbdm_1_1mEF.html#dd7caad7026b778af66e34480eec6f9e">00070</a> <a class="code" href="classbdm_1_1mEF.html#dd7caad7026b778af66e34480eec6f9e" title="Default constructor.">mEF</a> ( ) :<a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( ) {}; |
---|
101 | <a name="l00071"></a>00071 }; |
---|
102 | <a name="l00072"></a>00072 |
---|
103 | <a name="l00074"></a><a class="code" href="classbdm_1_1BMEF.html">00074</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> : <span class="keyword">public</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> { |
---|
104 | <a name="l00075"></a>00075 <span class="keyword">protected</span>: |
---|
105 | <a name="l00077"></a><a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64">00077</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>; |
---|
106 | <a name="l00079"></a><a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865">00079</a> <span class="keywordtype">double</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>; |
---|
107 | <a name="l00080"></a>00080 <span class="keyword">public</span>: |
---|
108 | <a name="l00082"></a><a class="code" href="classbdm_1_1BMEF.html#2def512872ed8a4fc3b702371ec0be55">00082</a> <a class="code" href="classbdm_1_1BMEF.html#2def512872ed8a4fc3b702371ec0be55" title="Default constructor (=empty constructor).">BMEF</a> ( <span class="keywordtype">double</span> frg0=1.0 ) :<a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a> ( ), <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> ( frg0 ) {} |
---|
109 | <a name="l00084"></a><a class="code" href="classbdm_1_1BMEF.html#9662379513101405e159e76717104e62">00084</a> <a class="code" href="classbdm_1_1BMEF.html#9662379513101405e159e76717104e62" title="Copy constructor.">BMEF</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> &B ) :<a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a> ( B ), <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> ( B.<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> ( B.<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> ) {} |
---|
110 | <a name="l00086"></a><a class="code" href="classbdm_1_1BMEF.html#d2b528b7a41ca67163152142f5404051">00086</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#d2b528b7a41ca67163152142f5404051" title="get statistics from another model">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* BM0 ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
111 | <a name="l00088"></a><a class="code" href="classbdm_1_1BMEF.html#bf58deb99af2a6cc674f13ff90300de6">00088</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#bf58deb99af2a6cc674f13ff90300de6" title="Weighted update of sufficient statistics (Bayes rule).">bayes</a> ( <span class="keyword">const</span> vec &data, <span class="keyword">const</span> <span class="keywordtype">double</span> w ) {}; |
---|
112 | <a name="l00089"></a>00089 <span class="comment">//original Bayes</span> |
---|
113 | <a name="l00090"></a>00090 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#bf58deb99af2a6cc674f13ff90300de6" title="Weighted update of sufficient statistics (Bayes rule).">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
---|
114 | <a name="l00092"></a><a class="code" href="classbdm_1_1BMEF.html#b2916a2e71a958665054473124d5e749">00092</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#b2916a2e71a958665054473124d5e749" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> * B ) {it_error ( <span class="stringliteral">"Not implemented"</span> );} |
---|
115 | <a name="l00094"></a>00094 <span class="comment">// virtual void flatten ( double nu0 ) {it_error ( "Not implemented" );}</span> |
---|
116 | <a name="l00095"></a>00095 |
---|
117 | <a name="l00096"></a><a class="code" href="classbdm_1_1BMEF.html#62d2e4691bed41a1efa6b9c2e35e5c67">00096</a> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* <a class="code" href="classbdm_1_1BMEF.html#62d2e4691bed41a1efa6b9c2e35e5c67" title="Flatten the posterior as if to keep nu0 data.">_copy_</a> ()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"function _copy_ not implemented for this BM"</span> ); <span class="keywordflow">return</span> NULL;}; |
---|
118 | <a name="l00097"></a>00097 }; |
---|
119 | <a name="l00098"></a>00098 |
---|
120 | <a name="l00099"></a>00099 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
121 | <a name="l00100"></a>00100 <span class="keyword">class </span>mlnorm; |
---|
122 | <a name="l00101"></a>00101 |
---|
123 | <a name="l00107"></a>00107 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
124 | <a name="l00108"></a><a class="code" href="classbdm_1_1enorm.html">00108</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> { |
---|
125 | <a name="l00109"></a>00109 <span class="keyword">protected</span>: |
---|
126 | <a name="l00111"></a><a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7">00111</a> vec <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
---|
127 | <a name="l00113"></a><a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2">00113</a> sq_T <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>; |
---|
128 | <a name="l00114"></a>00114 <span class="keyword">public</span>: |
---|
129 | <a name="l00117"></a>00117 |
---|
130 | <a name="l00118"></a>00118 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> ( ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( ),<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> ( ) {}; |
---|
131 | <a name="l00119"></a>00119 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> ( <span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>,<span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> ) {set_parameters ( mu,R );} |
---|
132 | <a name="l00120"></a>00120 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>,<span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> ); |
---|
133 | <a name="l00122"></a>00122 |
---|
134 | <a name="l00125"></a>00125 |
---|
135 | <a name="l00127"></a>00127 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">dupdate</a> ( mat &v,<span class="keywordtype">double</span> nu=1.0 ); |
---|
136 | <a name="l00128"></a>00128 |
---|
137 | <a name="l00129"></a>00129 vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
138 | <a name="l00130"></a>00130 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a> ( <span class="keywordtype">int</span> N ) <span class="keyword">const</span>; |
---|
139 | <a name="l00131"></a>00131 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
140 | <a name="l00132"></a>00132 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
141 | <a name="l00133"></a><a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600">00133</a> vec <a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
---|
142 | <a name="l00134"></a><a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773">00134</a> vec <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> diag ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.to_mat() );} |
---|
143 | <a name="l00135"></a>00135 <span class="comment">// mlnorm<sq_T>* condition ( const RV &rvn ) const ;</span> |
---|
144 | <a name="l00136"></a>00136 <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#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span> ; |
---|
145 | <a name="l00137"></a>00137 <span class="comment">// enorm<sq_T>* marginal ( const RV &rv ) const;</span> |
---|
146 | <a name="l00138"></a>00138 <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#cd02d76e9d4f96bdd3fa6b604e273039" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ) <span class="keyword">const</span>; |
---|
147 | <a name="l00140"></a>00140 |
---|
148 | <a name="l00143"></a>00143 |
---|
149 | <a name="l00144"></a>00144 vec& _mu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
---|
150 | <a name="l00145"></a>00145 <span class="keywordtype">void</span> set_mu ( <span class="keyword">const</span> vec mu0 ) { <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>=mu0;} |
---|
151 | <a name="l00146"></a>00146 sq_T& _R() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
---|
152 | <a name="l00147"></a>00147 <span class="keyword">const</span> sq_T& _R()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
---|
153 | <a name="l00149"></a>00149 |
---|
154 | <a name="l00150"></a>00150 }; |
---|
155 | <a name="l00151"></a>00151 |
---|
156 | <a name="l00158"></a><a class="code" href="classbdm_1_1egiw.html">00158</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> { |
---|
157 | <a name="l00159"></a>00159 <span class="keyword">protected</span>: |
---|
158 | <a name="l00161"></a><a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52">00161</a> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>; |
---|
159 | <a name="l00163"></a><a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4">00163</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>; |
---|
160 | <a name="l00165"></a><a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a">00165</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
---|
161 | <a name="l00167"></a><a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd">00167</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a>; |
---|
162 | <a name="l00168"></a>00168 <span class="keyword">public</span>: |
---|
163 | <a name="l00171"></a>00171 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a>() :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {}; |
---|
164 | <a name="l00172"></a>00172 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {set_parameters ( dimx0,V0, nu0 );}; |
---|
165 | <a name="l00173"></a>00173 |
---|
166 | <a name="l00174"></a>00174 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) { |
---|
167 | <a name="l00175"></a>00175 <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>=dimx0; |
---|
168 | <a name="l00176"></a>00176 <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> = V0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>()-<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
---|
169 | <a name="l00177"></a>00177 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>* ( <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>+<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> ); <span class="comment">// size(R) + size(Theta)</span> |
---|
170 | <a name="l00178"></a>00178 |
---|
171 | <a name="l00179"></a>00179 <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>=V0; |
---|
172 | <a name="l00180"></a>00180 <span class="keywordflow">if</span> ( nu0<0 ) { |
---|
173 | <a name="l00181"></a>00181 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> = 0.1 +<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> +2*<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> +2; <span class="comment">// +2 assures finite expected value of R</span> |
---|
174 | <a name="l00182"></a>00182 <span class="comment">// terms before that are sufficient for finite normalization</span> |
---|
175 | <a name="l00183"></a>00183 } |
---|
176 | <a name="l00184"></a>00184 <span class="keywordflow">else</span> { |
---|
177 | <a name="l00185"></a>00185 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>=nu0; |
---|
178 | <a name="l00186"></a>00186 } |
---|
179 | <a name="l00187"></a>00187 } |
---|
180 | <a name="l00189"></a>00189 |
---|
181 | <a name="l00190"></a>00190 vec <a class="code" href="classbdm_1_1egiw.html#920f21548b7a3723923dd108fe514c61" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
182 | <a name="l00191"></a>00191 vec <a class="code" href="classbdm_1_1egiw.html#df70c05f918c3a6f86d60f10c1fd6ba2" title="return expected value">mean</a>() <span class="keyword">const</span>; |
---|
183 | <a name="l00192"></a>00192 vec <a class="code" href="classbdm_1_1egiw.html#c1ecc406613cc2341225dc10c3d3b46a" title="return expected variance (not covariance!)">variance</a>() <span class="keyword">const</span>; |
---|
184 | <a name="l00193"></a>00193 <span class="keywordtype">void</span> mean_mat ( mat &M, mat&R ) <span class="keyword">const</span>; |
---|
185 | <a name="l00195"></a>00195 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#bfb8e7c619b34ad804a73bff71742b5e" title="In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise...">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
186 | <a name="l00196"></a>00196 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#41d72ba7b2abc8a9a4209ffa98ed5633" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
187 | <a name="l00197"></a><a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be">00197</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be" title="Power of the density, used e.g. to flatten the density.">pow</a> ( <span class="keywordtype">double</span> p ) {V*=p;<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>*=p;}; |
---|
188 | <a name="l00198"></a>00198 |
---|
189 | <a name="l00201"></a>00201 |
---|
190 | <a name="l00202"></a>00202 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V() {<span class="keywordflow">return</span> V;} |
---|
191 | <a name="l00203"></a>00203 <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V()<span class="keyword"> const </span>{<span class="keywordflow">return</span> V;} |
---|
192 | <a name="l00204"></a>00204 <span class="keywordtype">double</span>& _nu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
---|
193 | <a name="l00205"></a>00205 <span class="keyword">const</span> <span class="keywordtype">double</span>& _nu()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
---|
194 | <a name="l00207"></a>00207 }; |
---|
195 | <a name="l00208"></a>00208 |
---|
196 | <a name="l00217"></a><a class="code" href="classbdm_1_1eDirich.html">00217</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> { |
---|
197 | <a name="l00218"></a>00218 <span class="keyword">protected</span>: |
---|
198 | <a name="l00220"></a><a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2">00220</a> vec <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>; |
---|
199 | <a name="l00222"></a><a class="code" href="classbdm_1_1eDirich.html#ee9db192a6f0ab7b29c33b2a18a5e1b4">00222</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#ee9db192a6f0ab7b29c33b2a18a5e1b4" title="speedup variable">gamma</a>; |
---|
200 | <a name="l00223"></a>00223 <span class="keyword">public</span>: |
---|
201 | <a name="l00226"></a>00226 |
---|
202 | <a name="l00227"></a>00227 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ) {}; |
---|
203 | <a name="l00228"></a>00228 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> &D0 ) : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {set_parameters ( D0.<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> );}; |
---|
204 | <a name="l00229"></a>00229 eDirich ( <span class="keyword">const</span> vec &beta0 ) {set_parameters ( beta0 );}; |
---|
205 | <a name="l00230"></a>00230 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) { |
---|
206 | <a name="l00231"></a>00231 <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>= beta0; |
---|
207 | <a name="l00232"></a>00232 <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(); |
---|
208 | <a name="l00233"></a>00233 <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> ); |
---|
209 | <a name="l00234"></a>00234 } |
---|
210 | <a name="l00236"></a>00236 |
---|
211 | <a name="l00237"></a><a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc">00237</a> vec <a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> vec_1 ( 0.0 );}; |
---|
212 | <a name="l00238"></a><a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6">00238</a> vec <a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>/<a class="code" href="classbdm_1_1eDirich.html#ee9db192a6f0ab7b29c33b2a18a5e1b4" title="speedup variable">gamma</a>;}; |
---|
213 | <a name="l00239"></a><a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc">00239</a> vec <a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_mult ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>, ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>+1 ) ) / ( <a class="code" href="classbdm_1_1eDirich.html#ee9db192a6f0ab7b29c33b2a18a5e1b4" title="speedup variable">gamma</a>* ( <a class="code" href="classbdm_1_1eDirich.html#ee9db192a6f0ab7b29c33b2a18a5e1b4" title="speedup variable">gamma</a>+1 ) );} |
---|
214 | <a name="l00241"></a><a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318">00241</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318" title="In this instance, val is ...">evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
215 | <a name="l00242"></a>00242 <span class="keywordtype">double</span> tmp; tmp= ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>-1 ) *log ( val ); it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
---|
216 | <a name="l00243"></a>00243 <span class="keywordflow">return</span> tmp; |
---|
217 | <a name="l00244"></a>00244 }; |
---|
218 | <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>{ |
---|
219 | <a name="l00246"></a>00246 <span class="keywordtype">double</span> tmp; |
---|
220 | <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> ); |
---|
221 | <a name="l00248"></a>00248 <span class="keywordtype">double</span> lgb=0.0; |
---|
222 | <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 ) );} |
---|
223 | <a name="l00250"></a>00250 tmp= lgb-lgamma ( gam ); |
---|
224 | <a name="l00251"></a>00251 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
---|
225 | <a name="l00252"></a>00252 <span class="keywordflow">return</span> tmp; |
---|
226 | <a name="l00253"></a>00253 }; |
---|
227 | <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>;} |
---|
228 | <a name="l00257"></a>00257 }; |
---|
229 | <a name="l00258"></a>00258 |
---|
230 | <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> { |
---|
231 | <a name="l00261"></a>00261 <span class="keyword">protected</span>: |
---|
232 | <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>; |
---|
233 | <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>; |
---|
234 | <a name="l00266"></a>00266 <span class="keyword">public</span>: |
---|
235 | <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;}} |
---|
236 | <a name="l00270"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00270</a> <a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31" title="Copy constructor.">multiBM</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> &B ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( B ),<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ( B.<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ),<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta() ) {} |
---|
237 | <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>;} |
---|
238 | <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 ) { |
---|
239 | <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>();} |
---|
240 | <a name="l00275"></a>00275 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>+=dt; |
---|
241 | <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>;} |
---|
242 | <a name="l00277"></a>00277 } |
---|
243 | <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>{ |
---|
244 | <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> ); |
---|
245 | <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>(); |
---|
246 | <a name="l00281"></a>00281 |
---|
247 | <a name="l00282"></a>00282 <span class="keywordtype">double</span> lll; |
---|
248 | <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 ) |
---|
249 | <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>();} |
---|
250 | <a name="l00285"></a>00285 <span class="keywordflow">else</span> |
---|
251 | <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>;} |
---|
252 | <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>();} |
---|
253 | <a name="l00288"></a>00288 |
---|
254 | <a name="l00289"></a>00289 beta+=dt; |
---|
255 | <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; |
---|
256 | <a name="l00291"></a>00291 } |
---|
257 | <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 ) { |
---|
258 | <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 ); |
---|
259 | <a name="l00294"></a>00294 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
---|
260 | <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> |
---|
261 | <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> ) ); |
---|
262 | <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>();} |
---|
263 | <a name="l00298"></a>00298 } |
---|
264 | <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>;}; |
---|
265 | <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>;}; |
---|
266 | <a name="l00301"></a>00301 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) { |
---|
267 | <a name="l00302"></a>00302 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters ( beta0 ); |
---|
268 | <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();} |
---|
269 | <a name="l00304"></a>00304 } |
---|
270 | <a name="l00305"></a>00305 }; |
---|
271 | <a name="l00306"></a>00306 |
---|
272 | <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> { |
---|
273 | <a name="l00317"></a>00317 <span class="keyword">protected</span>: |
---|
274 | <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>; |
---|
275 | <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>; |
---|
276 | <a name="l00322"></a>00322 <span class="keyword">public</span> : |
---|
277 | <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>(0), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>(0) {}; |
---|
278 | <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 );}; |
---|
279 | <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();}; |
---|
280 | <a name="l00329"></a>00329 |
---|
281 | <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>; |
---|
282 | <a name="l00332"></a>00332 <span class="comment">// mat sample ( int N ) const;</span> |
---|
283 | <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>; |
---|
284 | <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>; |
---|
285 | <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>;} |
---|
286 | <a name="l00337"></a>00337 vec& _beta() {<span class="keywordflow">return</span> beta;} |
---|
287 | <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 );} |
---|
288 | <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 ) ); } |
---|
289 | <a name="l00340"></a>00340 }; |
---|
290 | <a name="l00341"></a>00341 |
---|
291 | <a name="l00358"></a><a class="code" href="classbdm_1_1eigamma.html">00358</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> { |
---|
292 | <a name="l00359"></a>00359 <span class="keyword">protected</span>: |
---|
293 | <a name="l00360"></a>00360 <span class="keyword">public</span> : |
---|
294 | <a name="l00365"></a>00365 |
---|
295 | <a name="l00366"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00366</a> vec <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1.0/<a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">egamma::sample</a>();}; |
---|
296 | <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_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>,<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-1 );} |
---|
297 | <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_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-2 );} |
---|
298 | <a name="l00370"></a>00370 }; |
---|
299 | <a name="l00371"></a>00371 <span class="comment">/*</span> |
---|
300 | <a name="l00373"></a>00373 <span class="comment">class emix : public epdf {</span> |
---|
301 | <a name="l00374"></a>00374 <span class="comment">protected:</span> |
---|
302 | <a name="l00375"></a>00375 <span class="comment"> int n;</span> |
---|
303 | <a name="l00376"></a>00376 <span class="comment"> vec &w;</span> |
---|
304 | <a name="l00377"></a>00377 <span class="comment"> Array<epdf*> Coms;</span> |
---|
305 | <a name="l00378"></a>00378 <span class="comment">public:</span> |
---|
306 | <a name="l00380"></a>00380 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
---|
307 | <a name="l00381"></a>00381 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
---|
308 | <a name="l00382"></a>00382 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
---|
309 | <a name="l00383"></a>00383 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
---|
310 | <a name="l00384"></a>00384 <span class="comment">};</span> |
---|
311 | <a name="l00385"></a>00385 <span class="comment">*/</span> |
---|
312 | <a name="l00386"></a>00386 |
---|
313 | <a name="l00388"></a>00388 |
---|
314 | <a name="l00389"></a><a class="code" href="classbdm_1_1euni.html">00389</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> { |
---|
315 | <a name="l00390"></a>00390 <span class="keyword">protected</span>: |
---|
316 | <a name="l00392"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00392</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
---|
317 | <a name="l00394"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00394</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
---|
318 | <a name="l00396"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00396</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
---|
319 | <a name="l00398"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00398</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
---|
320 | <a name="l00400"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00400</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
---|
321 | <a name="l00401"></a>00401 <span class="keyword">public</span>: |
---|
322 | <a name="l00404"></a>00404 <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> ( ) {} |
---|
323 | <a name="l00405"></a>00405 <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 );} |
---|
324 | <a name="l00406"></a>00406 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) { |
---|
325 | <a name="l00407"></a>00407 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0-low0; |
---|
326 | <a name="l00408"></a>00408 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> ); |
---|
327 | <a name="l00409"></a>00409 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
---|
328 | <a name="l00410"></a>00410 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
---|
329 | <a name="l00411"></a>00411 <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> ); |
---|
330 | <a name="l00412"></a>00412 <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> ); |
---|
331 | <a name="l00413"></a>00413 <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(); |
---|
332 | <a name="l00414"></a>00414 } |
---|
333 | <a name="l00416"></a>00416 |
---|
334 | <a name="l00417"></a>00417 <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>;} |
---|
335 | <a name="l00418"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00418</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>;} |
---|
336 | <a name="l00419"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00419</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
---|
337 | <a name="l00420"></a>00420 vec smp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
338 | <a name="l00421"></a>00421 <span class="preprocessor">#pragma omp critical</span> |
---|
339 | <a name="l00422"></a>00422 <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 ); |
---|
340 | <a name="l00423"></a>00423 <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 ); |
---|
341 | <a name="l00424"></a>00424 } |
---|
342 | <a name="l00426"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00426</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;} |
---|
343 | <a name="l00427"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00427</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;} |
---|
344 | <a name="l00428"></a>00428 }; |
---|
345 | <a name="l00429"></a>00429 |
---|
346 | <a name="l00430"></a>00430 |
---|
347 | <a name="l00436"></a>00436 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
348 | <a name="l00437"></a><a class="code" href="classbdm_1_1mlnorm.html">00437</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> { |
---|
349 | <a name="l00438"></a>00438 <span class="keyword">protected</span>: |
---|
350 | <a name="l00440"></a><a class="code" href="classbdm_1_1mlnorm.html#150ad6acb223b0a0abeaf92346686dcd">00440</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>; |
---|
351 | <a name="l00441"></a>00441 mat A; |
---|
352 | <a name="l00442"></a>00442 vec mu_const; |
---|
353 | <a name="l00443"></a>00443 vec& _mu; <span class="comment">//cached epdf.mu;</span> |
---|
354 | <a name="l00444"></a>00444 <span class="keyword">public</span>: |
---|
355 | <a name="l00447"></a>00447 <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>; }; |
---|
356 | <a name="l00448"></a>00448 <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() ) { |
---|
357 | <a name="l00449"></a>00449 <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 ); |
---|
358 | <a name="l00450"></a>00450 }; |
---|
359 | <a name="l00452"></a>00452 <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 ); |
---|
360 | <a name="l00455"></a>00455 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">condition</a> ( <span class="keyword">const</span> vec &cond ); |
---|
361 | <a name="l00456"></a>00456 |
---|
362 | <a name="l00458"></a><a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced">00458</a> vec& <a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced" title="access function">_mu_const</a>() {<span class="keywordflow">return</span> mu_const;} |
---|
363 | <a name="l00460"></a><a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614">00460</a> mat& <a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614" title="access function">_A</a>() {<span class="keywordflow">return</span> A;} |
---|
364 | <a name="l00462"></a><a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604">00462</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();} |
---|
365 | <a name="l00463"></a>00463 |
---|
366 | <a name="l00464"></a>00464 <span class="keyword">template</span><<span class="keyword">class</span> sq_M> |
---|
367 | <a name="l00465"></a>00465 <span class="keyword">friend</span> std::ostream &operator<< ( std::ostream &os, mlnorm<sq_M> &ml ); |
---|
368 | <a name="l00466"></a>00466 }; |
---|
369 | <a name="l00467"></a>00467 |
---|
370 | <a name="l00469"></a>00469 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
371 | <a name="l00470"></a><a class="code" href="classbdm_1_1mgnorm.html">00470</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgnorm.html" title="Mpdf with general function for mean value.">mgnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> { |
---|
372 | <a name="l00471"></a>00471 <span class="keyword">protected</span>: |
---|
373 | <a name="l00473"></a><a class="code" href="classbdm_1_1mgnorm.html#8f7a376a1d2197e0634557e88e03104a">00473</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>; |
---|
374 | <a name="l00474"></a>00474 vec &mu; |
---|
375 | <a name="l00475"></a>00475 <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>* g; |
---|
376 | <a name="l00476"></a>00476 <span class="keyword">public</span>: |
---|
377 | <a name="l00478"></a><a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d">00478</a> <a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d" title="default constructor">mgnorm</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>;} |
---|
378 | <a name="l00480"></a><a class="code" href="classbdm_1_1mgnorm.html#578e02458e2a0d17f3864826b6ebd564">00480</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#578e02458e2a0d17f3864826b6ebd564" title="set mean function">set_parameters</a> ( <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>* g0, <span class="keyword">const</span> sq_T &R0 ) {g=g0; <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( g-><a class="code" href="classbdm_1_1fnc.html#083832294da9d1e40804158b979c4341" title="access function">dimension</a>() ), R0 );} |
---|
379 | <a name="l00481"></a><a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d">00481</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &cond ) {mu=g-><a class="code" href="classbdm_1_1fnc.html#6277b11d7fffc7ef8a2fa3e84ae5bad4" title="function evaluates numerical value of at cond ">eval</a> ( cond );}; |
---|
380 | <a name="l00482"></a>00482 }; |
---|
381 | <a name="l00483"></a>00483 |
---|
382 | <a name="l00491"></a><a class="code" href="classbdm_1_1mlstudent.html">00491</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> { |
---|
383 | <a name="l00492"></a>00492 <span class="keyword">protected</span>: |
---|
384 | <a name="l00493"></a>00493 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Lambda; |
---|
385 | <a name="l00494"></a>00494 <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>; |
---|
386 | <a name="l00495"></a>00495 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Re; |
---|
387 | <a name="l00496"></a>00496 <span class="keyword">public</span>: |
---|
388 | <a name="l00497"></a>00497 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> ( ) :<a class="code" href="classbdm_1_1mlnorm.html">mlnorm<ldmat></a> (), |
---|
389 | <a name="l00498"></a>00498 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() ) {} |
---|
390 | <a name="l00499"></a>00499 <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 ) { |
---|
391 | <a name="l00500"></a>00500 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
---|
392 | <a name="l00501"></a>00501 it_assert_debug ( R0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ==A0.rows(),<span class="stringliteral">""</span> ); |
---|
393 | <a name="l00502"></a>00502 |
---|
394 | <a name="l00503"></a>00503 <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> |
---|
395 | <a name="l00504"></a>00504 A = A0; |
---|
396 | <a name="l00505"></a>00505 mu_const = mu0; |
---|
397 | <a name="l00506"></a>00506 Re=R0; |
---|
398 | <a name="l00507"></a>00507 Lambda = Lambda0; |
---|
399 | <a name="l00508"></a>00508 } |
---|
400 | <a name="l00509"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00509</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> ( <span class="keyword">const</span> vec &cond ) { |
---|
401 | <a name="l00510"></a>00510 _mu = A*cond + mu_const; |
---|
402 | <a name="l00511"></a>00511 <span class="keywordtype">double</span> zeta; |
---|
403 | <a name="l00512"></a>00512 <span class="comment">//ugly hack!</span> |
---|
404 | <a name="l00513"></a>00513 <span class="keywordflow">if</span> ( ( cond.length() +1 ) ==Lambda.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ) { |
---|
405 | <a name="l00514"></a>00514 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( concat ( cond, vec_1 ( 1.0 ) ) ); |
---|
406 | <a name="l00515"></a>00515 } |
---|
407 | <a name="l00516"></a>00516 <span class="keywordflow">else</span> { |
---|
408 | <a name="l00517"></a>00517 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( cond ); |
---|
409 | <a name="l00518"></a>00518 } |
---|
410 | <a name="l00519"></a>00519 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> = Re; |
---|
411 | <a name="l00520"></a>00520 <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> |
---|
412 | <a name="l00521"></a>00521 }; |
---|
413 | <a name="l00522"></a>00522 |
---|
414 | <a name="l00523"></a>00523 }; |
---|
415 | <a name="l00533"></a><a class="code" href="classbdm_1_1mgamma.html">00533</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> { |
---|
416 | <a name="l00534"></a>00534 <span class="keyword">protected</span>: |
---|
417 | <a name="l00536"></a><a class="code" href="classbdm_1_1mgamma.html#bdc9f1e9e03c09e91103fee269864438">00536</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>; |
---|
418 | <a name="l00538"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00538</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
---|
419 | <a name="l00540"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00540</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>; |
---|
420 | <a name="l00541"></a>00541 |
---|
421 | <a name="l00542"></a>00542 <span class="keyword">public</span>: |
---|
422 | <a name="l00544"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00544</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>;}; |
---|
423 | <a name="l00546"></a>00546 <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 ); |
---|
424 | <a name="l00547"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00547</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;}; |
---|
425 | <a name="l00548"></a>00548 }; |
---|
426 | <a name="l00549"></a>00549 |
---|
427 | <a name="l00559"></a><a class="code" href="classbdm_1_1migamma.html">00559</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> { |
---|
428 | <a name="l00560"></a>00560 <span class="keyword">protected</span>: |
---|
429 | <a name="l00562"></a><a class="code" href="classbdm_1_1migamma.html#a31b39d4179551b593c9e0d7d756783a">00562</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>; |
---|
430 | <a name="l00564"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00564</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
---|
431 | <a name="l00566"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00566</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>; |
---|
432 | <a name="l00568"></a><a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5">00568</a> vec &<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>; |
---|
433 | <a name="l00569"></a>00569 |
---|
434 | <a name="l00570"></a>00570 <span class="keyword">public</span>: |
---|
435 | <a name="l00573"></a>00573 <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>;}; |
---|
436 | <a name="l00574"></a>00574 <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>;}; |
---|
437 | <a name="l00576"></a>00576 |
---|
438 | <a name="l00578"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00578</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 ) { |
---|
439 | <a name="l00579"></a>00579 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>=k0; |
---|
440 | <a name="l00580"></a>00580 <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> ); |
---|
441 | <a name="l00581"></a>00581 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
---|
442 | <a name="l00582"></a>00582 }; |
---|
443 | <a name="l00583"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00583</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 ) { |
---|
444 | <a name="l00584"></a>00584 <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 ) ); |
---|
445 | <a name="l00585"></a>00585 }; |
---|
446 | <a name="l00586"></a>00586 }; |
---|
447 | <a name="l00587"></a>00587 |
---|
448 | <a name="l00599"></a><a class="code" href="classbdm_1_1mgamma__fix.html">00599</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> { |
---|
449 | <a name="l00600"></a>00600 <span class="keyword">protected</span>: |
---|
450 | <a name="l00602"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa">00602</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>; |
---|
451 | <a name="l00604"></a><a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2">00604</a> vec <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>; |
---|
452 | <a name="l00605"></a>00605 <span class="keyword">public</span>: |
---|
453 | <a name="l00607"></a><a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d">00607</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> () {}; |
---|
454 | <a name="l00609"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2">00609</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 ) { |
---|
455 | <a name="l00610"></a>00610 <a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2" title="Set value of k.">mgamma::set_parameters</a> ( k0, ref0 ); |
---|
456 | <a name="l00611"></a>00611 <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; |
---|
457 | <a name="l00612"></a>00612 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=dimension(); |
---|
458 | <a name="l00613"></a>00613 }; |
---|
459 | <a name="l00614"></a>00614 |
---|
460 | <a name="l00615"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">00615</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;}; |
---|
461 | <a name="l00616"></a>00616 }; |
---|
462 | <a name="l00617"></a>00617 |
---|
463 | <a name="l00618"></a>00618 |
---|
464 | <a name="l00631"></a><a class="code" href="classbdm_1_1migamma__ref.html">00631</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma__ref.html" title="Inverse-Gamma random walk around a fixed point.">migamma_ref</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> { |
---|
465 | <a name="l00632"></a>00632 <span class="keyword">protected</span>: |
---|
466 | <a name="l00634"></a><a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d">00634</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>; |
---|
467 | <a name="l00636"></a><a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6">00636</a> vec <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>; |
---|
468 | <a name="l00637"></a>00637 <span class="keyword">public</span>: |
---|
469 | <a name="l00639"></a><a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f">00639</a> <a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f" title="Constructor.">migamma_ref</a> ( ) : <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> (),<a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a> ( ) {}; |
---|
470 | <a name="l00641"></a><a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800">00641</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0 ) { |
---|
471 | <a name="l00642"></a>00642 <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">migamma::set_parameters</a> ( ref0.length(), k0 ); |
---|
472 | <a name="l00643"></a>00643 <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>=pow ( ref0,1.0-l0 ); |
---|
473 | <a name="l00644"></a>00644 <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>=l0; |
---|
474 | <a name="l00645"></a>00645 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
---|
475 | <a name="l00646"></a>00646 }; |
---|
476 | <a name="l00647"></a>00647 |
---|
477 | <a name="l00648"></a><a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">00648</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) { |
---|
478 | <a name="l00649"></a>00649 vec mean=elem_mult ( <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>,pow ( val,<a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a> ) ); |
---|
479 | <a name="l00650"></a>00650 <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">migamma::condition</a> ( mean ); |
---|
480 | <a name="l00651"></a>00651 }; |
---|
481 | <a name="l00652"></a>00652 }; |
---|
482 | <a name="l00653"></a>00653 |
---|
483 | <a name="l00663"></a><a class="code" href="classbdm_1_1elognorm.html">00663</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1elognorm.html">elognorm</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><ldmat>{ |
---|
484 | <a name="l00664"></a>00664 <span class="keyword">public</span>: |
---|
485 | <a name="l00665"></a><a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba">00665</a> vec <a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> exp(<a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<ldmat>::sample</a>());}; |
---|
486 | <a name="l00666"></a><a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea">00666</a> vec <a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec var=<a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">enorm<ldmat>::variance</a>();<span class="keywordflow">return</span> exp(<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> - 0.5*var);}; |
---|
487 | <a name="l00667"></a>00667 |
---|
488 | <a name="l00668"></a>00668 }; |
---|
489 | <a name="l00669"></a>00669 |
---|
490 | <a name="l00681"></a><a class="code" href="classbdm_1_1mlognorm.html">00681</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlognorm.html" title="Log-Normal random walk.">mlognorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
---|
491 | <a name="l00682"></a>00682 <span class="keyword">protected</span>: |
---|
492 | <a name="l00683"></a>00683 <a class="code" href="classbdm_1_1elognorm.html">elognorm</a> eno; |
---|
493 | <a name="l00685"></a><a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a">00685</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
---|
494 | <a name="l00687"></a><a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2">00687</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
---|
495 | <a name="l00688"></a>00688 <span class="keyword">public</span>: |
---|
496 | <a name="l00690"></a><a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41">00690</a> <a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a> ( ) : eno (), <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>(eno._mu()) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&eno;}; |
---|
497 | <a name="l00692"></a><a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f">00692</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">int</span> size, <span class="keywordtype">double</span> k) { |
---|
498 | <a name="l00693"></a>00693 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5*log(k*k+1); |
---|
499 | <a name="l00694"></a>00694 eno.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a>(zeros(size),2*<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye(size)); |
---|
500 | <a name="l00695"></a>00695 |
---|
501 | <a name="l00696"></a>00696 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
---|
502 | <a name="l00697"></a>00697 }; |
---|
503 | <a name="l00698"></a>00698 |
---|
504 | <a name="l00699"></a><a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">00699</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) { |
---|
505 | <a name="l00700"></a>00700 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>=log(val)-<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>;<span class="comment">//elem_mult ( refl,pow ( val,l ) );</span> |
---|
506 | <a name="l00701"></a>00701 }; |
---|
507 | <a name="l00702"></a>00702 }; |
---|
508 | <a name="l00703"></a>00703 |
---|
509 | <a name="l00707"></a><a class="code" href="classbdm_1_1iW.html">00707</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1iW.html">iW</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>{ |
---|
510 | <a name="l00708"></a>00708 <span class="keyword">public</span>: |
---|
511 | <a name="l00709"></a>00709 vec sample(){<span class="keywordflow">return</span> vec();} |
---|
512 | <a name="l00710"></a>00710 }; |
---|
513 | <a name="l00711"></a>00711 |
---|
514 | <a name="l00713"></a>00713 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
---|
515 | <a name="l00719"></a><a class="code" href="classbdm_1_1eEmp.html">00719</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> { |
---|
516 | <a name="l00720"></a>00720 <span class="keyword">protected</span> : |
---|
517 | <a name="l00722"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">00722</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
---|
518 | <a name="l00724"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">00724</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
---|
519 | <a name="l00726"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">00726</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
---|
520 | <a name="l00727"></a>00727 <span class="keyword">public</span>: |
---|
521 | <a name="l00730"></a>00730 <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> ( ) {}; |
---|
522 | <a name="l00731"></a>00731 <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> ) {}; |
---|
523 | <a name="l00733"></a>00733 |
---|
524 | <a name="l00735"></a>00735 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#7cfd383180b486fe4526bdf0179350c0" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> vec &w0, <span class="keyword">const</span> epdf* pdf0 ); |
---|
525 | <a name="l00737"></a><a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7">00737</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 , <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> ) {<a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( ones ( n ) /n,pdf0 );}; |
---|
526 | <a name="l00739"></a>00739 <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 ); |
---|
527 | <a name="l00741"></a><a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1">00741</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> ( <span class="keywordtype">int</span> n0, <span class="keywordtype">bool</span> copy=<span class="keyword">true</span> ) {<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>=n0; <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>.set_size ( n0,copy );<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>.set_size ( n0,copy );}; |
---|
528 | <a name="l00743"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">00743</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>;}; |
---|
529 | <a name="l00745"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">00745</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714" title="Potentially dangerous, use with care.">_w</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
---|
530 | <a name="l00747"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">00747</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>;}; |
---|
531 | <a name="l00749"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">00749</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2" title="access function">_samples</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
---|
532 | <a name="l00751"></a>00751 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 ); |
---|
533 | <a name="l00753"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">00753</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;} |
---|
534 | <a name="l00755"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">00755</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;} |
---|
535 | <a name="l00756"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">00756</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
---|
536 | <a name="l00757"></a>00757 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
537 | <a name="l00758"></a>00758 <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 );} |
---|
538 | <a name="l00759"></a>00759 <span class="keywordflow">return</span> pom; |
---|
539 | <a name="l00760"></a>00760 } |
---|
540 | <a name="l00761"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">00761</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
---|
541 | <a name="l00762"></a>00762 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
542 | <a name="l00763"></a>00763 <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 );} |
---|
543 | <a name="l00764"></a>00764 <span class="keywordflow">return</span> pom-pow ( <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(),2 ); |
---|
544 | <a name="l00765"></a>00765 } |
---|
545 | <a name="l00767"></a><a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f">00767</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f" title="For this class, qbounds are minimum and maximum value of the population!">qbounds</a> ( vec &lb, vec &ub, <span class="keywordtype">double</span> perc=0.95 )<span class="keyword"> const </span>{ |
---|
546 | <a name="l00768"></a>00768 <span class="comment">// lb in inf so than it will be pushed below;</span> |
---|
547 | <a name="l00769"></a>00769 lb.set_size(<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
---|
548 | <a name="l00770"></a>00770 ub.set_size(<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
---|
549 | <a name="l00771"></a>00771 lb = std::numeric_limits<double>::infinity(); |
---|
550 | <a name="l00772"></a>00772 ub = -std::numeric_limits<double>::infinity(); |
---|
551 | <a name="l00773"></a>00773 <span class="keywordtype">int</span> j; |
---|
552 | <a name="l00774"></a>00774 <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++ ) { |
---|
553 | <a name="l00775"></a>00775 <span class="keywordflow">for</span> ( j=0;j<<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>; j++ ) { |
---|
554 | <a name="l00776"></a>00776 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) <lb ( j ) ) {lb ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
---|
555 | <a name="l00777"></a>00777 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) >ub ( j ) ) {ub ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
---|
556 | <a name="l00778"></a>00778 } |
---|
557 | <a name="l00779"></a>00779 } |
---|
558 | <a name="l00780"></a>00780 } |
---|
559 | <a name="l00781"></a>00781 }; |
---|
560 | <a name="l00782"></a>00782 |
---|
561 | <a name="l00783"></a>00783 |
---|
562 | <a name="l00785"></a>00785 |
---|
563 | <a name="l00786"></a>00786 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
564 | <a name="l00787"></a>00787 <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 ) { |
---|
565 | <a name="l00788"></a>00788 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
---|
566 | <a name="l00789"></a>00789 mu = mu0; |
---|
567 | <a name="l00790"></a>00790 R = R0; |
---|
568 | <a name="l00791"></a>00791 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = mu0.length(); |
---|
569 | <a name="l00792"></a>00792 }; |
---|
570 | <a name="l00793"></a>00793 |
---|
571 | <a name="l00794"></a>00794 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
572 | <a name="l00795"></a><a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2">00795</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">enorm<sq_T>::dupdate</a> ( mat &v, <span class="keywordtype">double</span> nu ) { |
---|
573 | <a name="l00796"></a>00796 <span class="comment">//</span> |
---|
574 | <a name="l00797"></a>00797 }; |
---|
575 | <a name="l00798"></a>00798 |
---|
576 | <a name="l00799"></a>00799 <span class="comment">// template<class sq_T></span> |
---|
577 | <a name="l00800"></a>00800 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
---|
578 | <a name="l00801"></a>00801 <span class="comment">// //</span> |
---|
579 | <a name="l00802"></a>00802 <span class="comment">// };</span> |
---|
580 | <a name="l00803"></a>00803 |
---|
581 | <a name="l00804"></a>00804 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
582 | <a name="l00805"></a><a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766">00805</a> vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a>()<span class="keyword"> const </span>{ |
---|
583 | <a name="l00806"></a>00806 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
584 | <a name="l00807"></a>00807 <span class="preprocessor">#pragma omp critical</span> |
---|
585 | <a name="l00808"></a>00808 <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 ); |
---|
586 | <a name="l00809"></a>00809 vec smp = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
---|
587 | <a name="l00810"></a>00810 |
---|
588 | <a name="l00811"></a>00811 smp += <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
---|
589 | <a name="l00812"></a>00812 <span class="keywordflow">return</span> smp; |
---|
590 | <a name="l00813"></a>00813 }; |
---|
591 | <a name="l00814"></a>00814 |
---|
592 | <a name="l00815"></a>00815 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
593 | <a name="l00816"></a>00816 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a> ( <span class="keywordtype">int</span> N )<span class="keyword"> const </span>{ |
---|
594 | <a name="l00817"></a>00817 mat X ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,N ); |
---|
595 | <a name="l00818"></a>00818 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
596 | <a name="l00819"></a>00819 vec pom; |
---|
597 | <a name="l00820"></a>00820 <span class="keywordtype">int</span> i; |
---|
598 | <a name="l00821"></a>00821 |
---|
599 | <a name="l00822"></a>00822 <span class="keywordflow">for</span> ( i=0;i<N;i++ ) { |
---|
600 | <a name="l00823"></a>00823 <span class="preprocessor">#pragma omp critical</span> |
---|
601 | <a name="l00824"></a>00824 <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 ); |
---|
602 | <a name="l00825"></a>00825 pom = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
---|
603 | <a name="l00826"></a>00826 pom +=<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
---|
604 | <a name="l00827"></a>00827 X.set_col ( i, pom ); |
---|
605 | <a name="l00828"></a>00828 } |
---|
606 | <a name="l00829"></a>00829 |
---|
607 | <a name="l00830"></a>00830 <span class="keywordflow">return</span> X; |
---|
608 | <a name="l00831"></a>00831 }; |
---|
609 | <a name="l00832"></a>00832 |
---|
610 | <a name="l00833"></a>00833 <span class="comment">// template<class sq_T></span> |
---|
611 | <a name="l00834"></a>00834 <span class="comment">// double enorm<sq_T>::eval ( const vec &val ) const {</span> |
---|
612 | <a name="l00835"></a>00835 <span class="comment">// double pdfl,e;</span> |
---|
613 | <a name="l00836"></a>00836 <span class="comment">// pdfl = evallog ( val );</span> |
---|
614 | <a name="l00837"></a>00837 <span class="comment">// e = exp ( pdfl );</span> |
---|
615 | <a name="l00838"></a>00838 <span class="comment">// return e;</span> |
---|
616 | <a name="l00839"></a>00839 <span class="comment">// };</span> |
---|
617 | <a name="l00840"></a>00840 |
---|
618 | <a name="l00841"></a>00841 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
619 | <a name="l00842"></a><a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3">00842</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">enorm<sq_T>::evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
620 | <a name="l00843"></a>00843 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
---|
621 | <a name="l00844"></a>00844 <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> |
---|
622 | <a name="l00845"></a>00845 <span class="keywordflow">return</span> tmp; |
---|
623 | <a name="l00846"></a>00846 }; |
---|
624 | <a name="l00847"></a>00847 |
---|
625 | <a name="l00848"></a>00848 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
626 | <a name="l00849"></a><a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32">00849</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">enorm<sq_T>::lognc</a> ()<span class="keyword"> const </span>{ |
---|
627 | <a name="l00850"></a>00850 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
---|
628 | <a name="l00851"></a>00851 <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() ); |
---|
629 | <a name="l00852"></a>00852 <span class="keywordflow">return</span> tmp; |
---|
630 | <a name="l00853"></a>00853 }; |
---|
631 | <a name="l00854"></a>00854 |
---|
632 | <a name="l00855"></a>00855 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
633 | <a name="l00856"></a><a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f">00856</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">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 ) { |
---|
634 | <a name="l00857"></a>00857 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
---|
635 | <a name="l00858"></a>00858 it_assert_debug ( A0.rows() ==R0.rows(),<span class="stringliteral">""</span> ); |
---|
636 | <a name="l00859"></a>00859 |
---|
637 | <a name="l00860"></a>00860 <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 ); |
---|
638 | <a name="l00861"></a>00861 A = A0; |
---|
639 | <a name="l00862"></a>00862 mu_const = mu0; |
---|
640 | <a name="l00863"></a>00863 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=A0.cols(); |
---|
641 | <a name="l00864"></a>00864 } |
---|
642 | <a name="l00865"></a>00865 |
---|
643 | <a name="l00866"></a>00866 <span class="comment">// template<class sq_T></span> |
---|
644 | <a name="l00867"></a>00867 <span class="comment">// vec mlnorm<sq_T>::samplecond (const vec &cond, double &lik ) {</span> |
---|
645 | <a name="l00868"></a>00868 <span class="comment">// this->condition ( cond );</span> |
---|
646 | <a name="l00869"></a>00869 <span class="comment">// vec smp = epdf.sample();</span> |
---|
647 | <a name="l00870"></a>00870 <span class="comment">// lik = epdf.eval ( smp );</span> |
---|
648 | <a name="l00871"></a>00871 <span class="comment">// return smp;</span> |
---|
649 | <a name="l00872"></a>00872 <span class="comment">// }</span> |
---|
650 | <a name="l00873"></a>00873 |
---|
651 | <a name="l00874"></a>00874 <span class="comment">// template<class sq_T></span> |
---|
652 | <a name="l00875"></a>00875 <span class="comment">// mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) {</span> |
---|
653 | <a name="l00876"></a>00876 <span class="comment">// int i;</span> |
---|
654 | <a name="l00877"></a>00877 <span class="comment">// int dim = rv.count();</span> |
---|
655 | <a name="l00878"></a>00878 <span class="comment">// mat Smp ( dim,n );</span> |
---|
656 | <a name="l00879"></a>00879 <span class="comment">// vec smp ( dim );</span> |
---|
657 | <a name="l00880"></a>00880 <span class="comment">// this->condition ( cond );</span> |
---|
658 | <a name="l00881"></a>00881 <span class="comment">//</span> |
---|
659 | <a name="l00882"></a>00882 <span class="comment">// for ( i=0; i<n; i++ ) {</span> |
---|
660 | <a name="l00883"></a>00883 <span class="comment">// smp = epdf.sample();</span> |
---|
661 | <a name="l00884"></a>00884 <span class="comment">// lik ( i ) = epdf.eval ( smp );</span> |
---|
662 | <a name="l00885"></a>00885 <span class="comment">// Smp.set_col ( i ,smp );</span> |
---|
663 | <a name="l00886"></a>00886 <span class="comment">// }</span> |
---|
664 | <a name="l00887"></a>00887 <span class="comment">//</span> |
---|
665 | <a name="l00888"></a>00888 <span class="comment">// return Smp;</span> |
---|
666 | <a name="l00889"></a>00889 <span class="comment">// }</span> |
---|
667 | <a name="l00890"></a>00890 |
---|
668 | <a name="l00891"></a>00891 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
669 | <a name="l00892"></a><a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">00892</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">mlnorm<sq_T>::condition</a> ( <span class="keyword">const</span> vec &cond ) { |
---|
670 | <a name="l00893"></a>00893 _mu = A*cond + mu_const; |
---|
671 | <a name="l00894"></a>00894 <span class="comment">//R is already assigned;</span> |
---|
672 | <a name="l00895"></a>00895 } |
---|
673 | <a name="l00896"></a>00896 |
---|
674 | <a name="l00897"></a>00897 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
675 | <a name="l00898"></a><a class="code" href="classbdm_1_1enorm.html#cd02d76e9d4f96bdd3fa6b604e273039">00898</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#cd02d76e9d4f96bdd3fa6b604e273039" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">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>{ |
---|
676 | <a name="l00899"></a>00899 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> ); |
---|
677 | <a name="l00900"></a>00900 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> ); |
---|
678 | <a name="l00901"></a>00901 |
---|
679 | <a name="l00902"></a>00902 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> |
---|
680 | <a name="l00903"></a>00903 |
---|
681 | <a name="l00904"></a>00904 <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>; |
---|
682 | <a name="l00905"></a>00905 tmp-><a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
---|
683 | <a name="l00906"></a>00906 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 ); |
---|
684 | <a name="l00907"></a>00907 <span class="keywordflow">return</span> tmp; |
---|
685 | <a name="l00908"></a>00908 } |
---|
686 | <a name="l00909"></a>00909 |
---|
687 | <a name="l00910"></a>00910 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
688 | <a name="l00911"></a><a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26">00911</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#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">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>{ |
---|
689 | <a name="l00912"></a>00912 |
---|
690 | <a name="l00913"></a>00913 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> ); |
---|
691 | <a name="l00914"></a>00914 |
---|
692 | <a name="l00915"></a>00915 <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 ); |
---|
693 | <a name="l00916"></a>00916 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> ); |
---|
694 | <a name="l00917"></a>00917 <span class="comment">//Permutation vector of the new R</span> |
---|
695 | <a name="l00918"></a>00918 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> ); |
---|
696 | <a name="l00919"></a>00919 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> ); |
---|
697 | <a name="l00920"></a>00920 ivec perm=concat ( irvn , irvc ); |
---|
698 | <a name="l00921"></a>00921 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,perm ); |
---|
699 | <a name="l00922"></a>00922 |
---|
700 | <a name="l00923"></a>00923 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
---|
701 | <a name="l00924"></a>00924 mat S=Rn.to_mat(); |
---|
702 | <a name="l00925"></a>00925 <span class="comment">//fixme</span> |
---|
703 | <a name="l00926"></a>00926 <span class="keywordtype">int</span> n=rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>()-1; |
---|
704 | <a name="l00927"></a>00927 <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; |
---|
705 | <a name="l00928"></a>00928 mat S11 = S.get ( 0,n, 0, n ); |
---|
706 | <a name="l00929"></a>00929 mat S12 = S.get ( 0, n , rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
---|
707 | <a name="l00930"></a>00930 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 ); |
---|
708 | <a name="l00931"></a>00931 |
---|
709 | <a name="l00932"></a>00932 vec mu1 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ); |
---|
710 | <a name="l00933"></a>00933 vec mu2 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvc ); |
---|
711 | <a name="l00934"></a>00934 mat A=S12*inv ( S22 ); |
---|
712 | <a name="l00935"></a>00935 sq_T R_n ( S11 - A *S12.T() ); |
---|
713 | <a name="l00936"></a>00936 |
---|
714 | <a name="l00937"></a>00937 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a>* tmp=<span class="keyword">new</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a> ( ); |
---|
715 | <a name="l00938"></a>00938 tmp->set_rv ( rvn ); tmp->set_rvc ( rvc ); |
---|
716 | <a name="l00939"></a>00939 tmp->set_parameters ( A,mu1-A*mu2,R_n ); |
---|
717 | <a name="l00940"></a>00940 <span class="keywordflow">return</span> tmp; |
---|
718 | <a name="l00941"></a>00941 } |
---|
719 | <a name="l00942"></a>00942 |
---|
720 | <a name="l00944"></a>00944 |
---|
721 | <a name="l00945"></a>00945 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
722 | <a name="l00946"></a>00946 std::ostream &operator<< ( std::ostream &os, mlnorm<sq_T> &ml ) { |
---|
723 | <a name="l00947"></a>00947 os << <span class="stringliteral">"A:"</span><< ml.A<<endl; |
---|
724 | <a name="l00948"></a>00948 os << <span class="stringliteral">"mu:"</span><< ml.mu_const<<endl; |
---|
725 | <a name="l00949"></a>00949 os << <span class="stringliteral">"R:"</span> << ml.epdf._R().to_mat() <<endl; |
---|
726 | <a name="l00950"></a>00950 <span class="keywordflow">return</span> os; |
---|
727 | <a name="l00951"></a>00951 }; |
---|
728 | <a name="l00952"></a>00952 |
---|
729 | <a name="l00953"></a>00953 } |
---|
730 | <a name="l00954"></a>00954 <span class="preprocessor">#endif //EF_H</span> |
---|
731 | </pre></div></div> |
---|
732 | <hr size="1"><address style="text-align: right;"><small>Generated on Fri Mar 6 15:01:36 2009 for mixpp by |
---|
733 | <a href="http://www.doxygen.org/index.html"> |
---|
734 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
735 | </body> |
---|
736 | </html> |
---|