Show
Ignore:
Timestamp:
03/03/08 13:00:32 (17 years ago)
Author:
smidl
Message:

test KF : estimation of R in KF is not possible! Likelihood of y_t is growing when R -> 0

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • doc/html/libEF_8h-source.html

    r28 r32  
    2121<a name="l00017"></a>00017 <span class="preprocessor">#include "../math/libDC.h"</span> 
    2222<a name="l00018"></a>00018 <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> 
    23 <a name="l00019"></a>00019 <span class="comment">//#include &lt;std&gt;</span> 
    24 <a name="l00020"></a>00020  
    25 <a name="l00021"></a>00021 <span class="keyword">using namespace </span>itpp; 
    26 <a name="l00022"></a>00022  
    27 <a name="l00028"></a><a class="code" href="classeEF.html">00028</a> <span class="keyword">class </span><a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> : <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { 
     23<a name="l00019"></a>00019 <span class="preprocessor">#include "../itpp_ext.h"</span> 
     24<a name="l00020"></a>00020 <span class="comment">//#include &lt;std&gt;</span> 
     25<a name="l00021"></a>00021  
     26<a name="l00022"></a>00022 <span class="keyword">using namespace </span>itpp; 
     27<a name="l00023"></a>00023  
     28<a name="l00024"></a>00024  
     29<a name="l00026"></a>00026 <span class="keyword">extern</span> Uniform_RNG UniRNG; 
     30<a name="l00027"></a>00027 <span class="keyword">extern</span> Normal_RNG NorRNG; 
     31<a name="l00028"></a>00028 <span class="keyword">extern</span> <a class="code" href="classitpp_1_1Gamma__RNG.html" title="Gamma distribution.">Gamma_RNG</a> GamRNG; 
    2832<a name="l00029"></a>00029  
    29 <a name="l00030"></a>00030 <span class="keyword">public</span>: 
    30 <a name="l00031"></a>00031         <span class="keyword">virtual</span> <span class="keywordtype">void</span> tupdate( <span class="keywordtype">double</span> phi, mat &amp;vbar, <span class="keywordtype">double</span> nubar ) {}; 
    31 <a name="l00032"></a>00032         <span class="keyword">virtual</span> <span class="keywordtype">void</span> dupdate( mat &amp;v,<span class="keywordtype">double</span> nu=1.0 ) {}; 
    32 <a name="l00033"></a>00033 }; 
    33 <a name="l00034"></a>00034  
    34 <a name="l00035"></a>00035 <span class="keyword">class </span>mEF : <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { 
    35 <a name="l00036"></a>00036  
    36 <a name="l00037"></a>00037 <span class="keyword">public</span>: 
     33<a name="l00030"></a>00030  
     34<a name="l00037"></a><a class="code" href="classeEF.html">00037</a> <span class="keyword">class </span><a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> : <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { 
    3735<a name="l00038"></a>00038  
    38 <a name="l00039"></a>00039 }; 
    39 <a name="l00040"></a>00040  
    40 <a name="l00046"></a>00046 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    41 <a name="l00047"></a><a class="code" href="classenorm.html">00047</a> <span class="keyword">class </span><a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> : <span class="keyword">public</span> <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> { 
    42 <a name="l00048"></a>00048         <span class="keywordtype">int</span> dim; 
    43 <a name="l00049"></a>00049         vec mu; 
    44 <a name="l00050"></a>00050         sq_T R; 
    45 <a name="l00051"></a>00051 <span class="keyword">public</span>: 
    46 <a name="l00052"></a>00052         <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a>( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv, vec &amp;mu, sq_T &amp;R ); 
    47 <a name="l00053"></a>00053         <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a>(); 
    48 <a name="l00055"></a>00055         <span class="keywordtype">void</span> <a class="code" href="classenorm.html#2a1a522504c7788dfd7fb733157ee39e" title="tupdate used in KF">tupdate</a>( <span class="keywordtype">double</span> phi, mat &amp;vbar, <span class="keywordtype">double</span> nubar ); 
    49 <a name="l00056"></a>00056         <span class="keywordtype">void</span> <a class="code" href="classenorm.html#d1b0faf61260de09cf63bf823add5b32" title="dupdate used in KF">dupdate</a>( mat &amp;v,<span class="keywordtype">double</span> nu=1.0 ); 
    50 <a name="l00058"></a>00058         <span class="keywordtype">void</span> <a class="code" href="classenorm.html#2a1a522504c7788dfd7fb733157ee39e" title="tupdate used in KF">tupdate</a>(); 
    51 <a name="l00060"></a>00060         <span class="keywordtype">double</span> <a class="code" href="classenorm.html#d1b0faf61260de09cf63bf823add5b32" title="dupdate used in KF">dupdate</a>(); 
    52 <a name="l00061"></a>00061           
    53 <a name="l00062"></a>00062         vec <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">sample</a>(); 
    54 <a name="l00063"></a>00063         mat <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">sample</a>(<span class="keywordtype">int</span> N); 
    55 <a name="l00064"></a>00064         <span class="keywordtype">double</span> <a class="code" href="classenorm.html#93107f05a8e9b34b64853767200121a4" title="Compute probability of argument val.">eval</a>( <span class="keyword">const</span> vec &amp;val ); 
    56 <a name="l00065"></a>00065         Normal_RNG RNG; 
    57 <a name="l00066"></a>00066 }; 
    58 <a name="l00067"></a>00067  
    59 <a name="l00071"></a>00071 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    60 <a name="l00072"></a>00072 <span class="keyword">class </span>mlnorm : <span class="keyword">public</span> mEF { 
    61 <a name="l00073"></a>00073         <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; 
    62 <a name="l00074"></a>00074         mat A; 
     36<a name="l00039"></a>00039 <span class="keyword">public</span>: 
     37<a name="l00041"></a><a class="code" href="classeEF.html#702e24158366430bc24d57c7f64e1e9e">00041</a>         <a class="code" href="classeEF.html#702e24158366430bc24d57c7f64e1e9e" title="default constructor">eEF</a>() :<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>() {}; 
     38<a name="l00042"></a>00042  
     39<a name="l00043"></a>00043         <a class="code" href="classeEF.html#702e24158366430bc24d57c7f64e1e9e" title="default constructor">eEF</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv ) :<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {}; 
     40<a name="l00044"></a>00044  
     41<a name="l00045"></a>00045         <span class="keyword">virtual</span> <span class="keywordtype">void</span> tupdate ( <span class="keywordtype">double</span> phi, mat &amp;vbar, <span class="keywordtype">double</span> nubar ) {}; 
     42<a name="l00046"></a>00046  
     43<a name="l00047"></a>00047         <span class="keyword">virtual</span> <span class="keywordtype">void</span> dupdate ( mat &amp;v,<span class="keywordtype">double</span> nu=1.0 ) {}; 
     44<a name="l00048"></a>00048 }; 
     45<a name="l00049"></a>00049  
     46<a name="l00050"></a>00050 <span class="keyword">class </span>mEF : <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { 
     47<a name="l00051"></a>00051  
     48<a name="l00052"></a>00052 <span class="keyword">public</span>: 
     49<a name="l00053"></a>00053         mEF ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rvc0 ) :<a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv0,rvc0 ) {}; 
     50<a name="l00054"></a>00054 }; 
     51<a name="l00055"></a>00055  
     52<a name="l00061"></a>00061 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     53<a name="l00062"></a>00062  
     54<a name="l00063"></a><a class="code" href="classenorm.html">00063</a> <span class="keyword">class </span><a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> : <span class="keyword">public</span> <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> { 
     55<a name="l00064"></a>00064 <span class="keyword">protected</span>: 
     56<a name="l00066"></a><a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20">00066</a>         vec <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>; 
     57<a name="l00068"></a><a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1">00068</a>         sq_T <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>; 
     58<a name="l00070"></a><a class="code" href="classenorm.html#82f39ac49911d7097f4bfe385deba355">00070</a>         sq_T <a class="code" href="classenorm.html#82f39ac49911d7097f4bfe385deba355" title="Cache: _iR = inv(R);.">_iR</a>; 
     59<a name="l00072"></a><a class="code" href="classenorm.html#ae12db77283a96e0f14a3eae93dc3bf1">00072</a>         <span class="keywordtype">bool</span> <a class="code" href="classenorm.html#ae12db77283a96e0f14a3eae93dc3bf1" title="indicator if _iR is chached">cached</a>; 
     60<a name="l00074"></a><a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e">00074</a>         <span class="keywordtype">int</span> <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>; 
    6361<a name="l00075"></a>00075 <span class="keyword">public</span>: 
    64 <a name="l00077"></a>00077         mlnorm( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv,<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rvc, mat &amp;A, sq_T &amp;R ); 
    65 <a name="l00079"></a>00079         vec samplecond( vec &amp;cond, <span class="keywordtype">double</span> &amp;lik ); 
    66 <a name="l00080"></a>00080         mat samplecond( vec &amp;cond, vec &amp;lik, <span class="keywordtype">int</span> n ); 
    67 <a name="l00081"></a>00081         <span class="keywordtype">void</span> condition( vec &amp;cond ); 
    68 <a name="l00082"></a>00082 }; 
     62<a name="l00076"></a>00076         <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a>() :<a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {}; 
     63<a name="l00077"></a>00077  
     64<a name="l00078"></a>00078         <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv ); 
     65<a name="l00079"></a>00079         <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &amp;<a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>,<span class="keyword">const</span> sq_T &amp;<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a> ); 
     66<a name="l00081"></a>00081         <span class="keywordtype">void</span> <a class="code" href="classenorm.html#5b5fd142b6b17ea334597960e3fe126a" title="tupdate in exponential form (not really handy)">tupdate</a> ( <span class="keywordtype">double</span> phi, mat &amp;vbar, <span class="keywordtype">double</span> nubar ); 
     67<a name="l00082"></a>00082         <span class="keywordtype">void</span> dupdate ( mat &amp;v,<span class="keywordtype">double</span> nu=1.0 ); 
    6968<a name="l00083"></a>00083  
    70 <a name="l00085"></a>00085  
    71 <a name="l00086"></a>00086 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    72 <a name="l00087"></a>00087 <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;::enorm</a>( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv, vec &amp;mu0, sq_T &amp;R0 ) { 
    73 <a name="l00088"></a>00088         dim = rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>(); 
    74 <a name="l00089"></a>00089         mu = mu0; 
    75 <a name="l00090"></a>00090         R = R0; 
    76 <a name="l00091"></a>00091 }; 
    77 <a name="l00092"></a>00092  
    78 <a name="l00093"></a>00093 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    79 <a name="l00094"></a>00094 <span class="keywordtype">void</span> <a class="code" href="classenorm.html#d1b0faf61260de09cf63bf823add5b32" title="dupdate used in KF">enorm&lt;sq_T&gt;::dupdate</a>( mat &amp;v, <span class="keywordtype">double</span> nu ) { 
    80 <a name="l00095"></a>00095         <span class="comment">//</span> 
    81 <a name="l00096"></a>00096 }; 
    82 <a name="l00097"></a>00097  
    83 <a name="l00098"></a>00098 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    84 <a name="l00099"></a><a class="code" href="classenorm.html#5b5fd142b6b17ea334597960e3fe126a">00099</a> <span class="keywordtype">void</span> <a class="code" href="classenorm.html#2a1a522504c7788dfd7fb733157ee39e" title="tupdate used in KF">enorm&lt;sq_T&gt;::tupdate</a>( <span class="keywordtype">double</span> phi, mat &amp;vbar, <span class="keywordtype">double</span> nubar ) { 
    85 <a name="l00100"></a>00100         <span class="comment">//</span> 
    86 <a name="l00101"></a>00101 }; 
    87 <a name="l00102"></a>00102  
    88 <a name="l00103"></a>00103 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    89 <a name="l00104"></a><a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023">00104</a> vec <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">enorm&lt;sq_T&gt;::sample</a>() { 
    90 <a name="l00105"></a>00105         vec x( dim ); 
    91 <a name="l00106"></a>00106         RNG.sample_vector( dim,x ); 
    92 <a name="l00107"></a>00107         vec smp = R.sqrt_mult( x ); 
    93 <a name="l00108"></a>00108  
    94 <a name="l00109"></a>00109         smp += mu; 
    95 <a name="l00110"></a>00110         <span class="keywordflow">return</span> smp; 
    96 <a name="l00111"></a>00111 }; 
    97 <a name="l00112"></a>00112  
    98 <a name="l00113"></a>00113 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    99 <a name="l00114"></a>00114 mat <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">enorm&lt;sq_T&gt;::sample</a>( <span class="keywordtype">int</span> N ) { 
    100 <a name="l00115"></a>00115         mat X( dim,N ); 
    101 <a name="l00116"></a>00116         vec x( dim ); 
    102 <a name="l00117"></a>00117         vec pom; 
    103 <a name="l00118"></a>00118         <span class="keywordtype">int</span> i; 
    104 <a name="l00119"></a>00119         <span class="keywordflow">for</span> ( i=0;i&lt;N;i++ ) { 
    105 <a name="l00120"></a>00120                 RNG.sample_vector( dim,x ); 
    106 <a name="l00121"></a>00121                 pom = R.sqrt_mult( x ); 
    107 <a name="l00122"></a>00122                 pom +=mu; 
    108 <a name="l00123"></a>00123                 X.set_col( i, pom); 
    109 <a name="l00124"></a>00124         } 
    110 <a name="l00125"></a>00125         <span class="keywordflow">return</span> X; 
    111 <a name="l00126"></a>00126 }; 
    112 <a name="l00127"></a>00127  
    113 <a name="l00128"></a>00128 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    114 <a name="l00129"></a><a class="code" href="classenorm.html#93107f05a8e9b34b64853767200121a4">00129</a> <span class="keywordtype">double</span> <a class="code" href="classenorm.html#93107f05a8e9b34b64853767200121a4" title="Compute probability of argument val.">enorm&lt;sq_T&gt;::eval</a>( <span class="keyword">const</span> vec &amp;val ) { 
    115 <a name="l00130"></a>00130         <span class="comment">//</span> 
    116 <a name="l00131"></a>00131 }; 
    117 <a name="l00132"></a>00132  
    118 <a name="l00133"></a>00133  
    119 <a name="l00134"></a>00134 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    120 <a name="l00135"></a>00135 <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;::enorm</a>() {}; 
    121 <a name="l00136"></a>00136  
    122 <a name="l00137"></a>00137 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    123 <a name="l00138"></a>00138 mlnorm&lt;sq_T&gt;::mlnorm( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv,<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rvc, mat &amp;A, sq_T &amp;R ) { 
    124 <a name="l00139"></a>00139         <span class="keywordtype">int</span> dim = rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>(); 
    125 <a name="l00140"></a>00140         vec mu( dim ); 
    126 <a name="l00141"></a>00141  
    127 <a name="l00142"></a>00142         <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> = <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;</a>( rv,mu,R ); 
    128 <a name="l00143"></a>00143 } 
    129 <a name="l00144"></a>00144  
    130 <a name="l00145"></a>00145 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    131 <a name="l00146"></a>00146 vec mlnorm&lt;sq_T&gt;::samplecond( vec &amp;cond, <span class="keywordtype">double</span> &amp;lik ) { 
    132 <a name="l00147"></a>00147         this-&gt;condition( cond ); 
    133 <a name="l00148"></a>00148         vec smp = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.sample(); 
    134 <a name="l00149"></a>00149         lik = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.eval( smp ); 
    135 <a name="l00150"></a>00150         <span class="keywordflow">return</span> smp; 
    136 <a name="l00151"></a>00151 } 
    137 <a name="l00152"></a>00152  
    138 <a name="l00153"></a>00153 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    139 <a name="l00154"></a>00154 mat mlnorm&lt;sq_T&gt;::samplecond( vec &amp;cond, vec &amp;lik, <span class="keywordtype">int</span> n ) { 
    140 <a name="l00155"></a>00155         <span class="keywordtype">int</span> i; 
    141 <a name="l00156"></a>00156         <span class="keywordtype">int</span> dim = rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>(); 
    142 <a name="l00157"></a>00157         mat Smp( dim,n ); 
    143 <a name="l00158"></a>00158         vec smp( dim ); 
    144 <a name="l00159"></a>00159         this-&gt;condition( cond ); 
    145 <a name="l00160"></a>00160         <span class="keywordflow">for</span> ( i=0; i&lt;dim; i++ ) { 
    146 <a name="l00161"></a>00161                 smp = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.sample(); 
    147 <a name="l00162"></a>00162                 lik( i ) = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.eval( smp ); 
    148 <a name="l00163"></a>00163                 Smp.set_col( i ,smp ); 
    149 <a name="l00164"></a>00164         } 
    150 <a name="l00165"></a>00165         <span class="keywordflow">return</span> Smp; 
    151 <a name="l00166"></a>00166 } 
    152 <a name="l00167"></a>00167  
    153 <a name="l00168"></a>00168 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
    154 <a name="l00169"></a>00169 <span class="keywordtype">void</span> mlnorm&lt;sq_T&gt;::condition( vec &amp;cond ) { 
    155 <a name="l00170"></a>00170         <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.mu = A*cond; 
    156 <a name="l00171"></a>00171 <span class="comment">//R is already assigned;</span> 
    157 <a name="l00172"></a>00172 } 
    158 <a name="l00173"></a>00173  
    159 <a name="l00174"></a>00174 <span class="preprocessor">#endif //EF_H</span> 
    160 </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Mon Feb 18 21:48:39 2008 for mixpp by&nbsp; 
     69<a name="l00084"></a>00084         vec <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">sample</a>(); 
     70<a name="l00085"></a>00085         mat <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">sample</a> ( <span class="keywordtype">int</span> N ); 
     71<a name="l00086"></a>00086         <span class="keywordtype">double</span> <a class="code" href="classenorm.html#93107f05a8e9b34b64853767200121a4" title="Compute probability of argument val.">eval</a> ( <span class="keyword">const</span> vec &amp;val ); 
     72<a name="l00087"></a>00087         <span class="keywordtype">double</span> <a class="code" href="classenorm.html#9517594915e897584eaebbb057ed8881" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &amp;val ); 
     73<a name="l00088"></a><a class="code" href="classenorm.html#191c1220c3ddd0c5f54e78f19b57ebd5">00088</a>         vec <a class="code" href="classenorm.html#191c1220c3ddd0c5f54e78f19b57ebd5" title="return expected value">mean</a>(){<span class="keywordflow">return</span> <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>;} 
     74<a name="l00089"></a>00089  
     75<a name="l00090"></a>00090 <span class="comment">//Access methods</span> 
     76<a name="l00092"></a><a class="code" href="classenorm.html#3be0cb541ec9b88e5aa3f60307bbc753">00092</a> <span class="comment"></span>        vec* <a class="code" href="classenorm.html#3be0cb541ec9b88e5aa3f60307bbc753" title="returns a pointer to the internal mean value. Use with Care!">_mu</a>() {<span class="keywordflow">return</span> &amp;<a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>;} 
     77<a name="l00093"></a>00093  
     78<a name="l00095"></a><a class="code" href="classenorm.html#8725c534863c4fc2bddef0edfb95a740">00095</a>         <span class="keywordtype">void</span> <a class="code" href="classenorm.html#8725c534863c4fc2bddef0edfb95a740" title="returns pointers to the internal variance and its inverse. Use with Care!">_R</a> ( sq_T* &amp;pR, sq_T* &amp;piR ) { 
     79<a name="l00096"></a>00096                 pR=&amp;<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>; 
     80<a name="l00097"></a>00097                 piR=&amp;<a class="code" href="classenorm.html#82f39ac49911d7097f4bfe385deba355" title="Cache: _iR = inv(R);.">_iR</a>; 
     81<a name="l00098"></a>00098         } 
     82<a name="l00099"></a>00099  
     83<a name="l00101"></a><a class="code" href="classenorm.html#c9ca4f2ca42568e40ca146168e7f3247">00101</a>         <span class="keywordtype">void</span> <a class="code" href="classenorm.html#c9ca4f2ca42568e40ca146168e7f3247" title="set cache as inconsistent">_cached</a> ( <span class="keywordtype">bool</span> what ) {<a class="code" href="classenorm.html#ae12db77283a96e0f14a3eae93dc3bf1" title="indicator if _iR is chached">cached</a>=what;} 
     84<a name="l00102"></a>00102 }; 
     85<a name="l00103"></a>00103  
     86<a name="l00113"></a><a class="code" href="classegamma.html">00113</a> <span class="keyword">class </span><a class="code" href="classegamma.html" title="Gamma posterior density.">egamma</a> : <span class="keyword">public</span> <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> { 
     87<a name="l00114"></a>00114 <span class="keyword">protected</span>: 
     88<a name="l00115"></a>00115         vec alpha; 
     89<a name="l00116"></a>00116         vec beta; 
     90<a name="l00117"></a>00117 <span class="keyword">public</span> : 
     91<a name="l00119"></a><a class="code" href="classegamma.html#4b1d34f3b244ea51a58ec10c468788c1">00119</a>         <a class="code" href="classegamma.html#4b1d34f3b244ea51a58ec10c468788c1" title="Default constructor.">egamma</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv ) :<a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( rv ) {}; 
     92<a name="l00121"></a><a class="code" href="classegamma.html#8e348b89be82b70471fe8c5630f61339">00121</a>         <span class="keywordtype">void</span> <a class="code" href="classegamma.html#8e348b89be82b70471fe8c5630f61339" title="Sets parameters.">set_parameters</a> ( <span class="keyword">const</span> vec &amp;a, <span class="keyword">const</span> vec &amp;b ) {alpha=a,beta=b;}; 
     93<a name="l00122"></a>00122         vec <a class="code" href="classegamma.html#0a2186a586432c2c3f22d09c5341890f" title="Returns the required moment of the epdf.">sample</a>(); 
     94<a name="l00123"></a>00123         mat <a class="code" href="classegamma.html#0a2186a586432c2c3f22d09c5341890f" title="Returns the required moment of the epdf.">sample</a> ( <span class="keywordtype">int</span> N ); 
     95<a name="l00124"></a>00124         <span class="keywordtype">double</span> evalpdflog ( <span class="keyword">const</span> vec val ); 
     96<a name="l00126"></a><a class="code" href="classegamma.html#44445c56e60b91b377f207f8d5089790">00126</a>         <span class="keywordtype">void</span> <a class="code" href="classegamma.html#44445c56e60b91b377f207f8d5089790" title="Returns poiter to alpha and beta. Potentially dengerous: use with care!">_param</a> ( vec* &amp;a, vec* &amp;b ) {a=&amp;alpha;b=&amp;beta;}; 
     97<a name="l00127"></a><a class="code" href="classegamma.html#6617890ffa40767fc196876534d4119d">00127</a>         vec <a class="code" href="classegamma.html#6617890ffa40767fc196876534d4119d" title="return expected value">mean</a>(){vec pom(alpha); pom/=beta; <span class="keywordflow">return</span> pom;} 
     98<a name="l00128"></a>00128 }; 
     99<a name="l00129"></a>00129  
     100<a name="l00131"></a><a class="code" href="classemix.html">00131</a> <span class="keyword">class </span><a class="code" href="classemix.html" title="Weighted mixture of epdfs with external owned components.">emix</a> : <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { 
     101<a name="l00132"></a>00132 <span class="keyword">protected</span>: 
     102<a name="l00133"></a>00133         <span class="keywordtype">int</span> n; 
     103<a name="l00134"></a>00134         vec &amp;w; 
     104<a name="l00135"></a>00135         Array&lt;epdf*&gt; Coms; 
     105<a name="l00136"></a>00136 <span class="keyword">public</span>: 
     106<a name="l00138"></a><a class="code" href="classemix.html#b0ac204af8919c22bce72816ed82019e">00138</a>         <a class="code" href="classemix.html#b0ac204af8919c22bce72816ed82019e" title="Default constructor.">emix</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv, vec &amp;w0): <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>(rv), n(w0.length()), w(w0), Coms(n) {}; 
     107<a name="l00139"></a>00139         <span class="keywordtype">void</span> set_parameters( <span class="keywordtype">int</span> &amp;i, <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* ep){Coms(i)=ep;} 
     108<a name="l00140"></a><a class="code" href="classemix.html#dcb3f927bf061eac6229850158ca1558">00140</a>         vec <a class="code" href="classemix.html#dcb3f927bf061eac6229850158ca1558" title="return expected value">mean</a>(){vec pom; <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;n;i++){pom+=Coms(i)-&gt;mean()*w(i);} <span class="keywordflow">return</span> pom;}; 
     109<a name="l00141"></a><a class="code" href="classemix.html#3eb9a8e12ce1c5c8a3ddb245354b6941">00141</a>         vec <a class="code" href="classemix.html#3eb9a8e12ce1c5c8a3ddb245354b6941" title="Returns the required moment of the epdf.">sample</a>() {it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0;} 
     110<a name="l00142"></a>00142 }; 
     111<a name="l00143"></a>00143  
     112<a name="l00145"></a>00145  
     113<a name="l00146"></a><a class="code" href="classeuni.html">00146</a> <span class="keyword">class </span><a class="code" href="classeuni.html" title="Uniform distributed density on a rectangular support.">euni</a>: <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { 
     114<a name="l00147"></a>00147 <span class="keyword">protected</span>: 
     115<a name="l00149"></a><a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1">00149</a>         vec <a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1" title="lower bound on support">low</a>; 
     116<a name="l00151"></a><a class="code" href="classeuni.html#71b6d6b41aeb61a7f76f682b72119231">00151</a>         vec <a class="code" href="classeuni.html#71b6d6b41aeb61a7f76f682b72119231" title="upper bound on support">high</a>; 
     117<a name="l00153"></a><a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4">00153</a>         vec <a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a>; 
     118<a name="l00155"></a><a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda">00155</a>         <span class="keywordtype">double</span> <a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda" title="normalizing coefficients">nk</a>,lnk; 
     119<a name="l00156"></a>00156 <span class="keyword">public</span>: 
     120<a name="l00157"></a>00157         <a class="code" href="classeuni.html" title="Uniform distributed density on a rectangular support.">euni</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> rv ) :<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {} 
     121<a name="l00158"></a><a class="code" href="classeuni.html#95f29237feb32fcadf570a181d5a0918">00158</a>         <span class="keywordtype">double</span> <a class="code" href="classeuni.html#95f29237feb32fcadf570a181d5a0918" title="Compute probability of argument val.">eval</a> ( <span class="keyword">const</span> vec &amp;val ) {<span class="keywordflow">return</span> <a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda" title="normalizing coefficients">nk</a>;} 
     122<a name="l00159"></a><a class="code" href="classeuni.html#830fca2ffb6786530529c57eabc81666">00159</a>         <span class="keywordtype">double</span> <a class="code" href="classeuni.html#830fca2ffb6786530529c57eabc81666" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &amp;val ) {<span class="keywordflow">return</span> lnk;} 
     123<a name="l00160"></a><a class="code" href="classeuni.html#0f71562e3e919aba823cb7d9d420ad4c">00160</a>         vec <a class="code" href="classeuni.html#0f71562e3e919aba823cb7d9d420ad4c" title="Returns the required moment of the epdf.">sample</a>() { 
     124<a name="l00161"></a>00161                 vec smp ( rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>() ); UniRNG.sample_vector ( rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return length (number of scalars) of the RV.">count</a>(),smp ); 
     125<a name="l00162"></a>00162                 <span class="keywordflow">return</span> <a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1" title="lower bound on support">low</a>+<a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a>*smp; 
     126<a name="l00163"></a>00163         } 
     127<a name="l00164"></a>00164         <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &amp;low0, <span class="keyword">const</span> vec &amp;high0 ) { 
     128<a name="l00165"></a>00165                 <a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a> = high0-low0; 
     129<a name="l00166"></a>00166                 it_assert_debug ( min ( <a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a> ) &gt;0.0,<span class="stringliteral">"bad support"</span> ); 
     130<a name="l00167"></a>00167                 <a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1" title="lower bound on support">low</a> = low0; 
     131<a name="l00168"></a>00168                 <a class="code" href="classeuni.html#71b6d6b41aeb61a7f76f682b72119231" title="upper bound on support">high</a> = high0; 
     132<a name="l00169"></a>00169                 <a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda" title="normalizing coefficients">nk</a> = prod ( 1.0/<a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a> ); 
     133<a name="l00170"></a>00170                 lnk = log ( <a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda" title="normalizing coefficients">nk</a> ); 
     134<a name="l00171"></a>00171         } 
     135<a name="l00172"></a><a class="code" href="classeuni.html#34a2f2d23158c40b97b44dfe551a1b3d">00172</a>         vec <a class="code" href="classeuni.html#34a2f2d23158c40b97b44dfe551a1b3d" title="return expected value">mean</a>(){vec pom=<a class="code" href="classeuni.html#71b6d6b41aeb61a7f76f682b72119231" title="upper bound on support">high</a>; pom-=<a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1" title="lower bound on support">low</a>; pom/=2.0; <span class="keywordflow">return</span> pom;} 
     136<a name="l00173"></a>00173 }; 
     137<a name="l00174"></a>00174  
     138<a name="l00175"></a>00175  
     139<a name="l00181"></a>00181 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     140<a name="l00182"></a><a class="code" href="classmlnorm.html">00182</a> <span class="keyword">class </span><a class="code" href="classmlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> : <span class="keyword">public</span> mEF { 
     141<a name="l00183"></a>00183         <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; 
     142<a name="l00184"></a>00184         vec* _mu; <span class="comment">//cached epdf.mu;</span> 
     143<a name="l00185"></a>00185         mat A; 
     144<a name="l00186"></a>00186 <span class="keyword">public</span>: 
     145<a name="l00188"></a>00188         <a class="code" href="classmlnorm.html#f927203b3f31171c5c10ffc7caa797f5" title="Constructor.">mlnorm</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv,<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rvc ); 
     146<a name="l00189"></a>00189         <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span>  mat &amp;A, <span class="keyword">const</span> sq_T &amp;R ); 
     147<a name="l00191"></a>00191         vec <a class="code" href="classmlnorm.html#decf3e3b5c8e0812e5b4dbe94fa2ae18" title="Generate one sample of the posterior.">samplecond</a> ( vec &amp;cond, <span class="keywordtype">double</span> &amp;lik ); 
     148<a name="l00193"></a>00193         mat <a class="code" href="classmlnorm.html#decf3e3b5c8e0812e5b4dbe94fa2ae18" title="Generate one sample of the posterior.">samplecond</a> ( vec &amp;cond, vec &amp;lik, <span class="keywordtype">int</span> n ); 
     149<a name="l00194"></a>00194         <span class="keywordtype">void</span> condition ( vec &amp;cond ); 
     150<a name="l00195"></a>00195 }; 
     151<a name="l00196"></a>00196  
     152<a name="l00206"></a><a class="code" href="classmgamma.html">00206</a> <span class="keyword">class </span><a class="code" href="classmgamma.html" title="Gamma random walk.">mgamma</a> : <span class="keyword">public</span> mEF { 
     153<a name="l00207"></a>00207         <a class="code" href="classegamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; 
     154<a name="l00208"></a>00208         <span class="keywordtype">double</span> k; 
     155<a name="l00209"></a>00209         vec* _beta; 
     156<a name="l00210"></a>00210  
     157<a name="l00211"></a>00211 <span class="keyword">public</span>: 
     158<a name="l00213"></a>00213         <a class="code" href="classmgamma.html#af43e61b86900c0398d5c0ffc83b94e6" title="Constructor.">mgamma</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv,<span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rvc ); 
     159<a name="l00214"></a>00214         <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">double</span> k ); 
     160<a name="l00216"></a>00216         vec <a class="code" href="classmgamma.html#9f40dc43885085fad8e3d6652b79e139" title="Generate one sample of the posterior.">samplecond</a> ( vec &amp;cond, <span class="keywordtype">double</span> &amp;lik ); 
     161<a name="l00218"></a>00218         mat <a class="code" href="classmgamma.html#9f40dc43885085fad8e3d6652b79e139" title="Generate one sample of the posterior.">samplecond</a> ( vec &amp;cond, vec &amp;lik, <span class="keywordtype">int</span> n ); 
     162<a name="l00219"></a>00219         <span class="keywordtype">void</span> condition ( <span class="keyword">const</span> vec &amp;val ) {*_beta=k/val;}; 
     163<a name="l00220"></a>00220 }; 
     164<a name="l00221"></a>00221  
     165<a name="l00223"></a><a class="code" href="libEF_8h.html#99497a3ff630f761cf6bff7babd23212">00223</a> <span class="keyword">enum</span> <a class="code" href="libEF_8h.html#99497a3ff630f761cf6bff7babd23212" title="Switch between various resampling methods.">RESAMPLING_METHOD</a> { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; 
     166<a name="l00229"></a><a class="code" href="classeEmp.html">00229</a> <span class="keyword">class </span><a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a>: <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { 
     167<a name="l00230"></a>00230 <span class="keyword">protected</span> : 
     168<a name="l00232"></a><a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd">00232</a>         <span class="keywordtype">int</span> <a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd" title="Number of particles.">n</a>; 
     169<a name="l00233"></a>00233         vec w; 
     170<a name="l00234"></a>00234         Array&lt;vec&gt; samples; 
     171<a name="l00235"></a>00235 <span class="keyword">public</span>: 
     172<a name="l00236"></a>00236         <a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv0 ) :<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv0 ) {}; 
     173<a name="l00237"></a>00237         <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &amp;w0, <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); 
     174<a name="l00239"></a><a class="code" href="classeEmp.html#31b2bfb73b72486a5c89f2ab850c7a9b">00239</a>         vec&amp; <a class="code" href="classeEmp.html#31b2bfb73b72486a5c89f2ab850c7a9b" title="Potentially dangerous, use with care.">_w</a>()  {<span class="keywordflow">return</span> w;}; 
     175<a name="l00240"></a>00240         Array&lt;vec&gt;&amp; _samples() {<span class="keywordflow">return</span> samples;}; 
     176<a name="l00242"></a>00242         ivec <a class="code" href="classeEmp.html#77268292fc4465cb73ddbfb1f2932a59" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> ( <a class="code" href="libEF_8h.html#99497a3ff630f761cf6bff7babd23212" title="Switch between various resampling methods.">RESAMPLING_METHOD</a> method = SYSTEMATIC ); 
     177<a name="l00243"></a><a class="code" href="classeEmp.html#c9b44099a400579b88aff9f5afaf9c13">00243</a>         vec <a class="code" href="classeEmp.html#c9b44099a400579b88aff9f5afaf9c13" title="Returns the required moment of the epdf.">sample</a>() {it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0;} 
     178<a name="l00244"></a><a class="code" href="classeEmp.html#de42454cb65a17fd8662d207dd59aacf">00244</a>         vec <a class="code" href="classeEmp.html#de42454cb65a17fd8662d207dd59aacf" title="return expected value">mean</a>(){vec pom;  
     179<a name="l00245"></a>00245                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd" title="Number of particles.">n</a>;i++){pom+=samples(i)*w(i);} 
     180<a name="l00246"></a>00246                 <span class="keywordflow">return</span> pom; 
     181<a name="l00247"></a>00247         } 
     182<a name="l00248"></a>00248 }; 
     183<a name="l00249"></a>00249  
     184<a name="l00250"></a>00250  
     185<a name="l00252"></a>00252  
     186<a name="l00253"></a>00253 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     187<a name="l00254"></a>00254 <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;::enorm</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv ) :<a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a>(), mu ( rv.count() ),R ( rv.count() ),_iR ( rv.count() ),cached ( false ),dim ( rv.count() ) {}; 
     188<a name="l00255"></a>00255  
     189<a name="l00256"></a>00256 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     190<a name="l00257"></a>00257 <span class="keywordtype">void</span> <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;::set_parameters</a> ( <span class="keyword">const</span> vec &amp;mu0, <span class="keyword">const</span> sq_T &amp;R0 ) { 
     191<a name="l00258"></a>00258 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> 
     192<a name="l00259"></a>00259         mu = mu0; 
     193<a name="l00260"></a>00260         R = R0; 
     194<a name="l00261"></a>00261         <span class="keywordflow">if</span> ( _iR.rows() !=R.rows() ) _iR=R; <span class="comment">// memory allocation!</span> 
     195<a name="l00262"></a>00262         R.inv ( _iR ); <span class="comment">//update cache</span> 
     196<a name="l00263"></a>00263         cached=<span class="keyword">true</span>; 
     197<a name="l00264"></a>00264 }; 
     198<a name="l00265"></a>00265  
     199<a name="l00266"></a>00266 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     200<a name="l00267"></a>00267 <span class="keywordtype">void</span> <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm&lt;sq_T&gt;::dupdate</a> ( mat &amp;v, <span class="keywordtype">double</span> nu ) { 
     201<a name="l00268"></a>00268         <span class="comment">//</span> 
     202<a name="l00269"></a>00269 }; 
     203<a name="l00270"></a>00270  
     204<a name="l00271"></a>00271 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     205<a name="l00272"></a><a class="code" href="classenorm.html#5b5fd142b6b17ea334597960e3fe126a">00272</a> <span class="keywordtype">void</span> <a class="code" href="classenorm.html#5b5fd142b6b17ea334597960e3fe126a" title="tupdate in exponential form (not really handy)">enorm&lt;sq_T&gt;::tupdate</a> ( <span class="keywordtype">double</span> phi, mat &amp;vbar, <span class="keywordtype">double</span> nubar ) { 
     206<a name="l00273"></a>00273         <span class="comment">//</span> 
     207<a name="l00274"></a>00274 }; 
     208<a name="l00275"></a>00275  
     209<a name="l00276"></a>00276 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     210<a name="l00277"></a><a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023">00277</a> vec <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">enorm&lt;sq_T&gt;::sample</a>() { 
     211<a name="l00278"></a>00278         vec x ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a> ); 
     212<a name="l00279"></a>00279         NorRNG.sample_vector ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>,x ); 
     213<a name="l00280"></a>00280         vec smp = <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); 
     214<a name="l00281"></a>00281  
     215<a name="l00282"></a>00282         smp += <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>; 
     216<a name="l00283"></a>00283         <span class="keywordflow">return</span> smp; 
     217<a name="l00284"></a>00284 }; 
     218<a name="l00285"></a>00285  
     219<a name="l00286"></a>00286 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     220<a name="l00287"></a>00287 mat <a class="code" href="classenorm.html#6020bcd89db2c9584bd8871001bd2023" title="Returns the required moment of the epdf.">enorm&lt;sq_T&gt;::sample</a> ( <span class="keywordtype">int</span> N ) { 
     221<a name="l00288"></a>00288         mat X ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>,N ); 
     222<a name="l00289"></a>00289         vec x ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a> ); 
     223<a name="l00290"></a>00290         vec pom; 
     224<a name="l00291"></a>00291         <span class="keywordtype">int</span> i; 
     225<a name="l00292"></a>00292  
     226<a name="l00293"></a>00293         <span class="keywordflow">for</span> ( i=0;i&lt;N;i++ ) { 
     227<a name="l00294"></a>00294                 NorRNG.sample_vector ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>,x ); 
     228<a name="l00295"></a>00295                 pom = <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); 
     229<a name="l00296"></a>00296                 pom +=<a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>; 
     230<a name="l00297"></a>00297                 X.set_col ( i, pom ); 
     231<a name="l00298"></a>00298         } 
     232<a name="l00299"></a>00299  
     233<a name="l00300"></a>00300         <span class="keywordflow">return</span> X; 
     234<a name="l00301"></a>00301 }; 
     235<a name="l00302"></a>00302  
     236<a name="l00303"></a>00303 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     237<a name="l00304"></a><a class="code" href="classenorm.html#93107f05a8e9b34b64853767200121a4">00304</a> <span class="keywordtype">double</span> <a class="code" href="classenorm.html#93107f05a8e9b34b64853767200121a4" title="Compute probability of argument val.">enorm&lt;sq_T&gt;::eval</a> ( <span class="keyword">const</span> vec &amp;val ) { 
     238<a name="l00305"></a>00305         <span class="keywordtype">double</span> pdfl,e; 
     239<a name="l00306"></a>00306         pdfl = <a class="code" href="classenorm.html#9517594915e897584eaebbb057ed8881" title="Compute log-probability of argument val.">evalpdflog</a> ( val ); 
     240<a name="l00307"></a>00307         e = exp ( pdfl ); 
     241<a name="l00308"></a>00308         <span class="keywordflow">return</span> e; 
     242<a name="l00309"></a>00309 }; 
     243<a name="l00310"></a>00310  
     244<a name="l00311"></a>00311 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     245<a name="l00312"></a><a class="code" href="classenorm.html#9517594915e897584eaebbb057ed8881">00312</a> <span class="keywordtype">double</span> <a class="code" href="classenorm.html#9517594915e897584eaebbb057ed8881" title="Compute log-probability of argument val.">enorm&lt;sq_T&gt;::evalpdflog</a> ( <span class="keyword">const</span> vec &amp;val ) { 
     246<a name="l00313"></a>00313         <span class="keywordflow">if</span> ( !<a class="code" href="classenorm.html#ae12db77283a96e0f14a3eae93dc3bf1" title="indicator if _iR is chached">cached</a> ) {<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.inv ( <a class="code" href="classenorm.html#82f39ac49911d7097f4bfe385deba355" title="Cache: _iR = inv(R);.">_iR</a> );<a class="code" href="classenorm.html#ae12db77283a96e0f14a3eae93dc3bf1" title="indicator if _iR is chached">cached</a>=<span class="keyword">true</span>;} 
     247<a name="l00314"></a>00314  
     248<a name="l00315"></a>00315         <span class="keywordflow">return</span> -0.5* ( <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.cols() *0.79817986835811504957 +<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.logdet() +<a class="code" href="classenorm.html#82f39ac49911d7097f4bfe385deba355" title="Cache: _iR = inv(R);.">_iR</a>.qform ( <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>-val ) ); 
     249<a name="l00316"></a>00316 }; 
     250<a name="l00317"></a>00317  
     251<a name="l00318"></a>00318  
     252<a name="l00319"></a>00319 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     253<a name="l00320"></a><a class="code" href="classmlnorm.html#f927203b3f31171c5c10ffc7caa797f5">00320</a> <a class="code" href="classmlnorm.html#f927203b3f31171c5c10ffc7caa797f5" title="Constructor.">mlnorm&lt;sq_T&gt;::mlnorm</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rv0,<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;rvc0 ) :mEF ( rv0,rvc0 ),<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ),A ( rv0.count(),rv0.count() ) { 
     254<a name="l00321"></a>00321         _mu = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._mu(); 
     255<a name="l00322"></a>00322 } 
     256<a name="l00323"></a>00323  
     257<a name="l00324"></a>00324 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     258<a name="l00325"></a>00325 <span class="keywordtype">void</span> <a class="code" href="classmlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm&lt;sq_T&gt;::set_parameters</a> ( <span class="keyword">const</span> mat &amp;A0, <span class="keyword">const</span> sq_T &amp;R0 ) { 
     259<a name="l00326"></a>00326         <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( rv.count() ),R0 ); 
     260<a name="l00327"></a>00327         A = A0; 
     261<a name="l00328"></a>00328 } 
     262<a name="l00329"></a>00329  
     263<a name="l00330"></a>00330 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     264<a name="l00331"></a><a class="code" href="classmlnorm.html#decf3e3b5c8e0812e5b4dbe94fa2ae18">00331</a> vec <a class="code" href="classmlnorm.html#decf3e3b5c8e0812e5b4dbe94fa2ae18" title="Generate one sample of the posterior.">mlnorm&lt;sq_T&gt;::samplecond</a> ( vec &amp;cond, <span class="keywordtype">double</span> &amp;lik ) { 
     265<a name="l00332"></a>00332         this-&gt;condition ( cond ); 
     266<a name="l00333"></a>00333         vec smp = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.sample(); 
     267<a name="l00334"></a>00334         lik = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.eval ( smp ); 
     268<a name="l00335"></a>00335         <span class="keywordflow">return</span> smp; 
     269<a name="l00336"></a>00336 } 
     270<a name="l00337"></a>00337  
     271<a name="l00338"></a>00338 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     272<a name="l00339"></a><a class="code" href="classmlnorm.html#215fb88cc8b95d64cdefd6849abdd1e8">00339</a> mat <a class="code" href="classmlnorm.html#decf3e3b5c8e0812e5b4dbe94fa2ae18" title="Generate one sample of the posterior.">mlnorm&lt;sq_T&gt;::samplecond</a> ( vec &amp;cond, vec &amp;lik, <span class="keywordtype">int</span> n ) { 
     273<a name="l00340"></a>00340         <span class="keywordtype">int</span> i; 
     274<a name="l00341"></a>00341         <span class="keywordtype">int</span> dim = rv.count(); 
     275<a name="l00342"></a>00342         mat Smp ( dim,n ); 
     276<a name="l00343"></a>00343         vec smp ( dim ); 
     277<a name="l00344"></a>00344         this-&gt;condition ( cond ); 
     278<a name="l00345"></a>00345  
     279<a name="l00346"></a>00346         <span class="keywordflow">for</span> ( i=0; i&lt;n; i++ ) { 
     280<a name="l00347"></a>00347                 smp = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.sample(); 
     281<a name="l00348"></a>00348                 lik ( i ) = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.eval ( smp ); 
     282<a name="l00349"></a>00349                 Smp.set_col ( i ,smp ); 
     283<a name="l00350"></a>00350         } 
     284<a name="l00351"></a>00351  
     285<a name="l00352"></a>00352         <span class="keywordflow">return</span> Smp; 
     286<a name="l00353"></a>00353 } 
     287<a name="l00354"></a>00354  
     288<a name="l00355"></a>00355 <span class="keyword">template</span>&lt;<span class="keyword">class</span> sq_T&gt; 
     289<a name="l00356"></a>00356 <span class="keywordtype">void</span> <a class="code" href="classmlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm&lt;sq_T&gt;::condition</a> ( vec &amp;cond ) { 
     290<a name="l00357"></a>00357         *_mu = A*cond; 
     291<a name="l00358"></a>00358 <span class="comment">//R is already assigned;</span> 
     292<a name="l00359"></a>00359 } 
     293<a name="l00360"></a>00360  
     294<a name="l00362"></a>00362  
     295<a name="l00363"></a>00363  
     296<a name="l00364"></a>00364 <span class="preprocessor">#endif //EF_H</span> 
     297</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Feb 28 16:54:40 2008 for mixpp by&nbsp; 
    161298<a href="http://www.doxygen.org/index.html"> 
    162299<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>