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: work/git/mixpp/bdm/stat/libEF.h Source File</title> |
---|
4 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.6 --> |
---|
8 | <div class="navigation" id="top"> |
---|
9 | <div class="tabs"> |
---|
10 | <ul> |
---|
11 | <li><a href="index.html"><span>Main Page</span></a></li> |
---|
12 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
13 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
14 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
15 | </ul> |
---|
16 | </div> |
---|
17 | <h1>work/git/mixpp/bdm/stat/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 |
---|
18 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef EF_H</span> |
---|
19 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define EF_H</span> |
---|
20 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
21 | <a name="l00016"></a>00016 <span class="preprocessor">#include <itpp/itbase.h></span> |
---|
22 | <a name="l00017"></a>00017 <span class="preprocessor">#include "../math/libDC.h"</span> |
---|
23 | <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> |
---|
24 | <a name="l00019"></a>00019 <span class="preprocessor">#include "../itpp_ext.h"</span> |
---|
25 | <a name="l00020"></a>00020 <span class="comment">//#include <std></span> |
---|
26 | <a name="l00021"></a>00021 |
---|
27 | <a name="l00022"></a>00022 <span class="keyword">using namespace </span>itpp; |
---|
28 | <a name="l00023"></a>00023 |
---|
29 | <a name="l00024"></a>00024 |
---|
30 | <a name="l00026"></a>00026 <span class="keyword">extern</span> Uniform_RNG UniRNG; |
---|
31 | <a name="l00028"></a>00028 <span class="keyword">extern</span> Normal_RNG NorRNG; |
---|
32 | <a name="l00030"></a>00030 <span class="keyword">extern</span> <a class="code" href="classitpp_1_1Gamma__RNG.html" title="Gamma distribution.">Gamma_RNG</a> GamRNG; |
---|
33 | <a name="l00031"></a>00031 |
---|
34 | <a name="l00038"></a><a class="code" href="classeEF.html">00038</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> { |
---|
35 | <a name="l00039"></a>00039 <span class="keyword">public</span>: |
---|
36 | <a name="l00040"></a>00040 <span class="comment">// eEF() :epdf() {};</span> |
---|
37 | <a name="l00042"></a><a class="code" href="classeEF.html#7e3c63655e8375c76bf1f421245427a7">00042</a> <span class="comment"></span> <a class="code" href="classeEF.html#7e3c63655e8375c76bf1f421245427a7" 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> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) :<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {}; |
---|
38 | <a name="l00044"></a>00044 <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classeEF.html#69e5680dac10375d62520d26c672477d" title="logarithm of the normalizing constant, ">lognc</a>() <span class="keyword">const</span> =0; |
---|
39 | <a name="l00046"></a><a class="code" href="classeEF.html#a89bef8996410609004fa019b5b48964">00046</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classeEF.html#a89bef8996410609004fa019b5b48964" title="TODO decide if it is really needed.">dupdate</a> ( mat &v ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
40 | <a name="l00048"></a><a class="code" href="classeEF.html#48cdd33d0e20d1a1aa45683c956bc61c">00048</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classeEF.html#48cdd33d0e20d1a1aa45683c956bc61c" title="Evaluate normalized log-probability.">evalpdflog_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;}; |
---|
41 | <a name="l00050"></a><a class="code" href="classeEF.html#6466e8d4aa9dd64698ed288cbb1afc03">00050</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classeEF.html#6466e8d4aa9dd64698ed288cbb1afc03" title="Evaluate normalized log-probability.">evalpdflog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classeEF.html#48cdd33d0e20d1a1aa45683c956bc61c" title="Evaluate normalized log-probability.">evalpdflog_nn</a> ( val )-<a class="code" href="classeEF.html#69e5680dac10375d62520d26c672477d" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
42 | <a name="l00052"></a><a class="code" href="classeEF.html#c71faf4b2d153efda14bf1f87dca1507">00052</a> <span class="keyword">virtual</span> vec <a class="code" href="classeEF.html#6466e8d4aa9dd64698ed288cbb1afc03" title="Evaluate normalized log-probability.">evalpdflog</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
---|
43 | <a name="l00053"></a>00053 vec x ( Val.cols() ); |
---|
44 | <a name="l00054"></a>00054 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<Val.cols();i++ ) {x ( i ) =<a class="code" href="classeEF.html#48cdd33d0e20d1a1aa45683c956bc61c" title="Evaluate normalized log-probability.">evalpdflog_nn</a> ( Val.get_col ( i ) ) ;} |
---|
45 | <a name="l00055"></a>00055 <span class="keywordflow">return</span> x-<a class="code" href="classeEF.html#69e5680dac10375d62520d26c672477d" title="logarithm of the normalizing constant, ">lognc</a>(); |
---|
46 | <a name="l00056"></a>00056 } |
---|
47 | <a name="l00058"></a><a class="code" href="classeEF.html#4f8385dd1cc9740522dc373b1dc3cbf5">00058</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classeEF.html#4f8385dd1cc9740522dc373b1dc3cbf5" 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> );}; |
---|
48 | <a name="l00059"></a>00059 }; |
---|
49 | <a name="l00060"></a>00060 |
---|
50 | <a name="l00067"></a><a class="code" href="classmEF.html">00067</a> <span class="keyword">class </span><a class="code" href="classmEF.html" title="Exponential family model.">mEF</a> : <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
---|
51 | <a name="l00068"></a>00068 |
---|
52 | <a name="l00069"></a>00069 <span class="keyword">public</span>: |
---|
53 | <a name="l00071"></a><a class="code" href="classmEF.html#8bf51fe8654d7b83c8c8afeb19409d4f">00071</a> <a class="code" href="classmEF.html#8bf51fe8654d7b83c8c8afeb19409d4f" title="Default constructor.">mEF</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rv0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvc0 ) :<a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv0,rvc0 ) {}; |
---|
54 | <a name="l00072"></a>00072 }; |
---|
55 | <a name="l00073"></a>00073 |
---|
56 | <a name="l00075"></a><a class="code" href="classBMEF.html">00075</a> <span class="keyword">class </span><a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a> : <span class="keyword">public</span> <a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a> { |
---|
57 | <a name="l00076"></a>00076 <span class="keyword">protected</span>: |
---|
58 | <a name="l00078"></a><a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71">00078</a> <span class="keywordtype">double</span> <a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a>; |
---|
59 | <a name="l00080"></a><a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02">00080</a> <span class="keywordtype">double</span> <a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>; |
---|
60 | <a name="l00081"></a>00081 <span class="keyword">public</span>: |
---|
61 | <a name="l00083"></a><a class="code" href="classBMEF.html#46ac5c919ae647f3a6a38d9faba35f5d">00083</a> <a class="code" href="classBMEF.html#46ac5c919ae647f3a6a38d9faba35f5d" title="Default constructor.">BMEF</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>, <span class="keywordtype">double</span> frg0=1.0 ) :<a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a> ( rv ), <a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a> ( frg0 ) {} |
---|
62 | <a name="l00085"></a><a class="code" href="classBMEF.html#3dc6277cafbdc6cbc2db860ff219b33e">00085</a> <a class="code" href="classBMEF.html#46ac5c919ae647f3a6a38d9faba35f5d" title="Default constructor.">BMEF</a> ( <span class="keyword">const</span> <a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a> &B ) :<a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a> ( B ), <a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a> ( B.<a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a> ), <a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> ( B.<a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> ) {} |
---|
63 | <a name="l00087"></a><a class="code" href="classBMEF.html#30bb40eb1fd31869b2e62e79e1ecdcb4">00087</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classBMEF.html#30bb40eb1fd31869b2e62e79e1ecdcb4" title="get statistics from another model">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a>* BM0 ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
64 | <a name="l00089"></a><a class="code" href="classBMEF.html#8f4ecb6e2eaf630155a1fa98f35aa6ad">00089</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classBMEF.html#8f4ecb6e2eaf630155a1fa98f35aa6ad" 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 ) {}; |
---|
65 | <a name="l00090"></a>00090 <span class="comment">//original Bayes</span> |
---|
66 | <a name="l00091"></a>00091 <span class="keywordtype">void</span> <a class="code" href="classBMEF.html#8f4ecb6e2eaf630155a1fa98f35aa6ad" title="Weighted update of sufficient statistics (Bayes rule).">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
---|
67 | <a name="l00093"></a><a class="code" href="classBMEF.html#b3689f3ade328d157aa813384a5b153a">00093</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classBMEF.html#b3689f3ade328d157aa813384a5b153a" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a> * B ) {it_error ( <span class="stringliteral">"Not implemented"</span> );} |
---|
68 | <a name="l00095"></a><a class="code" href="classBMEF.html#c285f29db290d05428bf1aa2cd7c35ad">00095</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classBMEF.html#b3689f3ade328d157aa813384a5b153a" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keywordtype">double</span> nu0 ) {it_error ( <span class="stringliteral">"Not implemented"</span> );} |
---|
69 | <a name="l00096"></a>00096 }; |
---|
70 | <a name="l00097"></a>00097 |
---|
71 | <a name="l00098"></a>00098 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
72 | <a name="l00099"></a>00099 <span class="keyword">class </span><a class="code" href="classmlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a>; |
---|
73 | <a name="l00100"></a>00100 |
---|
74 | <a name="l00106"></a>00106 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
75 | <a name="l00107"></a><a class="code" href="classenorm.html">00107</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> { |
---|
76 | <a name="l00108"></a>00108 <span class="keyword">protected</span>: |
---|
77 | <a name="l00110"></a><a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20">00110</a> vec <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>; |
---|
78 | <a name="l00112"></a><a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1">00112</a> sq_T <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>; |
---|
79 | <a name="l00114"></a><a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e">00114</a> <span class="keywordtype">int</span> <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>; |
---|
80 | <a name="l00115"></a>00115 <span class="keyword">public</span>: |
---|
81 | <a name="l00117"></a>00117 <a class="code" href="classenorm.html#0caf54fed9e48f9fe28b534b2027df2f" title="Default constructor.">enorm</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
---|
82 | <a name="l00119"></a>00119 <span class="keywordtype">void</span> <a class="code" href="classenorm.html#1394a65caa6e00d42e00cc99b12227af" title="Set mean value mu and covariance R.">set_parameters</a> ( <span class="keyword">const</span> vec &<a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>,<span class="keyword">const</span> sq_T &<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a> ); |
---|
83 | <a name="l00121"></a>00121 <span class="comment">//void tupdate ( double phi, mat &vbar, double nubar );</span> |
---|
84 | <a name="l00123"></a>00123 <span class="comment"></span> <span class="keywordtype">void</span> <a class="code" href="classenorm.html#5bf185e31e5954fceb90ada3debd2ff2" title="dupdate in exponential form (not really handy)">dupdate</a> ( mat &v,<span class="keywordtype">double</span> nu=1.0 ); |
---|
85 | <a name="l00124"></a>00124 |
---|
86 | <a name="l00125"></a>00125 vec <a class="code" href="classenorm.html#60b47544f6181ffd4530d3e415ce12c5" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
87 | <a name="l00127"></a>00127 mat <a class="code" href="classenorm.html#60b47544f6181ffd4530d3e415ce12c5" title="Returns a sample, from density .">sample</a> ( <span class="keywordtype">int</span> N ) <span class="keyword">const</span>; |
---|
88 | <a name="l00128"></a>00128 <span class="keywordtype">double</span> <a class="code" href="classenorm.html#b9e1dfd33692d7b3f1a59f17b0e61bd0" title="Compute probability of argument val.">eval</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span> ; |
---|
89 | <a name="l00129"></a>00129 <span class="keywordtype">double</span> <a class="code" href="classenorm.html#c1e3dcba256b0153cfdb286120e110be" title="Evaluate normalized log-probability.">evalpdflog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
90 | <a name="l00130"></a>00130 <span class="keywordtype">double</span> <a class="code" href="classenorm.html#b289a36a69db59d182bb6eba9c05d4a8" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
91 | <a name="l00131"></a><a class="code" href="classenorm.html#50fa84da7bae02f7af17a98f37566899">00131</a> vec <a class="code" href="classenorm.html#50fa84da7bae02f7af17a98f37566899" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>;} |
---|
92 | <a name="l00132"></a>00132 <a class="code" href="classmlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a>* <a class="code" href="classenorm.html#13b7d503c6444eb4db4f359b13ec3bc2" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ); |
---|
93 | <a name="l00133"></a>00133 <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classenorm.html#14c05e1d059684b64c455ac16703b1c1" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
---|
94 | <a name="l00134"></a>00134 <span class="comment">//Access methods</span> |
---|
95 | <a name="l00136"></a><a class="code" href="classenorm.html#0b8cb284e5af920a1b64a21d057ec5ac">00136</a> <span class="comment"></span> vec& <a class="code" href="classenorm.html#0b8cb284e5af920a1b64a21d057ec5ac" title="returns a pointer to the internal mean value. Use with Care!">_mu</a>() {<span class="keywordflow">return</span> <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>;} |
---|
96 | <a name="l00137"></a>00137 |
---|
97 | <a name="l00139"></a><a class="code" href="classenorm.html#d892a38f03be12e572ea57d9689cef6b">00139</a> <span class="keywordtype">void</span> <a class="code" href="classenorm.html#d892a38f03be12e572ea57d9689cef6b" title="access function">set_mu</a> ( <span class="keyword">const</span> vec mu0 ) { <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>=mu0;} |
---|
98 | <a name="l00140"></a>00140 |
---|
99 | <a name="l00142"></a><a class="code" href="classenorm.html#7a5034b25771a84450a990d10fc40ac9">00142</a> sq_T& <a class="code" href="classenorm.html#7a5034b25771a84450a990d10fc40ac9" title="returns pointers to the internal variance and its inverse. Use with Care!">_R</a>() {<span class="keywordflow">return</span> <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>;} |
---|
100 | <a name="l00143"></a>00143 |
---|
101 | <a name="l00145"></a>00145 <span class="comment">// mat getR () {return R.to_mat();}</span> |
---|
102 | <a name="l00146"></a>00146 }; |
---|
103 | <a name="l00147"></a>00147 |
---|
104 | <a name="l00154"></a><a class="code" href="classegiw.html">00154</a> <span class="keyword">class </span><a class="code" href="classegiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> : <span class="keyword">public</span> <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> { |
---|
105 | <a name="l00155"></a>00155 <span class="keyword">protected</span>: |
---|
106 | <a name="l00157"></a><a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442">00157</a> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>; |
---|
107 | <a name="l00159"></a><a class="code" href="classegiw.html#4a2f130b91afe84f6d62fed289d5d453">00159</a> <span class="keywordtype">double</span> <a class="code" href="classegiw.html#4a2f130b91afe84f6d62fed289d5d453" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>; |
---|
108 | <a name="l00161"></a><a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e">00161</a> <span class="keywordtype">int</span> <a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e" title="Dimension of the output.">xdim</a>; |
---|
109 | <a name="l00163"></a><a class="code" href="classegiw.html#c70d13d86e0d9f0acede3e1dc0368812">00163</a> <span class="keywordtype">int</span> <a class="code" href="classegiw.html#c70d13d86e0d9f0acede3e1dc0368812" title="Dimension of the regressor.">nPsi</a>; |
---|
110 | <a name="l00164"></a>00164 <span class="keyword">public</span>: |
---|
111 | <a name="l00166"></a><a class="code" href="classegiw.html#c52a2173c6eb1490edce9c6c7c05d60b">00166</a> <a class="code" href="classegiw.html#c52a2173c6eb1490edce9c6c7c05d60b" title="Default constructor, assuming.">egiw</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>, mat V0, <span class="keywordtype">double</span> nu0 ) : <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( rv ), <a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a> ( V0 ), <a class="code" href="classegiw.html#4a2f130b91afe84f6d62fed289d5d453" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> ( nu0 ) { |
---|
112 | <a name="l00167"></a>00167 <a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e" title="Dimension of the output.">xdim</a> = rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() /<a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>.<a class="code" href="classldmat.html#96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>(); |
---|
113 | <a name="l00168"></a>00168 it_assert_debug ( rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ==<a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e" title="Dimension of the output.">xdim</a>*<a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>.<a class="code" href="classldmat.html#96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>(),<span class="stringliteral">"Incompatible V0."</span> ); |
---|
114 | <a name="l00169"></a>00169 <a class="code" href="classegiw.html#c70d13d86e0d9f0acede3e1dc0368812" title="Dimension of the regressor.">nPsi</a> = <a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>.<a class="code" href="classldmat.html#96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>()-<a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e" title="Dimension of the output.">xdim</a>; |
---|
115 | <a name="l00170"></a>00170 } |
---|
116 | <a name="l00172"></a><a class="code" href="classegiw.html#1a17fdbac6c72b9c3abb97623db466c8">00172</a> <a class="code" href="classegiw.html#c52a2173c6eb1490edce9c6c7c05d60b" title="Default constructor, assuming.">egiw</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>, <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 ) : <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( rv ), <a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a> ( V0 ), <a class="code" href="classegiw.html#4a2f130b91afe84f6d62fed289d5d453" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> ( nu0 ) { |
---|
117 | <a name="l00173"></a>00173 <a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e" title="Dimension of the output.">xdim</a> = rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() /<a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>.<a class="code" href="classldmat.html#96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>(); |
---|
118 | <a name="l00174"></a>00174 it_assert_debug ( rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ==<a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e" title="Dimension of the output.">xdim</a>*<a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>.<a class="code" href="classldmat.html#96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>(),<span class="stringliteral">"Incompatible V0."</span> ); |
---|
119 | <a name="l00175"></a>00175 <a class="code" href="classegiw.html#c70d13d86e0d9f0acede3e1dc0368812" title="Dimension of the regressor.">nPsi</a> = <a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>.<a class="code" href="classldmat.html#96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>()-<a class="code" href="classegiw.html#3d5c719f15a5527a6c62c2a53160148e" title="Dimension of the output.">xdim</a>; |
---|
120 | <a name="l00176"></a>00176 } |
---|
121 | <a name="l00177"></a>00177 |
---|
122 | <a name="l00178"></a>00178 vec <a class="code" href="classegiw.html#3d2c1f2ba0f9966781f1e0ae695e8a6f" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
123 | <a name="l00179"></a>00179 vec <a class="code" href="classegiw.html#6deb0ff2859f41ef7cbdf6a842cabb29" title="return expected value">mean</a>() <span class="keyword">const</span>; |
---|
124 | <a name="l00180"></a>00180 <span class="keywordtype">void</span> mean_mat ( mat &M, mat&R ) <span class="keyword">const</span>; |
---|
125 | <a name="l00182"></a>00182 <span class="keywordtype">double</span> <a class="code" href="classegiw.html#2ab1e525d692be8272a6f383d60b94cd" title="In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise...">evalpdflog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
126 | <a name="l00183"></a>00183 <span class="keywordtype">double</span> <a class="code" href="classegiw.html#70eb1a0b88459b227f919b425b0d3359" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
127 | <a name="l00184"></a>00184 |
---|
128 | <a name="l00185"></a>00185 <span class="comment">//Access</span> |
---|
129 | <a name="l00187"></a><a class="code" href="classegiw.html#533e792e1175bfa06d5d595dc5d080d5">00187</a> <span class="comment"></span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& <a class="code" href="classegiw.html#533e792e1175bfa06d5d595dc5d080d5" title="returns a pointer to the internal statistics. Use with Care!">_V</a>() {<span class="keywordflow">return</span> <a class="code" href="classegiw.html#f343d03ede89db820edf44a6297fa442" title="Extended information matrix of sufficient statistics.">V</a>;} |
---|
130 | <a name="l00189"></a><a class="code" href="classegiw.html#08029c481ff95d24f093df0573879afe">00189</a> <span class="keywordtype">double</span>& <a class="code" href="classegiw.html#08029c481ff95d24f093df0573879afe" title="returns a pointer to the internal statistics. Use with Care!">_nu</a>() {<span class="keywordflow">return</span> <a class="code" href="classegiw.html#4a2f130b91afe84f6d62fed289d5d453" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
---|
131 | <a name="l00190"></a>00190 <span class="keywordtype">void</span> <a class="code" href="classegiw.html#036306322a90a9977834baac07460816" title="Power of the density, used e.g. to flatten the density.">pow</a> ( <span class="keywordtype">double</span> p ); |
---|
132 | <a name="l00191"></a>00191 }; |
---|
133 | <a name="l00192"></a>00192 |
---|
134 | <a name="l00201"></a><a class="code" href="classeDirich.html">00201</a> <span class="keyword">class </span><a class="code" href="classeDirich.html" title="Dirichlet posterior density.">eDirich</a>: <span class="keyword">public</span> <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> { |
---|
135 | <a name="l00202"></a>00202 <span class="keyword">protected</span>: |
---|
136 | <a name="l00204"></a><a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7">00204</a> vec <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>; |
---|
137 | <a name="l00205"></a>00205 <span class="keyword">public</span>: |
---|
138 | <a name="l00207"></a><a class="code" href="classeDirich.html#ac7e6116f3575c3860d07355e96cd4af">00207</a> <a class="code" href="classeDirich.html#ac7e6116f3575c3860d07355e96cd4af" title="Default constructor.">eDirich</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>, <span class="keyword">const</span> vec &beta0 ) : <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( rv ),<a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a> ( beta0 ) {it_assert_debug ( rv.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ==<a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>.length(),<span class="stringliteral">"Incompatible statistics"</span> ); }; |
---|
139 | <a name="l00209"></a><a class="code" href="classeDirich.html#55cccbc5eb44764dce722567acf5fd58">00209</a> <a class="code" href="classeDirich.html#ac7e6116f3575c3860d07355e96cd4af" title="Default constructor.">eDirich</a> ( <span class="keyword">const</span> <a class="code" href="classeDirich.html" title="Dirichlet posterior density.">eDirich</a> &D0 ) : <a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( D0.<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ),<a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a> ( D0.<a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a> ) {}; |
---|
140 | <a name="l00210"></a><a class="code" href="classeDirich.html#23dff79110822e9639343fe8e177fd80">00210</a> vec <a class="code" href="classeDirich.html#23dff79110822e9639343fe8e177fd80" 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 );}; |
---|
141 | <a name="l00211"></a><a class="code" href="classeDirich.html#4206e1da149d51ff3b663c9241096b73">00211</a> vec <a class="code" href="classeDirich.html#4206e1da149d51ff3b663c9241096b73" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>/sum ( <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a> );}; |
---|
142 | <a name="l00213"></a><a class="code" href="classeDirich.html#688a24f04be6d80d4769cf0e4ded7acc">00213</a> <span class="keywordtype">double</span> <a class="code" href="classeDirich.html#688a24f04be6d80d4769cf0e4ded7acc" title="In this instance, val is ...">evalpdflog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> ( <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>-1 ) *log ( val );}; |
---|
143 | <a name="l00214"></a><a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77">00214</a> <span class="keywordtype">double</span> <a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const </span>{ |
---|
144 | <a name="l00215"></a>00215 <span class="keywordtype">double</span> gam=sum ( <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a> ); |
---|
145 | <a name="l00216"></a>00216 <span class="keywordtype">double</span> lgb=0.0; |
---|
146 | <a name="l00217"></a>00217 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>.length();i++ ) {lgb+=lgamma ( <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a> ( i ) );} |
---|
147 | <a name="l00218"></a>00218 <span class="keywordflow">return</span> lgb-lgamma ( gam ); |
---|
148 | <a name="l00219"></a>00219 }; |
---|
149 | <a name="l00221"></a><a class="code" href="classeDirich.html#6409d0362143a23976b43641ff19e53a">00221</a> vec& <a class="code" href="classeDirich.html#6409d0362143a23976b43641ff19e53a" title="access function">_beta</a>() {<span class="keywordflow">return</span> <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>;} |
---|
150 | <a name="l00223"></a><a class="code" href="classeDirich.html#c842acb2e1cce5cc9000769ff06c086d">00223</a> <span class="keywordtype">void</span> <a class="code" href="classeDirich.html#c842acb2e1cce5cc9000769ff06c086d" title="Set internal parameters.">set_parameters</a> ( <span class="keyword">const</span> vec &beta0 ) { |
---|
151 | <a name="l00224"></a>00224 <span class="keywordflow">if</span> ( beta0.length() !=<a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>.length() ) { |
---|
152 | <a name="l00225"></a>00225 it_assert_debug ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#c114a6f3ff06796cc2f4dacba74291eb" title="Return length (number of entries) of the RV.">length</a>() ==1,<span class="stringliteral">"Undefined"</span> ); |
---|
153 | <a name="l00226"></a>00226 <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#70b24c39c5130b1e4753fa2eef495433" title="access function">set_size</a> ( 0,beta0.length() ); |
---|
154 | <a name="l00227"></a>00227 } |
---|
155 | <a name="l00228"></a>00228 <a class="code" href="classeDirich.html#15e6b65e9595eedc8a1286c6cecd36d7" title="sufficient statistics">beta</a>= beta0; |
---|
156 | <a name="l00229"></a>00229 } |
---|
157 | <a name="l00230"></a>00230 }; |
---|
158 | <a name="l00231"></a>00231 |
---|
159 | <a name="l00233"></a><a class="code" href="classmultiBM.html">00233</a> <span class="keyword">class </span><a class="code" href="classmultiBM.html" title="Estimator for Multinomial density.">multiBM</a> : <span class="keyword">public</span> <a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a> { |
---|
160 | <a name="l00234"></a>00234 <span class="keyword">protected</span>: |
---|
161 | <a name="l00236"></a><a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5">00236</a> <a class="code" href="classeDirich.html" title="Dirichlet posterior density.">eDirich</a> <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>; |
---|
162 | <a name="l00238"></a><a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6">00238</a> vec &<a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a>; |
---|
163 | <a name="l00239"></a>00239 <span class="keyword">public</span>: |
---|
164 | <a name="l00241"></a><a class="code" href="classmultiBM.html#7d7d7e78c129602bcde96078359dc6e5">00241</a> <a class="code" href="classmultiBM.html#7d7d7e78c129602bcde96078359dc6e5" title="Default constructor.">multiBM</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>, <span class="keyword">const</span> vec beta0 ) : <a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a> ( rv ),<a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a> ( rv,beta0 ),<a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>._beta() ) {<a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
165 | <a name="l00243"></a><a class="code" href="classmultiBM.html#b92751adbfb9f259ca8c95232cfd9c09">00243</a> <a class="code" href="classmultiBM.html#7d7d7e78c129602bcde96078359dc6e5" title="Default constructor.">multiBM</a> ( <span class="keyword">const</span> <a class="code" href="classmultiBM.html" title="Estimator for Multinomial density.">multiBM</a> &B ) : <a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a> ( B ),<a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a> ( <a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>,B.<a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a> ),<a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>._beta() ) {} |
---|
166 | <a name="l00245"></a><a class="code" href="classmultiBM.html#42e36804041e551d3ceea6c75abc0562">00245</a> <span class="keywordtype">void</span> <a class="code" href="classmultiBM.html#42e36804041e551d3ceea6c75abc0562" title="Sets sufficient statistics to match that of givefrom mB0.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a>* mB0 ) {<span class="keyword">const</span> <a class="code" href="classmultiBM.html" title="Estimator for Multinomial density.">multiBM</a>* mB=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classmultiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> ( mB0 ); <a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a>=mB-><a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a>;} |
---|
167 | <a name="l00246"></a><a class="code" href="classmultiBM.html#11eeba7e97954e316e959116f90d80e2">00246</a> <span class="keywordtype">void</span> <a class="code" href="classmultiBM.html#11eeba7e97954e316e959116f90d80e2" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ) { |
---|
168 | <a name="l00247"></a>00247 <span class="keywordflow">if</span> ( <a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a><1.0 ) {<a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a>*=<a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a>;<a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
169 | <a name="l00248"></a>00248 <a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a>+=dt; |
---|
170 | <a name="l00249"></a>00249 <span class="keywordflow">if</span> ( <a class="code" href="classBM.html#bf6fb59b30141074f8ee1e2f43d03129" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classBM.html#5623fef6572a08c2b53b8c87b82dc979" title="Logarithm of marginalized data likelihood.">ll</a>=<a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>()-<a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
---|
171 | <a name="l00250"></a>00250 } |
---|
172 | <a name="l00251"></a><a class="code" href="classmultiBM.html#13e26a61757278981fd8cac9a7ef91eb">00251</a> <span class="keywordtype">double</span> <a class="code" href="classmultiBM.html#13e26a61757278981fd8cac9a7ef91eb">logpred</a> ( <span class="keyword">const</span> vec &dt )<span class="keyword"> const </span>{ |
---|
173 | <a name="l00252"></a>00252 <a class="code" href="classeDirich.html" title="Dirichlet posterior density.">eDirich</a> pred ( <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a> ); |
---|
174 | <a name="l00253"></a>00253 vec &<a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a> = pred.<a class="code" href="classeDirich.html#6409d0362143a23976b43641ff19e53a" title="access function">_beta</a>(); |
---|
175 | <a name="l00254"></a>00254 |
---|
176 | <a name="l00255"></a>00255 <span class="keywordtype">double</span> lll; |
---|
177 | <a name="l00256"></a>00256 <span class="keywordflow">if</span> ( <a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a><1.0 ) |
---|
178 | <a name="l00257"></a>00257 {beta*=<a class="code" href="classBMEF.html#538d632e59f9afa8daa1de74da12ce71" title="forgetting factor">frg</a>;lll=pred.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
179 | <a name="l00258"></a>00258 <span class="keywordflow">else</span> |
---|
180 | <a name="l00259"></a>00259 <span class="keywordflow">if</span> ( <a class="code" href="classBM.html#bf6fb59b30141074f8ee1e2f43d03129" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {lll=<a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
---|
181 | <a name="l00260"></a>00260 <span class="keywordflow">else</span>{lll=pred.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
182 | <a name="l00261"></a>00261 |
---|
183 | <a name="l00262"></a>00262 beta+=dt; |
---|
184 | <a name="l00263"></a>00263 <span class="keywordflow">return</span> pred.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>()-lll; |
---|
185 | <a name="l00264"></a>00264 } |
---|
186 | <a name="l00265"></a><a class="code" href="classmultiBM.html#3988322f8f51b153622036f461f62a67">00265</a> <span class="keywordtype">void</span> <a class="code" href="classmultiBM.html#3988322f8f51b153622036f461f62a67" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classBMEF.html" title="Estimator for Exponential family.">BMEF</a>* B ) { |
---|
187 | <a name="l00266"></a>00266 <span class="keyword">const</span> <a class="code" href="classeDirich.html" title="Dirichlet posterior density.">eDirich</a>* E=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classeDirich.html" title="Dirichlet posterior density.">eDirich</a>*<span class="keyword">></span> ( B ); |
---|
188 | <a name="l00267"></a>00267 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
---|
189 | <a name="l00268"></a>00268 <span class="keyword">const</span> vec &Eb=<span class="keyword">const_cast<</span><a class="code" href="classeDirich.html" title="Dirichlet posterior density.">eDirich</a>*<span class="keyword">></span> ( E )->_beta(); |
---|
190 | <a name="l00269"></a>00269 <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classeEF.html#4f8385dd1cc9740522dc373b1dc3cbf5" title="Power of the density, used e.g. to flatten the density.">pow</a> ( sum ( <a class="code" href="classmultiBM.html#7b606116aed7e8834a339cbb0424b1d6" title="Pointer inside est to sufficient statistics.">beta</a> ) /sum ( Eb ) ); |
---|
191 | <a name="l00270"></a>00270 <span class="keywordflow">if</span> ( <a class="code" href="classBM.html#bf6fb59b30141074f8ee1e2f43d03129" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
192 | <a name="l00271"></a>00271 } |
---|
193 | <a name="l00272"></a><a class="code" href="classmultiBM.html#66cdfd83a70bc281840ab0646b941684">00272</a> <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& <a class="code" href="classmultiBM.html#66cdfd83a70bc281840ab0646b941684" title="Returns a pointer to the epdf representing posterior density on parameters. Use with...">_epdf</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>;}; |
---|
194 | <a name="l00273"></a>00273 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) { |
---|
195 | <a name="l00274"></a>00274 <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classeDirich.html#c842acb2e1cce5cc9000769ff06c086d" title="Set internal parameters.">set_parameters</a> ( beta0 ); |
---|
196 | <a name="l00275"></a>00275 <a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a> = <a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>(); |
---|
197 | <a name="l00276"></a>00276 <span class="keywordflow">if</span> ( <a class="code" href="classBM.html#bf6fb59b30141074f8ee1e2f43d03129" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classBMEF.html#308cf5d4133cd471fdf1ecd5dfa09d02" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classmultiBM.html#eddee08a724170de63f36e40c57b27b5" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classeDirich.html#7ce60be7119ffc639ede4e583c1f6e77" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
198 | <a name="l00277"></a>00277 } |
---|
199 | <a name="l00278"></a>00278 }; |
---|
200 | <a name="l00279"></a>00279 |
---|
201 | <a name="l00289"></a><a class="code" href="classegamma.html">00289</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> { |
---|
202 | <a name="l00290"></a>00290 <span class="keyword">protected</span>: |
---|
203 | <a name="l00292"></a><a class="code" href="classegamma.html#376cebd8932546c440f21b182910b01b">00292</a> vec <a class="code" href="classegamma.html#376cebd8932546c440f21b182910b01b" title="Vector .">alpha</a>; |
---|
204 | <a name="l00294"></a><a class="code" href="classegamma.html#cfc5f136467488a421ab22f886323790">00294</a> vec <a class="code" href="classegamma.html#cfc5f136467488a421ab22f886323790" title="Vector .">beta</a>; |
---|
205 | <a name="l00295"></a>00295 <span class="keyword">public</span> : |
---|
206 | <a name="l00297"></a><a class="code" href="classegamma.html#4b1d34f3b244ea51a58ec10c468788c1">00297</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> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) :<a class="code" href="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( rv ) {}; |
---|
207 | <a name="l00299"></a><a class="code" href="classegamma.html#8e348b89be82b70471fe8c5630f61339">00299</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 &a, <span class="keyword">const</span> vec &b ) {<a class="code" href="classegamma.html#376cebd8932546c440f21b182910b01b" title="Vector .">alpha</a>=a,<a class="code" href="classegamma.html#cfc5f136467488a421ab22f886323790" title="Vector .">beta</a>=b;}; |
---|
208 | <a name="l00300"></a>00300 vec <a class="code" href="classegamma.html#8e10c0021b5dfdd9cb62c6959b5ef425" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
209 | <a name="l00302"></a>00302 <span class="comment">// mat sample ( int N ) const;</span> |
---|
210 | <a name="l00303"></a>00303 <span class="keywordtype">double</span> <a class="code" href="classegamma.html#de84faac8f9799dfe2777ddbedf997ef" title="TODO: is it used anywhere?">evalpdflog</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
211 | <a name="l00304"></a>00304 <span class="keywordtype">double</span> <a class="code" href="classegamma.html#d6dbbdb72360f9e54d64501f80318bb6" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
212 | <a name="l00306"></a><a class="code" href="classegamma.html#44445c56e60b91b377f207f8d5089790">00306</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* &a, vec* &b ) {a=&<a class="code" href="classegamma.html#376cebd8932546c440f21b182910b01b" title="Vector .">alpha</a>;b=&<a class="code" href="classegamma.html#cfc5f136467488a421ab22f886323790" title="Vector .">beta</a>;}; |
---|
213 | <a name="l00307"></a><a class="code" href="classegamma.html#6ab5ba56f7cdb2e5921c3e77524fa50a">00307</a> vec <a class="code" href="classegamma.html#6ab5ba56f7cdb2e5921c3e77524fa50a" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec pom ( <a class="code" href="classegamma.html#376cebd8932546c440f21b182910b01b" title="Vector .">alpha</a> ); pom/=<a class="code" href="classegamma.html#cfc5f136467488a421ab22f886323790" title="Vector .">beta</a>; <span class="keywordflow">return</span> pom;} |
---|
214 | <a name="l00308"></a>00308 }; |
---|
215 | <a name="l00309"></a>00309 <span class="comment">/*</span> |
---|
216 | <a name="l00311"></a>00311 <span class="comment">class emix : public epdf {</span> |
---|
217 | <a name="l00312"></a>00312 <span class="comment">protected:</span> |
---|
218 | <a name="l00313"></a>00313 <span class="comment"> int n;</span> |
---|
219 | <a name="l00314"></a>00314 <span class="comment"> vec &w;</span> |
---|
220 | <a name="l00315"></a>00315 <span class="comment"> Array<epdf*> Coms;</span> |
---|
221 | <a name="l00316"></a>00316 <span class="comment">public:</span> |
---|
222 | <a name="l00318"></a>00318 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
---|
223 | <a name="l00319"></a>00319 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
---|
224 | <a name="l00320"></a>00320 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
---|
225 | <a name="l00321"></a>00321 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
---|
226 | <a name="l00322"></a>00322 <span class="comment">};</span> |
---|
227 | <a name="l00323"></a>00323 <span class="comment">*/</span> |
---|
228 | <a name="l00324"></a>00324 |
---|
229 | <a name="l00326"></a>00326 |
---|
230 | <a name="l00327"></a><a class="code" href="classeuni.html">00327</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> { |
---|
231 | <a name="l00328"></a>00328 <span class="keyword">protected</span>: |
---|
232 | <a name="l00330"></a><a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1">00330</a> vec <a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1" title="lower bound on support">low</a>; |
---|
233 | <a name="l00332"></a><a class="code" href="classeuni.html#71b6d6b41aeb61a7f76f682b72119231">00332</a> vec <a class="code" href="classeuni.html#71b6d6b41aeb61a7f76f682b72119231" title="upper bound on support">high</a>; |
---|
234 | <a name="l00334"></a><a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4">00334</a> vec <a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a>; |
---|
235 | <a name="l00336"></a><a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda">00336</a> <span class="keywordtype">double</span> <a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda" title="normalizing coefficients">nk</a>; |
---|
236 | <a name="l00338"></a><a class="code" href="classeuni.html#f445a0ce24f39d14c1a4eed53fc8e2c3">00338</a> <span class="keywordtype">double</span> <a class="code" href="classeuni.html#f445a0ce24f39d14c1a4eed53fc8e2c3" title="cache of log( nk )">lnk</a>; |
---|
237 | <a name="l00339"></a>00339 <span class="keyword">public</span>: |
---|
238 | <a name="l00341"></a><a class="code" href="classeuni.html#2537a6c239cff52e3ba814851a1116cd">00341</a> <a class="code" href="classeuni.html#2537a6c239cff52e3ba814851a1116cd" title="Defualt constructor.">euni</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) :<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {} |
---|
239 | <a name="l00342"></a><a class="code" href="classeuni.html#2723d4992900b5c5495bfa03628195ed">00342</a> <span class="keywordtype">double</span> <a class="code" href="classeuni.html#2723d4992900b5c5495bfa03628195ed" title="Compute probability of argument val.">eval</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda" title="normalizing coefficients">nk</a>;} |
---|
240 | <a name="l00343"></a><a class="code" href="classeuni.html#06af95d514a6623ad4688bd2ad50ad71">00343</a> <span class="keywordtype">double</span> <a class="code" href="classeuni.html#06af95d514a6623ad4688bd2ad50ad71" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classeuni.html#f445a0ce24f39d14c1a4eed53fc8e2c3" title="cache of log( nk )">lnk</a>;} |
---|
241 | <a name="l00344"></a><a class="code" href="classeuni.html#4a0e09392be17beaee120ba98fc038cd">00344</a> vec <a class="code" href="classeuni.html#4a0e09392be17beaee120ba98fc038cd" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
---|
242 | <a name="l00345"></a>00345 vec smp ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
---|
243 | <a name="l00346"></a>00346 <span class="preprocessor">#pragma omp critical</span> |
---|
244 | <a name="l00347"></a>00347 <span class="preprocessor"></span> UniRNG.sample_vector ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(),smp ); |
---|
245 | <a name="l00348"></a>00348 <span class="keywordflow">return</span> <a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1" title="lower bound on support">low</a>+elem_mult ( <a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a>,smp ); |
---|
246 | <a name="l00349"></a>00349 } |
---|
247 | <a name="l00351"></a><a class="code" href="classeuni.html#4fd7c6a05100616ad16ece405cad7bf2">00351</a> <span class="keywordtype">void</span> <a class="code" href="classeuni.html#4fd7c6a05100616ad16ece405cad7bf2" title="set values of low and high ">set_parameters</a> ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) { |
---|
248 | <a name="l00352"></a>00352 <a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a> = high0-low0; |
---|
249 | <a name="l00353"></a>00353 it_assert_debug ( min ( <a class="code" href="classeuni.html#52a6ff4a54010f88a6a19fca605c64a4" title="internal">distance</a> ) >0.0,<span class="stringliteral">"bad support"</span> ); |
---|
250 | <a name="l00354"></a>00354 <a class="code" href="classeuni.html#ef42cd8d7645422048d46c46ec5cdac1" title="lower bound on support">low</a> = low0; |
---|
251 | <a name="l00355"></a>00355 <a class="code" href="classeuni.html#71b6d6b41aeb61a7f76f682b72119231" title="upper bound on support">high</a> = high0; |
---|
252 | <a name="l00356"></a>00356 <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> ); |
---|
253 | <a name="l00357"></a>00357 <a class="code" href="classeuni.html#f445a0ce24f39d14c1a4eed53fc8e2c3" title="cache of log( nk )">lnk</a> = log ( <a class="code" href="classeuni.html#63105490e946e43372d6187ad1bafdda" title="normalizing coefficients">nk</a> ); |
---|
254 | <a name="l00358"></a>00358 } |
---|
255 | <a name="l00359"></a><a class="code" href="classeuni.html#8050087e421a9cfd1b4b1f8bd33b1cc1">00359</a> vec <a class="code" href="classeuni.html#8050087e421a9cfd1b4b1f8bd33b1cc1" title="return expected value">mean</a>()<span class="keyword"> const </span>{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;} |
---|
256 | <a name="l00360"></a>00360 }; |
---|
257 | <a name="l00361"></a>00361 |
---|
258 | <a name="l00362"></a>00362 |
---|
259 | <a name="l00368"></a>00368 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
260 | <a name="l00369"></a><a class="code" href="classmlnorm.html">00369</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> <a class="code" href="classmEF.html" title="Exponential family model.">mEF</a> { |
---|
261 | <a name="l00371"></a>00371 <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
---|
262 | <a name="l00372"></a>00372 mat A; |
---|
263 | <a name="l00373"></a>00373 vec mu_const; |
---|
264 | <a name="l00374"></a>00374 vec& _mu; <span class="comment">//cached epdf.mu;</span> |
---|
265 | <a name="l00375"></a>00375 <span class="keyword">public</span>: |
---|
266 | <a name="l00377"></a>00377 <a class="code" href="classmlnorm.html#3a5ad4798d8a3878c5e93b8e796c8837" title="Constructor.">mlnorm</a> (<span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
---|
267 | <a name="l00379"></a>00379 <span class="keywordtype">void</span> <a class="code" href="classmlnorm.html#f95dfce0b500636a44ecd7e5210de999" 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 ); |
---|
268 | <a name="l00381"></a>00381 vec <a class="code" href="classmlnorm.html#1bd939dbf8ec7b8066d3f18abba6822b" title="Generate one sample of the posterior.">samplecond</a> (<span class="keyword">const</span> vec &cond, <span class="keywordtype">double</span> &lik ); |
---|
269 | <a name="l00383"></a>00383 mat <a class="code" href="classmlnorm.html#1bd939dbf8ec7b8066d3f18abba6822b" title="Generate one sample of the posterior.">samplecond</a> (<span class="keyword">const</span> vec &cond, vec &lik, <span class="keywordtype">int</span> n ); |
---|
270 | <a name="l00385"></a>00385 <span class="keywordtype">void</span> <a class="code" href="classmlnorm.html#d41126455ac64b888a38f677886e1b40" title="Set value of rvc . Result of this operation is stored in epdf use function _ep to...">condition</a> (<span class="keyword">const</span> vec &cond ); |
---|
271 | <a name="l00386"></a>00386 }; |
---|
272 | <a name="l00387"></a>00387 |
---|
273 | <a name="l00397"></a><a class="code" href="classmgamma.html">00397</a> <span class="keyword">class </span><a class="code" href="classmgamma.html" title="Gamma random walk.">mgamma</a> : <span class="keyword">public</span> <a class="code" href="classmEF.html" title="Exponential family model.">mEF</a> { |
---|
274 | <a name="l00398"></a>00398 <span class="keyword">protected</span>: |
---|
275 | <a name="l00400"></a><a class="code" href="classmgamma.html#612dbf35c770a780027619aaac2c443e">00400</a> <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>; |
---|
276 | <a name="l00402"></a><a class="code" href="classmgamma.html#43f733cce0245a52363d566099add687">00402</a> <span class="keywordtype">double</span> <a class="code" href="classmgamma.html#43f733cce0245a52363d566099add687" title="Constant .">k</a>; |
---|
277 | <a name="l00404"></a><a class="code" href="classmgamma.html#5e90652837448bcc29707e7412f99691">00404</a> vec* <a class="code" href="classmgamma.html#5e90652837448bcc29707e7412f99691" title="cache of epdf.beta">_beta</a>; |
---|
278 | <a name="l00405"></a>00405 |
---|
279 | <a name="l00406"></a>00406 <span class="keyword">public</span>: |
---|
280 | <a name="l00408"></a>00408 <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> &<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>,<span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
---|
281 | <a name="l00410"></a>00410 <span class="keywordtype">void</span> <a class="code" href="classmgamma.html#a9d646cf758a70126dde7c48790b6e94" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> <a class="code" href="classmgamma.html#43f733cce0245a52363d566099add687" title="Constant .">k</a> ); |
---|
282 | <a name="l00411"></a><a class="code" href="classmgamma.html#a61094c9f7a2d64ea77b130cbc031f97">00411</a> <span class="keywordtype">void</span> <a class="code" href="classmgamma.html#a61094c9f7a2d64ea77b130cbc031f97" 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="classmgamma.html#5e90652837448bcc29707e7412f99691" title="cache of epdf.beta">_beta</a>=<a class="code" href="classmgamma.html#43f733cce0245a52363d566099add687" title="Constant .">k</a>/val;}; |
---|
283 | <a name="l00412"></a>00412 }; |
---|
284 | <a name="l00413"></a>00413 |
---|
285 | <a name="l00425"></a><a class="code" href="classmgamma__fix.html">00425</a> <span class="keyword">class </span><a class="code" href="classmgamma__fix.html" title="Gamma random walk around a fixed point.">mgamma_fix</a> : <span class="keyword">public</span> <a class="code" href="classmgamma.html" title="Gamma random walk.">mgamma</a> { |
---|
286 | <a name="l00426"></a>00426 <span class="keyword">protected</span>: |
---|
287 | <a name="l00428"></a><a class="code" href="classmgamma__fix.html#3f48c09caddc298901ad75fe7c0529f6">00428</a> <span class="keywordtype">double</span> <a class="code" href="classmgamma__fix.html#3f48c09caddc298901ad75fe7c0529f6" title="parameter l">l</a>; |
---|
288 | <a name="l00430"></a><a class="code" href="classmgamma__fix.html#81ce49029ecc385418619b200dcafeb0">00430</a> vec <a class="code" href="classmgamma__fix.html#81ce49029ecc385418619b200dcafeb0" title="reference vector">refl</a>; |
---|
289 | <a name="l00431"></a>00431 <span class="keyword">public</span>: |
---|
290 | <a name="l00433"></a><a class="code" href="classmgamma__fix.html#b92c3d2e5fd0381033a072e5ef3bcf80">00433</a> <a class="code" href="classmgamma__fix.html#b92c3d2e5fd0381033a072e5ef3bcf80" title="Constructor.">mgamma_fix</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>,<span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ) : <a class="code" href="classmgamma.html" title="Gamma random walk.">mgamma</a> ( rv,rvc ),<a class="code" href="classmgamma__fix.html#81ce49029ecc385418619b200dcafeb0" title="reference vector">refl</a> ( rv.count() ) {}; |
---|
291 | <a name="l00435"></a><a class="code" href="classmgamma__fix.html#ec6f846896749e27cb7be9fa48dd1cb1">00435</a> <span class="keywordtype">void</span> <a class="code" href="classmgamma__fix.html#ec6f846896749e27cb7be9fa48dd1cb1" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0 ) { |
---|
292 | <a name="l00436"></a>00436 <a class="code" href="classmgamma.html#a9d646cf758a70126dde7c48790b6e94" title="Set value of k.">mgamma::set_parameters</a> ( k0 ); |
---|
293 | <a name="l00437"></a>00437 <a class="code" href="classmgamma__fix.html#81ce49029ecc385418619b200dcafeb0" title="reference vector">refl</a>=pow ( ref0,1.0-l0 );<a class="code" href="classmgamma__fix.html#3f48c09caddc298901ad75fe7c0529f6" title="parameter l">l</a>=l0; |
---|
294 | <a name="l00438"></a>00438 }; |
---|
295 | <a name="l00439"></a>00439 |
---|
296 | <a name="l00440"></a><a class="code" href="classmgamma__fix.html#6ea3931eec7b7da7b693e45981052460">00440</a> <span class="keywordtype">void</span> <a class="code" href="classmgamma__fix.html#6ea3931eec7b7da7b693e45981052460" 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="classmgamma__fix.html#81ce49029ecc385418619b200dcafeb0" title="reference vector">refl</a>,pow ( val,<a class="code" href="classmgamma__fix.html#3f48c09caddc298901ad75fe7c0529f6" title="parameter l">l</a> ) ); *<a class="code" href="classmgamma.html#5e90652837448bcc29707e7412f99691" title="cache of epdf.beta">_beta</a>=<a class="code" href="classmgamma.html#43f733cce0245a52363d566099add687" title="Constant .">k</a>/mean;}; |
---|
297 | <a name="l00441"></a>00441 }; |
---|
298 | <a name="l00442"></a>00442 |
---|
299 | <a name="l00444"></a><a class="code" href="libEF_8h.html#99497a3ff630f761cf6bff7babd23212">00444</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 }; |
---|
300 | <a name="l00450"></a><a class="code" href="classeEmp.html">00450</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> { |
---|
301 | <a name="l00451"></a>00451 <span class="keyword">protected</span> : |
---|
302 | <a name="l00453"></a><a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd">00453</a> <span class="keywordtype">int</span> <a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd" title="Number of particles.">n</a>; |
---|
303 | <a name="l00455"></a><a class="code" href="classeEmp.html#ae78d144404ddba843c93b171b215de8">00455</a> vec <a class="code" href="classeEmp.html#ae78d144404ddba843c93b171b215de8" title="Sample weights .">w</a>; |
---|
304 | <a name="l00457"></a><a class="code" href="classeEmp.html#a4d6f4bbd6a6824fc39f14676701279a">00457</a> Array<vec> <a class="code" href="classeEmp.html#a4d6f4bbd6a6824fc39f14676701279a" title="Samples .">samples</a>; |
---|
305 | <a name="l00458"></a>00458 <span class="keyword">public</span>: |
---|
306 | <a name="l00460"></a><a class="code" href="classeEmp.html#0c04b073ecd0dae3d498e680ae27e9e4">00460</a> <a class="code" href="classeEmp.html#0c04b073ecd0dae3d498e680ae27e9e4" title="Default constructor.">eEmp</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rv0 ,<span class="keywordtype">int</span> n0 ) :<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv0 ),<a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd" title="Number of particles.">n</a> ( n0 ),<a class="code" href="classeEmp.html#ae78d144404ddba843c93b171b215de8" title="Sample weights .">w</a> ( <a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd" title="Number of particles.">n</a> ),<a class="code" href="classeEmp.html#a4d6f4bbd6a6824fc39f14676701279a" title="Samples .">samples</a> ( <a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd" title="Number of particles.">n</a> ) {}; |
---|
307 | <a name="l00462"></a>00462 <span class="keywordtype">void</span> <a class="code" href="classeEmp.html#eab03bd3381aaea11ce34d5a26556353" title="Set samples and weights.">set_parameters</a> ( <span class="keyword">const</span> vec &w0, <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); |
---|
308 | <a name="l00464"></a>00464 <span class="keywordtype">void</span> <a class="code" href="classeEmp.html#e31bc9e6196173c3480b06a761a3e716" title="Set sample.">set_samples</a> ( <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); |
---|
309 | <a name="l00466"></a><a class="code" href="classeEmp.html#31b2bfb73b72486a5c89f2ab850c7a9b">00466</a> vec& <a class="code" href="classeEmp.html#31b2bfb73b72486a5c89f2ab850c7a9b" title="Potentially dangerous, use with care.">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classeEmp.html#ae78d144404ddba843c93b171b215de8" title="Sample weights .">w</a>;}; |
---|
310 | <a name="l00468"></a><a class="code" href="classeEmp.html#31b747eca73b16f30370827ba4cc3575">00468</a> Array<vec>& <a class="code" href="classeEmp.html#31b747eca73b16f30370827ba4cc3575" title="access function">_samples</a>() {<span class="keywordflow">return</span> <a class="code" href="classeEmp.html#a4d6f4bbd6a6824fc39f14676701279a" title="Samples .">samples</a>;}; |
---|
311 | <a name="l00470"></a>00470 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 ); |
---|
312 | <a name="l00472"></a><a class="code" href="classeEmp.html#83f9283f92b805508d896479dc1ccf12">00472</a> vec <a class="code" href="classeEmp.html#83f9283f92b805508d896479dc1ccf12" 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;} |
---|
313 | <a name="l00474"></a><a class="code" href="classeEmp.html#23e7358995400865ad2e278945922fb3">00474</a> <span class="keywordtype">double</span> <a class="code" href="classeEmp.html#23e7358995400865ad2e278945922fb3" title="inherited operation : NOT implemneted">evalpdflog</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;} |
---|
314 | <a name="l00475"></a><a class="code" href="classeEmp.html#ba055c19038cc72628d98e25197e982d">00475</a> vec <a class="code" href="classeEmp.html#ba055c19038cc72628d98e25197e982d" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
---|
315 | <a name="l00476"></a>00476 vec pom=zeros ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
---|
316 | <a name="l00477"></a>00477 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeEmp.html#8c33034de0e35f03f8bb85d3d67438fd" title="Number of particles.">n</a>;i++ ) {pom+=<a class="code" href="classeEmp.html#a4d6f4bbd6a6824fc39f14676701279a" title="Samples .">samples</a> ( i ) *<a class="code" href="classeEmp.html#ae78d144404ddba843c93b171b215de8" title="Sample weights .">w</a> ( i );} |
---|
317 | <a name="l00478"></a>00478 <span class="keywordflow">return</span> pom; |
---|
318 | <a name="l00479"></a>00479 } |
---|
319 | <a name="l00480"></a>00480 }; |
---|
320 | <a name="l00481"></a>00481 |
---|
321 | <a name="l00482"></a>00482 |
---|
322 | <a name="l00484"></a>00484 |
---|
323 | <a name="l00485"></a>00485 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
324 | <a name="l00486"></a><a class="code" href="classenorm.html#0caf54fed9e48f9fe28b534b2027df2f">00486</a> <a class="code" href="classenorm.html#0caf54fed9e48f9fe28b534b2027df2f" title="Default constructor.">enorm<sq_T>::enorm</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="classeEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( rv ), mu ( rv.count() ),R ( rv.count() ),dim ( rv.count() ) {}; |
---|
325 | <a name="l00487"></a>00487 |
---|
326 | <a name="l00488"></a>00488 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
327 | <a name="l00489"></a><a class="code" href="classenorm.html#1394a65caa6e00d42e00cc99b12227af">00489</a> <span class="keywordtype">void</span> <a class="code" href="classenorm.html#1394a65caa6e00d42e00cc99b12227af" title="Set mean value mu and covariance R.">enorm<sq_T>::set_parameters</a> ( <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0 ) { |
---|
328 | <a name="l00490"></a>00490 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
---|
329 | <a name="l00491"></a>00491 <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a> = mu0; |
---|
330 | <a name="l00492"></a>00492 <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a> = R0; |
---|
331 | <a name="l00493"></a>00493 }; |
---|
332 | <a name="l00494"></a>00494 |
---|
333 | <a name="l00495"></a>00495 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
334 | <a name="l00496"></a><a class="code" href="classenorm.html#5bf185e31e5954fceb90ada3debd2ff2">00496</a> <span class="keywordtype">void</span> <a class="code" href="classenorm.html#5bf185e31e5954fceb90ada3debd2ff2" title="dupdate in exponential form (not really handy)">enorm<sq_T>::dupdate</a> ( mat &v, <span class="keywordtype">double</span> nu ) { |
---|
335 | <a name="l00497"></a>00497 <span class="comment">//</span> |
---|
336 | <a name="l00498"></a>00498 }; |
---|
337 | <a name="l00499"></a>00499 |
---|
338 | <a name="l00500"></a>00500 <span class="comment">// template<class sq_T></span> |
---|
339 | <a name="l00501"></a>00501 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
---|
340 | <a name="l00502"></a>00502 <span class="comment">// //</span> |
---|
341 | <a name="l00503"></a>00503 <span class="comment">// };</span> |
---|
342 | <a name="l00504"></a>00504 |
---|
343 | <a name="l00505"></a>00505 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
344 | <a name="l00506"></a><a class="code" href="classenorm.html#60b47544f6181ffd4530d3e415ce12c5">00506</a> vec <a class="code" href="classenorm.html#60b47544f6181ffd4530d3e415ce12c5" title="Returns a sample, from density .">enorm<sq_T>::sample</a>()<span class="keyword"> const </span>{ |
---|
345 | <a name="l00507"></a>00507 vec x ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a> ); |
---|
346 | <a name="l00508"></a>00508 NorRNG.sample_vector ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>,x ); |
---|
347 | <a name="l00509"></a>00509 vec smp = <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
---|
348 | <a name="l00510"></a>00510 |
---|
349 | <a name="l00511"></a>00511 smp += <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>; |
---|
350 | <a name="l00512"></a>00512 <span class="keywordflow">return</span> smp; |
---|
351 | <a name="l00513"></a>00513 }; |
---|
352 | <a name="l00514"></a>00514 |
---|
353 | <a name="l00515"></a>00515 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
354 | <a name="l00516"></a><a class="code" href="classenorm.html#60f0f3bfa53d6e65843eea9532b16d36">00516</a> mat <a class="code" href="classenorm.html#60b47544f6181ffd4530d3e415ce12c5" title="Returns a sample, from density .">enorm<sq_T>::sample</a> ( <span class="keywordtype">int</span> N )<span class="keyword"> const </span>{ |
---|
355 | <a name="l00517"></a>00517 mat X ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>,N ); |
---|
356 | <a name="l00518"></a>00518 vec x ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a> ); |
---|
357 | <a name="l00519"></a>00519 vec pom; |
---|
358 | <a name="l00520"></a>00520 <span class="keywordtype">int</span> i; |
---|
359 | <a name="l00521"></a>00521 |
---|
360 | <a name="l00522"></a>00522 <span class="keywordflow">for</span> ( i=0;i<N;i++ ) { |
---|
361 | <a name="l00523"></a>00523 NorRNG.sample_vector ( <a class="code" href="classenorm.html#6938fc390a19cdaf6ad4503fcbaada4e" title="dimension (redundant from rv.count() for easier coding )">dim</a>,x ); |
---|
362 | <a name="l00524"></a>00524 pom = <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
---|
363 | <a name="l00525"></a>00525 pom +=<a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>; |
---|
364 | <a name="l00526"></a>00526 X.set_col ( i, pom ); |
---|
365 | <a name="l00527"></a>00527 } |
---|
366 | <a name="l00528"></a>00528 |
---|
367 | <a name="l00529"></a>00529 <span class="keywordflow">return</span> X; |
---|
368 | <a name="l00530"></a>00530 }; |
---|
369 | <a name="l00531"></a>00531 |
---|
370 | <a name="l00532"></a>00532 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
371 | <a name="l00533"></a><a class="code" href="classenorm.html#b9e1dfd33692d7b3f1a59f17b0e61bd0">00533</a> <span class="keywordtype">double</span> <a class="code" href="classenorm.html#b9e1dfd33692d7b3f1a59f17b0e61bd0" title="Compute probability of argument val.">enorm<sq_T>::eval</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
372 | <a name="l00534"></a>00534 <span class="keywordtype">double</span> pdfl,e; |
---|
373 | <a name="l00535"></a>00535 pdfl = <a class="code" href="classeEF.html#6466e8d4aa9dd64698ed288cbb1afc03" title="Evaluate normalized log-probability.">evalpdflog</a> ( val ); |
---|
374 | <a name="l00536"></a>00536 e = exp ( pdfl ); |
---|
375 | <a name="l00537"></a>00537 <span class="keywordflow">return</span> e; |
---|
376 | <a name="l00538"></a>00538 }; |
---|
377 | <a name="l00539"></a>00539 |
---|
378 | <a name="l00540"></a>00540 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
379 | <a name="l00541"></a><a class="code" href="classenorm.html#c1e3dcba256b0153cfdb286120e110be">00541</a> <span class="keywordtype">double</span> <a class="code" href="classenorm.html#c1e3dcba256b0153cfdb286120e110be" title="Evaluate normalized log-probability.">enorm<sq_T>::evalpdflog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
380 | <a name="l00542"></a>00542 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
---|
381 | <a name="l00543"></a>00543 <span class="keywordflow">return</span> -0.5* ( <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.invqform ( <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a>-val ) );<span class="comment">// - lognc();</span> |
---|
382 | <a name="l00544"></a>00544 }; |
---|
383 | <a name="l00545"></a>00545 |
---|
384 | <a name="l00546"></a>00546 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
385 | <a name="l00547"></a><a class="code" href="classenorm.html#b289a36a69db59d182bb6eba9c05d4a8">00547</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classenorm.html#b289a36a69db59d182bb6eba9c05d4a8" title="logarithm of the normalizing constant, ">enorm<sq_T>::lognc</a> ()<span class="keyword"> const </span>{ |
---|
386 | <a name="l00548"></a>00548 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
---|
387 | <a name="l00549"></a>00549 <span class="keywordflow">return</span> 0.5* ( <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.cols() * 1.83787706640935 +<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.logdet() ); |
---|
388 | <a name="l00550"></a>00550 }; |
---|
389 | <a name="l00551"></a>00551 |
---|
390 | <a name="l00552"></a>00552 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
391 | <a name="l00553"></a><a class="code" href="classmlnorm.html#3a5ad4798d8a3878c5e93b8e796c8837">00553</a> <a class="code" href="classmlnorm.html#3a5ad4798d8a3878c5e93b8e796c8837" title="Constructor.">mlnorm<sq_T>::mlnorm</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rv0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvc0 ) :<a class="code" href="classmEF.html" title="Exponential family model.">mEF</a> ( rv0,rvc0 ),<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv0 ),A ( rv0.count(),rv0.count() ),<a class="code" href="classenorm.html#0b8cb284e5af920a1b64a21d057ec5ac" title="returns a pointer to the internal mean value. Use with Care!">_mu</a> ( <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#0b8cb284e5af920a1b64a21d057ec5ac" title="returns a pointer to the internal mean value. Use with Care!">_mu</a>() ) { |
---|
392 | <a name="l00554"></a>00554 <a class="code" href="classmpdf.html#7aa894208a32f3487827df6d5054424c" title="pointer to internal epdf">ep</a> =&<a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
---|
393 | <a name="l00555"></a>00555 } |
---|
394 | <a name="l00556"></a>00556 |
---|
395 | <a name="l00557"></a>00557 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
396 | <a name="l00558"></a><a class="code" href="classmlnorm.html#f95dfce0b500636a44ecd7e5210de999">00558</a> <span class="keywordtype">void</span> <a class="code" href="classmlnorm.html#f95dfce0b500636a44ecd7e5210de999" 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 ) { |
---|
397 | <a name="l00559"></a>00559 <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ),R0 ); |
---|
398 | <a name="l00560"></a>00560 A = A0; |
---|
399 | <a name="l00561"></a>00561 mu_const = mu0; |
---|
400 | <a name="l00562"></a>00562 } |
---|
401 | <a name="l00563"></a>00563 |
---|
402 | <a name="l00564"></a>00564 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
403 | <a name="l00565"></a><a class="code" href="classmlnorm.html#1bd939dbf8ec7b8066d3f18abba6822b">00565</a> vec <a class="code" href="classmlnorm.html#1bd939dbf8ec7b8066d3f18abba6822b" title="Generate one sample of the posterior.">mlnorm<sq_T>::samplecond</a> (<span class="keyword">const</span> vec &cond, <span class="keywordtype">double</span> &lik ) { |
---|
404 | <a name="l00566"></a>00566 this-><a class="code" href="classmlnorm.html#d41126455ac64b888a38f677886e1b40" title="Set value of rvc . Result of this operation is stored in epdf use function _ep to...">condition</a> ( cond ); |
---|
405 | <a name="l00567"></a>00567 vec smp = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.sample(); |
---|
406 | <a name="l00568"></a>00568 lik = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.eval ( smp ); |
---|
407 | <a name="l00569"></a>00569 <span class="keywordflow">return</span> smp; |
---|
408 | <a name="l00570"></a>00570 } |
---|
409 | <a name="l00571"></a>00571 |
---|
410 | <a name="l00572"></a>00572 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
411 | <a name="l00573"></a><a class="code" href="classmlnorm.html#06a3600a414b4b0f006ce9440f462817">00573</a> mat <a class="code" href="classmlnorm.html#1bd939dbf8ec7b8066d3f18abba6822b" title="Generate one sample of the posterior.">mlnorm<sq_T>::samplecond</a> (<span class="keyword">const</span> vec &cond, vec &lik, <span class="keywordtype">int</span> n ) { |
---|
412 | <a name="l00574"></a>00574 <span class="keywordtype">int</span> i; |
---|
413 | <a name="l00575"></a>00575 <span class="keywordtype">int</span> dim = <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(); |
---|
414 | <a name="l00576"></a>00576 mat Smp ( dim,n ); |
---|
415 | <a name="l00577"></a>00577 vec smp ( dim ); |
---|
416 | <a name="l00578"></a>00578 this-><a class="code" href="classmlnorm.html#d41126455ac64b888a38f677886e1b40" title="Set value of rvc . Result of this operation is stored in epdf use function _ep to...">condition</a> ( cond ); |
---|
417 | <a name="l00579"></a>00579 |
---|
418 | <a name="l00580"></a>00580 <span class="keywordflow">for</span> ( i=0; i<n; i++ ) { |
---|
419 | <a name="l00581"></a>00581 smp = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.sample(); |
---|
420 | <a name="l00582"></a>00582 lik ( i ) = <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.eval ( smp ); |
---|
421 | <a name="l00583"></a>00583 Smp.set_col ( i ,smp ); |
---|
422 | <a name="l00584"></a>00584 } |
---|
423 | <a name="l00585"></a>00585 |
---|
424 | <a name="l00586"></a>00586 <span class="keywordflow">return</span> Smp; |
---|
425 | <a name="l00587"></a>00587 } |
---|
426 | <a name="l00588"></a>00588 |
---|
427 | <a name="l00589"></a>00589 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
428 | <a name="l00590"></a><a class="code" href="classmlnorm.html#d41126455ac64b888a38f677886e1b40">00590</a> <span class="keywordtype">void</span> <a class="code" href="classmlnorm.html#d41126455ac64b888a38f677886e1b40" title="Set value of rvc . Result of this operation is stored in epdf use function _ep to...">mlnorm<sq_T>::condition</a> (<span class="keyword">const</span> vec &cond ) { |
---|
429 | <a name="l00591"></a>00591 _mu = A*cond + mu_const; |
---|
430 | <a name="l00592"></a>00592 <span class="comment">//R is already assigned;</span> |
---|
431 | <a name="l00593"></a>00593 } |
---|
432 | <a name="l00594"></a>00594 |
---|
433 | <a name="l00595"></a>00595 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
434 | <a name="l00596"></a><a class="code" href="classenorm.html#14c05e1d059684b64c455ac16703b1c1">00596</a> <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classenorm.html#14c05e1d059684b64c455ac16703b1c1" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) { |
---|
435 | <a name="l00597"></a>00597 ivec irvn = rvn.<a class="code" href="classRV.html#bb724fa4e2d9ed7bfd0993b5975018a4" title="generate indeces into">dataind</a> ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
---|
436 | <a name="l00598"></a>00598 |
---|
437 | <a name="l00599"></a>00599 sq_T Rn ( <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>,irvn ); |
---|
438 | <a name="l00600"></a>00600 <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* tmp = <span class="keyword">new</span> <a class="code" href="classenorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>( rvn ); |
---|
439 | <a name="l00601"></a>00601 tmp-><a class="code" href="classenorm.html#1394a65caa6e00d42e00cc99b12227af" title="Set mean value mu and covariance R.">set_parameters</a> ( <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a> ( irvn ), Rn ); |
---|
440 | <a name="l00602"></a>00602 <span class="keywordflow">return</span> tmp; |
---|
441 | <a name="l00603"></a>00603 } |
---|
442 | <a name="l00604"></a>00604 |
---|
443 | <a name="l00605"></a>00605 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
444 | <a name="l00606"></a><a class="code" href="classenorm.html#13b7d503c6444eb4db4f359b13ec3bc2">00606</a> <a class="code" href="classmlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a>* <a class="code" href="classenorm.html#13b7d503c6444eb4db4f359b13ec3bc2" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) { |
---|
445 | <a name="l00607"></a>00607 |
---|
446 | <a name="l00608"></a>00608 <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> rvc = <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#b9d175c327c21488b1e2fb756a84e149" title="Subtract another variable from the current one.">subt</a> ( rvn ); |
---|
447 | <a name="l00609"></a>00609 it_assert_debug ( ( rvc.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() +rvn.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ==<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ),<span class="stringliteral">"wrong rvn"</span> ); |
---|
448 | <a name="l00610"></a>00610 <span class="comment">//Permutation vector of the new R</span> |
---|
449 | <a name="l00611"></a>00611 ivec irvn = rvn.<a class="code" href="classRV.html#bb724fa4e2d9ed7bfd0993b5975018a4" title="generate indeces into">dataind</a> ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
---|
450 | <a name="l00612"></a>00612 ivec irvc = rvc.<a class="code" href="classRV.html#bb724fa4e2d9ed7bfd0993b5975018a4" title="generate indeces into">dataind</a> ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
---|
451 | <a name="l00613"></a>00613 ivec perm=concat ( irvn , irvc ); |
---|
452 | <a name="l00614"></a>00614 sq_T Rn ( <a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>,perm ); |
---|
453 | <a name="l00615"></a>00615 |
---|
454 | <a name="l00616"></a>00616 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
---|
455 | <a name="l00617"></a>00617 mat S=<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.to_mat(); |
---|
456 | <a name="l00618"></a>00618 <span class="comment">//fixme</span> |
---|
457 | <a name="l00619"></a>00619 <span class="keywordtype">int</span> n=rvn.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>()-1; |
---|
458 | <a name="l00620"></a>00620 <span class="keywordtype">int</span> end=<a class="code" href="classenorm.html#4ccc8d8514d644ef1c98d8ab023748a1" title="Covariance matrix in decomposed form.">R</a>.rows()-1; |
---|
459 | <a name="l00621"></a>00621 mat S11 = S.get ( 0,n, 0, n ); |
---|
460 | <a name="l00622"></a>00622 mat S12 = S.get ( rvn.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(), end, 0, n ); |
---|
461 | <a name="l00623"></a>00623 mat S22 = S.get ( rvn.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(), end, rvn.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(), end ); |
---|
462 | <a name="l00624"></a>00624 |
---|
463 | <a name="l00625"></a>00625 vec mu1 = <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a> ( irvn ); |
---|
464 | <a name="l00626"></a>00626 vec mu2 = <a class="code" href="classenorm.html#71fde0d54bba147e00f612577f95ad20" title="mean value">mu</a> ( irvc ); |
---|
465 | <a name="l00627"></a>00627 mat A=S12*inv ( S22 ); |
---|
466 | <a name="l00628"></a>00628 sq_T R_n ( S11 - A *S12.T() ); |
---|
467 | <a name="l00629"></a>00629 |
---|
468 | <a name="l00630"></a>00630 <a class="code" href="classmlnorm.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="classmlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a> ( rvn,rvc ); |
---|
469 | <a name="l00631"></a>00631 |
---|
470 | <a name="l00632"></a>00632 tmp->set_parameters ( A,mu1-A*mu2,R_n ); |
---|
471 | <a name="l00633"></a>00633 <span class="keywordflow">return</span> tmp; |
---|
472 | <a name="l00634"></a>00634 } |
---|
473 | <a name="l00635"></a>00635 |
---|
474 | <a name="l00637"></a>00637 |
---|
475 | <a name="l00638"></a>00638 |
---|
476 | <a name="l00639"></a>00639 <span class="preprocessor">#endif //EF_H</span> |
---|
477 | </pre></div></div> |
---|
478 | <hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 15 15:57:09 2008 for mixpp by |
---|
479 | <a href="http://www.doxygen.org/index.html"> |
---|
480 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> |
---|
481 | </body> |
---|
482 | </html> |
---|