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: exp_family.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>exp_family.h</h1><a href="exp__family_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef EF_H</span> |
---|
67 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define EF_H</span> |
---|
68 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
69 | <a name="l00016"></a>00016 |
---|
70 | <a name="l00017"></a>00017 <span class="preprocessor">#include "../base/bdmbase.h"</span> |
---|
71 | <a name="l00018"></a>00018 <span class="preprocessor">#include "../math/chmat.h"</span> |
---|
72 | <a name="l00019"></a>00019 |
---|
73 | <a name="l00020"></a>00020 <span class="keyword">namespace </span>bdm |
---|
74 | <a name="l00021"></a>00021 { |
---|
75 | <a name="l00022"></a>00022 |
---|
76 | <a name="l00023"></a>00023 |
---|
77 | <a name="l00025"></a>00025 <span class="keyword">extern</span> Uniform_RNG UniRNG; |
---|
78 | <a name="l00027"></a>00027 <span class="keyword">extern</span> Normal_RNG NorRNG; |
---|
79 | <a name="l00029"></a>00029 <span class="keyword">extern</span> Gamma_RNG GamRNG; |
---|
80 | <a name="l00030"></a>00030 |
---|
81 | <a name="l00037"></a><a class="code" href="classbdm_1_1eEF.html">00037</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
---|
82 | <a name="l00038"></a>00038 { |
---|
83 | <a name="l00039"></a>00039 <span class="keyword">public</span>: |
---|
84 | <a name="l00040"></a>00040 <span class="comment">// eEF() :epdf() {};</span> |
---|
85 | <a name="l00042"></a><a class="code" href="classbdm_1_1eEF.html#d5459d472d0feca7cf1fb5f65c4b9ef4">00042</a> <span class="comment"></span> <a class="code" href="classbdm_1_1eEF.html#d5459d472d0feca7cf1fb5f65c4b9ef4" title="default constructor">eEF</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ) {}; |
---|
86 | <a name="l00044"></a>00044 <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEF.html#cd678fc9b02007a4b8d6692e746f1bf8" title="logarithm of the normalizing constant, ">lognc</a>() <span class="keyword">const</span> =0; |
---|
87 | <a name="l00046"></a><a class="code" href="classbdm_1_1eEF.html#deef7d6273ba4d5a5cf0bbd91ec7277a">00046</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEF.html#deef7d6273ba4d5a5cf0bbd91ec7277a" title="TODO decide if it is really needed.">dupdate</a> ( mat &v ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
88 | <a name="l00048"></a><a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6">00048</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6" title="Evaluate normalized log-probability.">evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const</span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0.0;}; |
---|
89 | <a name="l00050"></a><a class="code" href="classbdm_1_1eEF.html#a36d06ecdd6f4c79dc122510eaccc692">00050</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEF.html#a36d06ecdd6f4c79dc122510eaccc692" title="Evaluate normalized log-probability.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
90 | <a name="l00051"></a>00051 <span class="keywordtype">double</span> tmp; |
---|
91 | <a name="l00052"></a>00052 tmp= <a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6" title="Evaluate normalized log-probability.">evallog_nn</a> ( val )-<a class="code" href="classbdm_1_1eEF.html#cd678fc9b02007a4b8d6692e746f1bf8" title="logarithm of the normalizing constant, ">lognc</a>(); |
---|
92 | <a name="l00053"></a>00053 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
---|
93 | <a name="l00054"></a>00054 <span class="keywordflow">return</span> tmp;} |
---|
94 | <a name="l00056"></a><a class="code" href="classbdm_1_1eEF.html#79a7c8ea8c02e45d410bd1d7ffd72b41">00056</a> <span class="keyword">virtual</span> vec <a class="code" href="classbdm_1_1eEF.html#a36d06ecdd6f4c79dc122510eaccc692" title="Evaluate normalized log-probability.">evallog</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const</span> |
---|
95 | <a name="l00057"></a>00057 <span class="keyword"> </span>{ |
---|
96 | <a name="l00058"></a>00058 vec x ( Val.cols() ); |
---|
97 | <a name="l00059"></a>00059 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<Val.cols();i++ ) {x ( i ) =<a class="code" href="classbdm_1_1eEF.html#a4135778ecd9ab774762936c82a097c6" title="Evaluate normalized log-probability.">evallog_nn</a> ( Val.get_col ( i ) ) ;} |
---|
98 | <a name="l00060"></a>00060 <span class="keywordflow">return</span> x-<a class="code" href="classbdm_1_1eEF.html#cd678fc9b02007a4b8d6692e746f1bf8" title="logarithm of the normalizing constant, ">lognc</a>(); |
---|
99 | <a name="l00061"></a>00061 } |
---|
100 | <a name="l00063"></a><a class="code" href="classbdm_1_1eEF.html#cf38af29e8e3d650c640509a52396053">00063</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEF.html#cf38af29e8e3d650c640509a52396053" title="Power of the density, used e.g. to flatten the density.">pow</a> ( <span class="keywordtype">double</span> p ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
101 | <a name="l00064"></a>00064 }; |
---|
102 | <a name="l00065"></a>00065 |
---|
103 | <a name="l00072"></a><a class="code" href="classbdm_1_1mEF.html">00072</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> |
---|
104 | <a name="l00073"></a>00073 { |
---|
105 | <a name="l00074"></a>00074 |
---|
106 | <a name="l00075"></a>00075 <span class="keyword">public</span>: |
---|
107 | <a name="l00077"></a><a class="code" href="classbdm_1_1mEF.html#dd7caad7026b778af66e34480eec6f9e">00077</a> <a class="code" href="classbdm_1_1mEF.html#dd7caad7026b778af66e34480eec6f9e" title="Default constructor.">mEF</a> ( ) :<a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( ) {}; |
---|
108 | <a name="l00078"></a>00078 }; |
---|
109 | <a name="l00079"></a>00079 |
---|
110 | <a name="l00081"></a><a class="code" href="classbdm_1_1BMEF.html">00081</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a> |
---|
111 | <a name="l00082"></a>00082 { |
---|
112 | <a name="l00083"></a>00083 <span class="keyword">protected</span>: |
---|
113 | <a name="l00085"></a><a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64">00085</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>; |
---|
114 | <a name="l00087"></a><a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865">00087</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>; |
---|
115 | <a name="l00088"></a>00088 <span class="keyword">public</span>: |
---|
116 | <a name="l00090"></a><a class="code" href="classbdm_1_1BMEF.html#2def512872ed8a4fc3b702371ec0be55">00090</a> <a class="code" href="classbdm_1_1BMEF.html#2def512872ed8a4fc3b702371ec0be55" title="Default constructor (=empty constructor).">BMEF</a> ( <span class="keywordtype">double</span> frg0=1.0 ) :<a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a> ( ), <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> ( frg0 ) {} |
---|
117 | <a name="l00092"></a><a class="code" href="classbdm_1_1BMEF.html#9662379513101405e159e76717104e62">00092</a> <a class="code" href="classbdm_1_1BMEF.html#9662379513101405e159e76717104e62" title="Copy constructor.">BMEF</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> &B ) :<a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a> ( B ), <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> ( B.<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> ), <a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> ( B.<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> ) {} |
---|
118 | <a name="l00094"></a><a class="code" href="classbdm_1_1BMEF.html#d2b528b7a41ca67163152142f5404051">00094</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#d2b528b7a41ca67163152142f5404051" title="get statistics from another model">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* BM0 ) {it_error ( <span class="stringliteral">"Not implemented"</span> );}; |
---|
119 | <a name="l00096"></a><a class="code" href="classbdm_1_1BMEF.html#bf58deb99af2a6cc674f13ff90300de6">00096</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#bf58deb99af2a6cc674f13ff90300de6" title="Weighted update of sufficient statistics (Bayes rule).">bayes</a> ( <span class="keyword">const</span> vec &data, <span class="keyword">const</span> <span class="keywordtype">double</span> w ) {}; |
---|
120 | <a name="l00097"></a>00097 <span class="comment">//original Bayes</span> |
---|
121 | <a name="l00098"></a>00098 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#bf58deb99af2a6cc674f13ff90300de6" title="Weighted update of sufficient statistics (Bayes rule).">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
---|
122 | <a name="l00100"></a><a class="code" href="classbdm_1_1BMEF.html#b2916a2e71a958665054473124d5e749">00100</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1BMEF.html#b2916a2e71a958665054473124d5e749" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> * B ) {it_error ( <span class="stringliteral">"Not implemented"</span> );} |
---|
123 | <a name="l00102"></a>00102 <span class="comment">// virtual void flatten ( double nu0 ) {it_error ( "Not implemented" );}</span> |
---|
124 | <a name="l00103"></a>00103 |
---|
125 | <a name="l00104"></a><a class="code" href="classbdm_1_1BMEF.html#62d2e4691bed41a1efa6b9c2e35e5c67">00104</a> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* <a class="code" href="classbdm_1_1BMEF.html#62d2e4691bed41a1efa6b9c2e35e5c67" title="Flatten the posterior as if to keep nu0 data.">_copy_</a> ()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"function _copy_ not implemented for this BM"</span> ); <span class="keywordflow">return</span> NULL;}; |
---|
126 | <a name="l00105"></a>00105 }; |
---|
127 | <a name="l00106"></a>00106 |
---|
128 | <a name="l00107"></a>00107 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
129 | <a name="l00108"></a>00108 <span class="keyword">class </span>mlnorm; |
---|
130 | <a name="l00109"></a>00109 |
---|
131 | <a name="l00115"></a>00115 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
132 | <a name="l00116"></a><a class="code" href="classbdm_1_1enorm.html">00116</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
---|
133 | <a name="l00117"></a>00117 { |
---|
134 | <a name="l00118"></a>00118 <span class="keyword">protected</span>: |
---|
135 | <a name="l00120"></a><a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7">00120</a> vec <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
---|
136 | <a name="l00122"></a><a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2">00122</a> sq_T <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>; |
---|
137 | <a name="l00123"></a>00123 <span class="keyword">public</span>: |
---|
138 | <a name="l00126"></a>00126 |
---|
139 | <a name="l00127"></a>00127 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> ( ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( ),<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> ( ) {}; |
---|
140 | <a name="l00128"></a>00128 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a> ( <span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>,<span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> ) {set_parameters ( mu,R );} |
---|
141 | <a name="l00129"></a>00129 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>,<span class="keyword">const</span> sq_T &<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a> ); |
---|
142 | <a name="l00130"></a>00130 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">from_setting</a>(<span class="keyword">const</span> Setting &root); |
---|
143 | <a name="l00131"></a><a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea">00131</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea" title="This method TODO.">validate</a>() { |
---|
144 | <a name="l00132"></a>00132 it_assert(<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>.length()==<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows(),<span class="stringliteral">"parameters mismatch"</span>); |
---|
145 | <a name="l00133"></a>00133 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>.length(); |
---|
146 | <a name="l00134"></a>00134 } |
---|
147 | <a name="l00136"></a>00136 |
---|
148 | <a name="l00139"></a>00139 |
---|
149 | <a name="l00141"></a>00141 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">dupdate</a> ( mat &v,<span class="keywordtype">double</span> nu=1.0 ); |
---|
150 | <a name="l00142"></a>00142 |
---|
151 | <a name="l00143"></a>00143 vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
152 | <a name="l00144"></a>00144 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a> ( <span class="keywordtype">int</span> N ) <span class="keyword">const</span>; |
---|
153 | <a name="l00145"></a>00145 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
154 | <a name="l00146"></a>00146 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
155 | <a name="l00147"></a><a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600">00147</a> vec <a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
---|
156 | <a name="l00148"></a><a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773">00148</a> vec <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> diag ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.to_mat() );} |
---|
157 | <a name="l00149"></a>00149 <span class="comment">// mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why?</span> |
---|
158 | <a name="l00150"></a>00150 <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span> ; |
---|
159 | <a name="l00151"></a>00151 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ) <span class="keyword">const</span>; |
---|
160 | <a name="l00152"></a>00152 <span class="comment">// epdf* marginal ( const RV &rv ) const;</span> |
---|
161 | <a name="l00154"></a>00154 <span class="comment"></span> |
---|
162 | <a name="l00157"></a>00157 |
---|
163 | <a name="l00158"></a>00158 vec& _mu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
---|
164 | <a name="l00159"></a>00159 <span class="keywordtype">void</span> set_mu ( <span class="keyword">const</span> vec mu0 ) { <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>=mu0;} |
---|
165 | <a name="l00160"></a>00160 sq_T& _R() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
---|
166 | <a name="l00161"></a>00161 <span class="keyword">const</span> sq_T& _R()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
---|
167 | <a name="l00163"></a>00163 |
---|
168 | <a name="l00164"></a>00164 }; |
---|
169 | <a name="l00165"></a>00165 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(enorm<chmat>); |
---|
170 | <a name="l00166"></a>00166 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(enorm<ldmat>); |
---|
171 | <a name="l00167"></a>00167 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(enorm<fsqmat>); |
---|
172 | <a name="l00168"></a>00168 |
---|
173 | <a name="l00169"></a>00169 |
---|
174 | <a name="l00176"></a><a class="code" href="classbdm_1_1egiw.html">00176</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
---|
175 | <a name="l00177"></a>00177 { |
---|
176 | <a name="l00178"></a>00178 <span class="keyword">protected</span>: |
---|
177 | <a name="l00180"></a><a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52">00180</a> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>; |
---|
178 | <a name="l00182"></a><a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4">00182</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>; |
---|
179 | <a name="l00184"></a><a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a">00184</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
---|
180 | <a name="l00186"></a><a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd">00186</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a>; |
---|
181 | <a name="l00187"></a>00187 <span class="keyword">public</span>: |
---|
182 | <a name="l00190"></a>00190 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a>() :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {}; |
---|
183 | <a name="l00191"></a>00191 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {set_parameters ( dimx0,V0, nu0 );}; |
---|
184 | <a name="l00192"></a>00192 |
---|
185 | <a name="l00193"></a>00193 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) |
---|
186 | <a name="l00194"></a>00194 { |
---|
187 | <a name="l00195"></a>00195 <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>=dimx0; |
---|
188 | <a name="l00196"></a>00196 <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> = V0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>()-<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
---|
189 | <a name="l00197"></a>00197 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>* ( <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>+<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> ); <span class="comment">// size(R) + size(Theta)</span> |
---|
190 | <a name="l00198"></a>00198 |
---|
191 | <a name="l00199"></a>00199 <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>=V0; |
---|
192 | <a name="l00200"></a>00200 <span class="keywordflow">if</span> ( nu0<0 ) |
---|
193 | <a name="l00201"></a>00201 { |
---|
194 | <a name="l00202"></a>00202 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> = 0.1 +<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> +2*<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> +2; <span class="comment">// +2 assures finite expected value of R</span> |
---|
195 | <a name="l00203"></a>00203 <span class="comment">// terms before that are sufficient for finite normalization</span> |
---|
196 | <a name="l00204"></a>00204 } |
---|
197 | <a name="l00205"></a>00205 <span class="keywordflow">else</span> |
---|
198 | <a name="l00206"></a>00206 { |
---|
199 | <a name="l00207"></a>00207 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>=nu0; |
---|
200 | <a name="l00208"></a>00208 } |
---|
201 | <a name="l00209"></a>00209 } |
---|
202 | <a name="l00211"></a>00211 |
---|
203 | <a name="l00212"></a>00212 vec <a class="code" href="classbdm_1_1egiw.html#920f21548b7a3723923dd108fe514c61" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
204 | <a name="l00213"></a>00213 vec <a class="code" href="classbdm_1_1egiw.html#df70c05f918c3a6f86d60f10c1fd6ba2" title="return expected value">mean</a>() <span class="keyword">const</span>; |
---|
205 | <a name="l00214"></a>00214 vec <a class="code" href="classbdm_1_1egiw.html#c1ecc406613cc2341225dc10c3d3b46a" title="return expected variance (not covariance!)">variance</a>() <span class="keyword">const</span>; |
---|
206 | <a name="l00215"></a>00215 |
---|
207 | <a name="l00217"></a>00217 vec <a class="code" href="classbdm_1_1egiw.html#66d2ba9295c306012b309efcc9e516f0" title="LS estimate of .">est_theta</a>() <span class="keyword">const</span>; |
---|
208 | <a name="l00218"></a>00218 |
---|
209 | <a name="l00220"></a>00220 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1egiw.html#88c321a2051d1afdbb31a098896a717b" title="Covariance of the LS estimate.">est_theta_cov</a>() <span class="keyword">const</span>; |
---|
210 | <a name="l00221"></a>00221 |
---|
211 | <a name="l00222"></a>00222 <span class="keywordtype">void</span> mean_mat ( mat &M, mat&R ) <span class="keyword">const</span>; |
---|
212 | <a name="l00224"></a>00224 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#bfb8e7c619b34ad804a73bff71742b5e" title="In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise...">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
213 | <a name="l00225"></a>00225 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#41d72ba7b2abc8a9a4209ffa98ed5633" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
214 | <a name="l00226"></a><a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be">00226</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be" title="Power of the density, used e.g. to flatten the density.">pow</a> ( <span class="keywordtype">double</span> p ) {V*=p;<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>*=p;}; |
---|
215 | <a name="l00227"></a>00227 |
---|
216 | <a name="l00230"></a>00230 |
---|
217 | <a name="l00231"></a>00231 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V() {<span class="keywordflow">return</span> V;} |
---|
218 | <a name="l00232"></a>00232 <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V()<span class="keyword"> const </span>{<span class="keywordflow">return</span> V;} |
---|
219 | <a name="l00233"></a>00233 <span class="keywordtype">double</span>& _nu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
---|
220 | <a name="l00234"></a>00234 <span class="keyword">const</span> <span class="keywordtype">double</span>& _nu()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
---|
221 | <a name="l00235"></a><a class="code" href="classbdm_1_1egiw.html#55b76ec75bd2df5ef9cab3be20a33bbb">00235</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#55b76ec75bd2df5ef9cab3be20a33bbb">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
---|
222 | <a name="l00236"></a>00236 <span class="keyword">set</span>.lookupValue(<span class="stringliteral">"nu"</span>,<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>); |
---|
223 | <a name="l00237"></a>00237 <span class="keyword">set</span>.lookupValue(<span class="stringliteral">"dimx"</span>,<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>); |
---|
224 | <a name="l00238"></a>00238 mat V; |
---|
225 | <a name="l00239"></a>00239 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(V,<span class="keyword">set</span>,<span class="stringliteral">"V"</span>); |
---|
226 | <a name="l00240"></a>00240 set_parameters(<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>, V, <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>); |
---|
227 | <a name="l00241"></a>00241 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a>* <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>=UI::build<RV>(<span class="keyword">set</span>,<span class="stringliteral">"rv"</span>); |
---|
228 | <a name="l00242"></a>00242 <a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a>(*rv); |
---|
229 | <a name="l00243"></a>00243 <span class="keyword">delete</span> rv; |
---|
230 | <a name="l00244"></a>00244 } |
---|
231 | <a name="l00246"></a>00246 }; |
---|
232 | <a name="l00247"></a>00247 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(egiw); |
---|
233 | <a name="l00248"></a>00248 |
---|
234 | <a name="l00257"></a><a class="code" href="classbdm_1_1eDirich.html">00257</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
---|
235 | <a name="l00258"></a>00258 { |
---|
236 | <a name="l00259"></a>00259 <span class="keyword">protected</span>: |
---|
237 | <a name="l00261"></a><a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2">00261</a> vec <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>; |
---|
238 | <a name="l00262"></a>00262 <span class="keyword">public</span>: |
---|
239 | <a name="l00265"></a>00265 |
---|
240 | <a name="l00266"></a>00266 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ) {}; |
---|
241 | <a name="l00267"></a>00267 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> &D0 ) : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {set_parameters ( D0.<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> );}; |
---|
242 | <a name="l00268"></a>00268 eDirich ( <span class="keyword">const</span> vec &beta0 ) {set_parameters ( beta0 );}; |
---|
243 | <a name="l00269"></a>00269 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) |
---|
244 | <a name="l00270"></a>00270 { |
---|
245 | <a name="l00271"></a>00271 <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>= beta0; |
---|
246 | <a name="l00272"></a>00272 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length(); |
---|
247 | <a name="l00273"></a>00273 } |
---|
248 | <a name="l00275"></a>00275 |
---|
249 | <a name="l00276"></a><a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc">00276</a> vec <a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> vec_1 ( 0.0 );}; |
---|
250 | <a name="l00277"></a><a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6">00277</a> vec <a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>/sum(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
---|
251 | <a name="l00278"></a><a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc">00278</a> vec <a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordtype">double</span> gamma =sum(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); <span class="keywordflow">return</span> elem_mult ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>, ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>+1 ) ) / ( gamma* ( gamma+1 ) );} |
---|
252 | <a name="l00280"></a><a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318">00280</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318" title="In this instance, val is ...">evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const</span> |
---|
253 | <a name="l00281"></a>00281 <span class="keyword"> </span>{ |
---|
254 | <a name="l00282"></a>00282 <span class="keywordtype">double</span> tmp; tmp= ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>-1 ) *log ( val ); it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
---|
255 | <a name="l00283"></a>00283 <span class="keywordflow">return</span> tmp; |
---|
256 | <a name="l00284"></a>00284 }; |
---|
257 | <a name="l00285"></a><a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2">00285</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const</span> |
---|
258 | <a name="l00286"></a>00286 <span class="keyword"> </span>{ |
---|
259 | <a name="l00287"></a>00287 <span class="keywordtype">double</span> tmp; |
---|
260 | <a name="l00288"></a>00288 <span class="keywordtype">double</span> gam=sum ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ); |
---|
261 | <a name="l00289"></a>00289 <span class="keywordtype">double</span> lgb=0.0; |
---|
262 | <a name="l00290"></a>00290 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length();i++ ) {lgb+=lgamma ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ( i ) );} |
---|
263 | <a name="l00291"></a>00291 tmp= lgb-lgamma ( gam ); |
---|
264 | <a name="l00292"></a>00292 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
---|
265 | <a name="l00293"></a>00293 <span class="keywordflow">return</span> tmp; |
---|
266 | <a name="l00294"></a>00294 }; |
---|
267 | <a name="l00296"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00296</a> vec& <a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>;} |
---|
268 | <a name="l00298"></a>00298 }; |
---|
269 | <a name="l00299"></a>00299 |
---|
270 | <a name="l00301"></a><a class="code" href="classbdm_1_1multiBM.html">00301</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> |
---|
271 | <a name="l00302"></a>00302 { |
---|
272 | <a name="l00303"></a>00303 <span class="keyword">protected</span>: |
---|
273 | <a name="l00305"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00305</a> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>; |
---|
274 | <a name="l00307"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00307</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
---|
275 | <a name="l00308"></a>00308 <span class="keyword">public</span>: |
---|
276 | <a name="l00310"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00310</a> <a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf" title="Default constructor.">multiBM</a> ( ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( ),<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ( ),<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta() ) |
---|
277 | <a name="l00311"></a>00311 { |
---|
278 | <a name="l00312"></a>00312 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>.length() >0 ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
279 | <a name="l00313"></a>00313 <span class="keywordflow">else</span>{<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=0.0;} |
---|
280 | <a name="l00314"></a>00314 } |
---|
281 | <a name="l00316"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00316</a> <a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31" title="Copy constructor.">multiBM</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> &B ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( B ),<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ( B.<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ),<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta() ) {} |
---|
282 | <a name="l00318"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00318</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52" title="Sets sufficient statistics to match that of givefrom mB0.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* mB0 ) {<span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* mB=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> ( mB0 ); <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>=mB-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;} |
---|
283 | <a name="l00319"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00319</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ) |
---|
284 | <a name="l00320"></a>00320 { |
---|
285 | <a name="l00321"></a>00321 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) {<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>*=<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
286 | <a name="l00322"></a>00322 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>+=dt; |
---|
287 | <a name="l00323"></a>00323 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BM.html#4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
---|
288 | <a name="l00324"></a>00324 } |
---|
289 | <a name="l00325"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00325</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">logpred</a> ( <span class="keyword">const</span> vec &dt )<span class="keyword"> const</span> |
---|
290 | <a name="l00326"></a>00326 <span class="keyword"> </span>{ |
---|
291 | <a name="l00327"></a>00327 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> pred ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ); |
---|
292 | <a name="l00328"></a>00328 vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = pred.<a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>(); |
---|
293 | <a name="l00329"></a>00329 |
---|
294 | <a name="l00330"></a>00330 <span class="keywordtype">double</span> lll; |
---|
295 | <a name="l00331"></a>00331 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) |
---|
296 | <a name="l00332"></a>00332 {beta*=<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
297 | <a name="l00333"></a>00333 <span class="keywordflow">else</span> |
---|
298 | <a name="l00334"></a>00334 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {lll=<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
---|
299 | <a name="l00335"></a>00335 <span class="keywordflow">else</span>{lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
300 | <a name="l00336"></a>00336 |
---|
301 | <a name="l00337"></a>00337 beta+=dt; |
---|
302 | <a name="l00338"></a>00338 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-lll; |
---|
303 | <a name="l00339"></a>00339 } |
---|
304 | <a name="l00340"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00340</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* B ) |
---|
305 | <a name="l00341"></a>00341 { |
---|
306 | <a name="l00342"></a>00342 <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* E=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> ( B ); |
---|
307 | <a name="l00343"></a>00343 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
---|
308 | <a name="l00344"></a>00344 <span class="keyword">const</span> vec &Eb=E-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;<span class="comment">//const_cast<multiBM*> ( E )->_beta();</span> |
---|
309 | <a name="l00345"></a>00345 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>*= ( sum ( Eb ) /sum ( <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ) ); |
---|
310 | <a name="l00346"></a>00346 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
---|
311 | <a name="l00347"></a>00347 } |
---|
312 | <a name="l00348"></a>00348 <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& posterior()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
---|
313 | <a name="l00349"></a>00349 <span class="keyword">const</span> eDirich* _e()<span class="keyword"> const </span>{<span class="keywordflow">return</span> &<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
---|
314 | <a name="l00350"></a>00350 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) |
---|
315 | <a name="l00351"></a>00351 { |
---|
316 | <a name="l00352"></a>00352 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters ( beta0 ); |
---|
317 | <a name="l00353"></a>00353 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.lognc();} |
---|
318 | <a name="l00354"></a>00354 } |
---|
319 | <a name="l00355"></a>00355 }; |
---|
320 | <a name="l00356"></a>00356 |
---|
321 | <a name="l00366"></a><a class="code" href="classbdm_1_1egamma.html">00366</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
---|
322 | <a name="l00367"></a>00367 { |
---|
323 | <a name="l00368"></a>00368 <span class="keyword">protected</span>: |
---|
324 | <a name="l00370"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00370</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
---|
325 | <a name="l00372"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00372</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
---|
326 | <a name="l00373"></a>00373 <span class="keyword">public</span> : |
---|
327 | <a name="l00376"></a>00376 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> ( ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> ( 0 ), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> ( 0 ) {}; |
---|
328 | <a name="l00377"></a>00377 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ) {set_parameters ( a, b );}; |
---|
329 | <a name="l00378"></a>00378 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ) {<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>=a,<a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>=b;<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length();}; |
---|
330 | <a name="l00380"></a>00380 |
---|
331 | <a name="l00381"></a>00381 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
332 | <a name="l00383"></a>00383 <span class="comment">// mat sample ( int N ) const;</span> |
---|
333 | <a name="l00384"></a>00384 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="TODO: is it used anywhere?">evallog</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
---|
334 | <a name="l00385"></a>00385 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
---|
335 | <a name="l00387"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00387</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns poiter to alpha and beta. Potentially dengerous: use with care!">_alpha</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>;} |
---|
336 | <a name="l00388"></a>00388 vec& _beta() {<span class="keywordflow">return</span> beta;} |
---|
337 | <a name="l00389"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00389</a> vec <a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>,beta );} |
---|
338 | <a name="l00390"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00390</a> vec <a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>,elem_mult ( beta,beta ) ); } |
---|
339 | <a name="l00391"></a>00391 |
---|
340 | <a name="l00400"></a><a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">00400</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
---|
341 | <a name="l00401"></a>00401 <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">epdf::from_setting</a>(<span class="keyword">set</span>); <span class="comment">// reads rv</span> |
---|
342 | <a name="l00402"></a>00402 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>,<span class="keyword">set</span>,<span class="stringliteral">"alpha"</span>); |
---|
343 | <a name="l00403"></a>00403 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(beta,<span class="keyword">set</span>,<span class="stringliteral">"beta"</span>); |
---|
344 | <a name="l00404"></a>00404 <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>(); |
---|
345 | <a name="l00405"></a>00405 } |
---|
346 | <a name="l00406"></a><a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127">00406</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>(){ |
---|
347 | <a name="l00407"></a>00407 it_assert(<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length() ==beta.length(), <span class="stringliteral">"parameters do not match"</span>); |
---|
348 | <a name="l00408"></a>00408 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> =<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length(); |
---|
349 | <a name="l00409"></a>00409 } |
---|
350 | <a name="l00410"></a>00410 }; |
---|
351 | <a name="l00411"></a>00411 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(egamma); |
---|
352 | <a name="l00428"></a><a class="code" href="classbdm_1_1eigamma.html">00428</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> |
---|
353 | <a name="l00429"></a>00429 { |
---|
354 | <a name="l00430"></a>00430 <span class="keyword">protected</span>: |
---|
355 | <a name="l00431"></a>00431 <span class="keyword">public</span> : |
---|
356 | <a name="l00436"></a>00436 |
---|
357 | <a name="l00437"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00437</a> vec <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1.0/<a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">egamma::sample</a>();}; |
---|
358 | <a name="l00439"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00439</a> vec <a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>,<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-1 );} |
---|
359 | <a name="l00440"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00440</a> vec <a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{vec mea=<a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>(); <span class="keywordflow">return</span> elem_div ( elem_mult ( mea,mea ),<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-2 );} |
---|
360 | <a name="l00441"></a>00441 }; |
---|
361 | <a name="l00442"></a>00442 <span class="comment">/*</span> |
---|
362 | <a name="l00444"></a>00444 <span class="comment"> class emix : public epdf {</span> |
---|
363 | <a name="l00445"></a>00445 <span class="comment"> protected:</span> |
---|
364 | <a name="l00446"></a>00446 <span class="comment"> int n;</span> |
---|
365 | <a name="l00447"></a>00447 <span class="comment"> vec &w;</span> |
---|
366 | <a name="l00448"></a>00448 <span class="comment"> Array<epdf*> Coms;</span> |
---|
367 | <a name="l00449"></a>00449 <span class="comment"> public:</span> |
---|
368 | <a name="l00451"></a>00451 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
---|
369 | <a name="l00452"></a>00452 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
---|
370 | <a name="l00453"></a>00453 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
---|
371 | <a name="l00454"></a>00454 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
---|
372 | <a name="l00455"></a>00455 <span class="comment"> };</span> |
---|
373 | <a name="l00456"></a>00456 <span class="comment"> */</span> |
---|
374 | <a name="l00457"></a>00457 |
---|
375 | <a name="l00459"></a>00459 |
---|
376 | <a name="l00460"></a><a class="code" href="classbdm_1_1euni.html">00460</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
---|
377 | <a name="l00461"></a>00461 { |
---|
378 | <a name="l00462"></a>00462 <span class="keyword">protected</span>: |
---|
379 | <a name="l00464"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00464</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
---|
380 | <a name="l00466"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00466</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
---|
381 | <a name="l00468"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00468</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
---|
382 | <a name="l00470"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00470</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
---|
383 | <a name="l00472"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00472</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
---|
384 | <a name="l00473"></a>00473 <span class="keyword">public</span>: |
---|
385 | <a name="l00476"></a>00476 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ) {} |
---|
386 | <a name="l00477"></a>00477 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) {set_parameters ( low0,high0 );} |
---|
387 | <a name="l00478"></a>00478 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) |
---|
388 | <a name="l00479"></a>00479 { |
---|
389 | <a name="l00480"></a>00480 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0-low0; |
---|
390 | <a name="l00481"></a>00481 it_assert_debug ( min ( <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> ) >0.0,<span class="stringliteral">"bad support"</span> ); |
---|
391 | <a name="l00482"></a>00482 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
---|
392 | <a name="l00483"></a>00483 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
---|
393 | <a name="l00484"></a>00484 <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> = prod ( 1.0/<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> ); |
---|
394 | <a name="l00485"></a>00485 <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a> = log ( <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> ); |
---|
395 | <a name="l00486"></a>00486 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(); |
---|
396 | <a name="l00487"></a>00487 } |
---|
397 | <a name="l00489"></a>00489 |
---|
398 | <a name="l00490"></a>00490 <span class="keywordtype">double</span> eval ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>;} |
---|
399 | <a name="l00491"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00491</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>;} |
---|
400 | <a name="l00492"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00492</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const</span> |
---|
401 | <a name="l00493"></a>00493 <span class="keyword"> </span>{ |
---|
402 | <a name="l00494"></a>00494 vec smp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
403 | <a name="l00495"></a>00495 <span class="preprocessor">#pragma omp critical</span> |
---|
404 | <a name="l00496"></a>00496 <span class="preprocessor"></span> UniRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ,smp ); |
---|
405 | <a name="l00497"></a>00497 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>+elem_mult ( <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>,smp ); |
---|
406 | <a name="l00498"></a>00498 } |
---|
407 | <a name="l00500"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00500</a> vec <a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226" title="set values of low and high ">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>-<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> ) /2.0;} |
---|
408 | <a name="l00501"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00501</a> vec <a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> ( pow ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>,2 ) +pow ( <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>,2 ) +elem_mult ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>,<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> ) ) /3.0;} |
---|
409 | <a name="l00510"></a><a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">00510</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
---|
410 | <a name="l00511"></a>00511 <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">epdf::from_setting</a>(<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
---|
411 | <a name="l00512"></a>00512 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>,<span class="keyword">set</span>,<span class="stringliteral">"high"</span>); |
---|
412 | <a name="l00513"></a>00513 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>,<span class="keyword">set</span>,<span class="stringliteral">"low"</span>); |
---|
413 | <a name="l00514"></a>00514 } |
---|
414 | <a name="l00515"></a>00515 }; |
---|
415 | <a name="l00516"></a>00516 |
---|
416 | <a name="l00517"></a>00517 |
---|
417 | <a name="l00523"></a>00523 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
418 | <a name="l00524"></a><a class="code" href="classbdm_1_1mlnorm.html">00524</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
---|
419 | <a name="l00525"></a>00525 { |
---|
420 | <a name="l00526"></a>00526 <span class="keyword">protected</span>: |
---|
421 | <a name="l00528"></a><a class="code" href="classbdm_1_1mlnorm.html#150ad6acb223b0a0abeaf92346686dcd">00528</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
---|
422 | <a name="l00529"></a>00529 mat A; |
---|
423 | <a name="l00530"></a>00530 vec mu_const; |
---|
424 | <a name="l00531"></a>00531 vec& _mu; <span class="comment">//cached epdf.mu;</span> |
---|
425 | <a name="l00532"></a>00532 <span class="keyword">public</span>: |
---|
426 | <a name="l00535"></a>00535 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> ( ) :<a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> (),<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ),A ( ),_mu ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._mu() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a> =&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; }; |
---|
427 | <a name="l00536"></a>00536 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> ( <span class="keyword">const</span> mat &A, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ),_mu ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._mu() ) |
---|
428 | <a name="l00537"></a>00537 { |
---|
429 | <a name="l00538"></a>00538 <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a> =&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">set_parameters</a> ( A,mu0,R ); |
---|
430 | <a name="l00539"></a>00539 }; |
---|
431 | <a name="l00541"></a>00541 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">set_parameters</a> ( <span class="keyword">const</span> mat &A, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R ); |
---|
432 | <a name="l00544"></a>00544 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">condition</a> ( <span class="keyword">const</span> vec &cond ); |
---|
433 | <a name="l00545"></a>00545 |
---|
434 | <a name="l00547"></a><a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced">00547</a> vec& <a class="code" href="classbdm_1_1mlnorm.html#56e587952f94fcac6cfc999eae6dbced" title="access function">_mu_const</a>() {<span class="keywordflow">return</span> mu_const;} |
---|
435 | <a name="l00549"></a><a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614">00549</a> mat& <a class="code" href="classbdm_1_1mlnorm.html#262a2a486bff585f34bb6a5005b02614" title="access function">_A</a>() {<span class="keywordflow">return</span> A;} |
---|
436 | <a name="l00551"></a><a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604">00551</a> mat <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R().to_mat();} |
---|
437 | <a name="l00552"></a>00552 |
---|
438 | <a name="l00553"></a>00553 <span class="keyword">template</span><<span class="keyword">class</span> sq_M> |
---|
439 | <a name="l00554"></a>00554 <span class="keyword">friend</span> std::ostream &operator<< ( std::ostream &os, mlnorm<sq_M> &ml ); |
---|
440 | <a name="l00555"></a>00555 }; |
---|
441 | <a name="l00556"></a>00556 |
---|
442 | <a name="l00558"></a>00558 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
443 | <a name="l00559"></a><a class="code" href="classbdm_1_1mgnorm.html">00559</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgnorm.html" title="Mpdf with general function for mean value.">mgnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
---|
444 | <a name="l00560"></a>00560 { |
---|
445 | <a name="l00561"></a>00561 <span class="keyword">protected</span>: |
---|
446 | <a name="l00563"></a><a class="code" href="classbdm_1_1mgnorm.html#8f7a376a1d2197e0634557e88e03104a">00563</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
---|
447 | <a name="l00564"></a>00564 vec &mu; |
---|
448 | <a name="l00565"></a>00565 <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>* g; |
---|
449 | <a name="l00566"></a>00566 <span class="keyword">public</span>: |
---|
450 | <a name="l00568"></a><a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d">00568</a> <a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d" title="default constructor">mgnorm</a>() :mu ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._mu() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;} |
---|
451 | <a name="l00570"></a><a class="code" href="classbdm_1_1mgnorm.html#578e02458e2a0d17f3864826b6ebd564">00570</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#578e02458e2a0d17f3864826b6ebd564" title="set mean function">set_parameters</a> ( <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>* g0, <span class="keyword">const</span> sq_T &R0 ) {g=g0; <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( g-><a class="code" href="classbdm_1_1fnc.html#083832294da9d1e40804158b979c4341" title="access function">dimension</a>() ), R0 );} |
---|
452 | <a name="l00571"></a><a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d">00571</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &cond ) {mu=g-><a class="code" href="classbdm_1_1fnc.html#6277b11d7fffc7ef8a2fa3e84ae5bad4" title="function evaluates numerical value of at cond ">eval</a> ( cond );}; |
---|
453 | <a name="l00572"></a>00572 |
---|
454 | <a name="l00573"></a>00573 |
---|
455 | <a name="l00601"></a><a class="code" href="classbdm_1_1mgnorm.html#d717dacc6a9eb967f8410994dc6dc6f9">00601</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#d717dacc6a9eb967f8410994dc6dc6f9">from_setting</a>( <span class="keyword">const</span> Setting &<span class="keyword">set</span> ) |
---|
456 | <a name="l00602"></a>00602 { |
---|
457 | <a name="l00603"></a>00603 <a class="code" href="classbdm_1_1fnc.html" title="Class representing function of variable represented by rv.">fnc</a>* g = UI::build<fnc>( <span class="keyword">set</span>, <span class="stringliteral">"g"</span> ); |
---|
458 | <a name="l00604"></a>00604 |
---|
459 | <a name="l00605"></a>00605 mat R; |
---|
460 | <a name="l00606"></a>00606 <span class="keywordflow">if</span> ( <span class="keyword">set</span>.exists( <span class="stringliteral">"dR"</span> ) ) |
---|
461 | <a name="l00607"></a>00607 { |
---|
462 | <a name="l00608"></a>00608 vec dR; |
---|
463 | <a name="l00609"></a>00609 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>( dR, <span class="keyword">set</span>, <span class="stringliteral">"dR"</span> ); |
---|
464 | <a name="l00610"></a>00610 R=diag(dR); |
---|
465 | <a name="l00611"></a>00611 } |
---|
466 | <a name="l00612"></a>00612 <span class="keywordflow">else</span> |
---|
467 | <a name="l00613"></a>00613 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>( R, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>); |
---|
468 | <a name="l00614"></a>00614 |
---|
469 | <a name="l00615"></a>00615 <a class="code" href="classbdm_1_1mgnorm.html#578e02458e2a0d17f3864826b6ebd564" title="set mean function">set_parameters</a>(g,R); |
---|
470 | <a name="l00616"></a>00616 } |
---|
471 | <a name="l00617"></a>00617 |
---|
472 | <a name="l00618"></a>00618 <span class="comment">/*void mgnorm::to_setting( Setting &set ) const</span> |
---|
473 | <a name="l00619"></a>00619 <span class="comment"> { </span> |
---|
474 | <a name="l00620"></a>00620 <span class="comment"> Transport::to_setting( set );</span> |
---|
475 | <a name="l00621"></a>00621 <span class="comment"></span> |
---|
476 | <a name="l00622"></a>00622 <span class="comment"> Setting &kilometers_setting = set.add("kilometers", Setting::TypeInt );</span> |
---|
477 | <a name="l00623"></a>00623 <span class="comment"> kilometers_setting = kilometers;</span> |
---|
478 | <a name="l00624"></a>00624 <span class="comment"></span> |
---|
479 | <a name="l00625"></a>00625 <span class="comment"> UI::save( passengers, set, "passengers" );</span> |
---|
480 | <a name="l00626"></a>00626 <span class="comment"> }*/</span> |
---|
481 | <a name="l00627"></a>00627 |
---|
482 | <a name="l00628"></a>00628 }; |
---|
483 | <a name="l00629"></a>00629 |
---|
484 | <a name="l00630"></a>00630 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(mgnorm<chmat>); |
---|
485 | <a name="l00631"></a>00631 |
---|
486 | <a name="l00632"></a>00632 |
---|
487 | <a name="l00640"></a><a class="code" href="classbdm_1_1mlstudent.html">00640</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><ldmat> |
---|
488 | <a name="l00641"></a>00641 { |
---|
489 | <a name="l00642"></a>00642 <span class="keyword">protected</span>: |
---|
490 | <a name="l00643"></a>00643 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Lambda; |
---|
491 | <a name="l00644"></a>00644 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>; |
---|
492 | <a name="l00645"></a>00645 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Re; |
---|
493 | <a name="l00646"></a>00646 <span class="keyword">public</span>: |
---|
494 | <a name="l00647"></a>00647 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> ( ) :<a class="code" href="classbdm_1_1mlnorm.html">mlnorm<ldmat></a> (), |
---|
495 | <a name="l00648"></a>00648 Lambda (), <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R() ) {} |
---|
496 | <a name="l00649"></a>00649 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0 ) |
---|
497 | <a name="l00650"></a>00650 { |
---|
498 | <a name="l00651"></a>00651 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
---|
499 | <a name="l00652"></a>00652 it_assert_debug ( R0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ==A0.rows(),<span class="stringliteral">""</span> ); |
---|
500 | <a name="l00653"></a>00653 |
---|
501 | <a name="l00654"></a>00654 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( mu0,Lambda ); <span class="comment">//</span> |
---|
502 | <a name="l00655"></a>00655 A = A0; |
---|
503 | <a name="l00656"></a>00656 mu_const = mu0; |
---|
504 | <a name="l00657"></a>00657 Re=R0; |
---|
505 | <a name="l00658"></a>00658 Lambda = Lambda0; |
---|
506 | <a name="l00659"></a>00659 } |
---|
507 | <a name="l00660"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00660</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> ( <span class="keyword">const</span> vec &cond ) |
---|
508 | <a name="l00661"></a>00661 { |
---|
509 | <a name="l00662"></a>00662 _mu = A*cond + mu_const; |
---|
510 | <a name="l00663"></a>00663 <span class="keywordtype">double</span> zeta; |
---|
511 | <a name="l00664"></a>00664 <span class="comment">//ugly hack!</span> |
---|
512 | <a name="l00665"></a>00665 <span class="keywordflow">if</span> ( ( cond.length() +1 ) ==Lambda.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ) |
---|
513 | <a name="l00666"></a>00666 { |
---|
514 | <a name="l00667"></a>00667 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( concat ( cond, vec_1 ( 1.0 ) ) ); |
---|
515 | <a name="l00668"></a>00668 } |
---|
516 | <a name="l00669"></a>00669 <span class="keywordflow">else</span> |
---|
517 | <a name="l00670"></a>00670 { |
---|
518 | <a name="l00671"></a>00671 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( cond ); |
---|
519 | <a name="l00672"></a>00672 } |
---|
520 | <a name="l00673"></a>00673 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> = Re; |
---|
521 | <a name="l00674"></a>00674 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>*= ( 1+zeta );<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
---|
522 | <a name="l00675"></a>00675 }; |
---|
523 | <a name="l00676"></a>00676 |
---|
524 | <a name="l00677"></a>00677 }; |
---|
525 | <a name="l00687"></a><a class="code" href="classbdm_1_1mgamma.html">00687</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
---|
526 | <a name="l00688"></a>00688 { |
---|
527 | <a name="l00689"></a>00689 <span class="keyword">protected</span>: |
---|
528 | <a name="l00691"></a><a class="code" href="classbdm_1_1mgamma.html#bdc9f1e9e03c09e91103fee269864438">00691</a> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
---|
529 | <a name="l00693"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00693</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
---|
530 | <a name="l00695"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00695</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>; |
---|
531 | <a name="l00696"></a>00696 |
---|
532 | <a name="l00697"></a>00697 <span class="keyword">public</span>: |
---|
533 | <a name="l00699"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00699</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> ( ), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> (), <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
---|
534 | <a name="l00701"></a>00701 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">const</span> vec &beta0 ); |
---|
535 | <a name="l00702"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00702</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/val;}; |
---|
536 | <a name="l00712"></a><a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">00712</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
---|
537 | <a name="l00713"></a>00713 <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">mpdf::from_setting</a>(<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
---|
538 | <a name="l00714"></a>00714 vec betatmp; <span class="comment">// ugly but necessary</span> |
---|
539 | <a name="l00715"></a>00715 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(betatmp,<span class="keyword">set</span>,<span class="stringliteral">"beta"</span>); |
---|
540 | <a name="l00716"></a>00716 <span class="keyword">set</span>.lookupValue(<span class="stringliteral">"k"</span>,<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>); |
---|
541 | <a name="l00717"></a>00717 <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a>(<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>,betatmp); |
---|
542 | <a name="l00718"></a>00718 } |
---|
543 | <a name="l00719"></a>00719 }; |
---|
544 | <a name="l00720"></a>00720 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(mgamma); |
---|
545 | <a name="l00721"></a>00721 |
---|
546 | <a name="l00731"></a><a class="code" href="classbdm_1_1migamma.html">00731</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
---|
547 | <a name="l00732"></a>00732 { |
---|
548 | <a name="l00733"></a>00733 <span class="keyword">protected</span>: |
---|
549 | <a name="l00735"></a><a class="code" href="classbdm_1_1migamma.html#a31b39d4179551b593c9e0d7d756783a">00735</a> <a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
---|
550 | <a name="l00737"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00737</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
---|
551 | <a name="l00739"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00739</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>; |
---|
552 | <a name="l00741"></a><a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5">00741</a> vec &<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>; |
---|
553 | <a name="l00742"></a>00742 |
---|
554 | <a name="l00743"></a>00743 <span class="keyword">public</span>: |
---|
555 | <a name="l00746"></a>00746 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ), <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
---|
556 | <a name="l00747"></a>00747 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> &m ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( m.<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ), <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
---|
557 | <a name="l00749"></a>00749 |
---|
558 | <a name="l00751"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00751</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">int</span> len, <span class="keywordtype">double</span> k0 ) |
---|
559 | <a name="l00752"></a>00752 { |
---|
560 | <a name="l00753"></a>00753 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>=k0; |
---|
561 | <a name="l00754"></a>00754 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( ( 1.0/ ( <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>*<a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> ) +2.0 ) *ones ( len ) <span class="comment">/*alpha*/</span>, ones ( len ) <span class="comment">/*beta*/</span> ); |
---|
562 | <a name="l00755"></a>00755 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
---|
563 | <a name="l00756"></a>00756 }; |
---|
564 | <a name="l00757"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00757</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) |
---|
565 | <a name="l00758"></a>00758 { |
---|
566 | <a name="l00759"></a>00759 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>=elem_mult ( val, ( <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>-1.0 ) ); |
---|
567 | <a name="l00760"></a>00760 }; |
---|
568 | <a name="l00761"></a>00761 }; |
---|
569 | <a name="l00762"></a>00762 |
---|
570 | <a name="l00763"></a>00763 |
---|
571 | <a name="l00775"></a><a class="code" href="classbdm_1_1mgamma__fix.html">00775</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma__fix.html" title="Gamma random walk around a fixed point.">mgamma_fix</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> |
---|
572 | <a name="l00776"></a>00776 { |
---|
573 | <a name="l00777"></a>00777 <span class="keyword">protected</span>: |
---|
574 | <a name="l00779"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa">00779</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>; |
---|
575 | <a name="l00781"></a><a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2">00781</a> vec <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>; |
---|
576 | <a name="l00782"></a>00782 <span class="keyword">public</span>: |
---|
577 | <a name="l00784"></a><a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d">00784</a> <a class="code" href="classbdm_1_1mgamma__fix.html#9a31bc9b4b60188a18a2a6b588dc4b2d" title="Constructor.">mgamma_fix</a> ( ) : <a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> ( ),<a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a> () {}; |
---|
578 | <a name="l00786"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2">00786</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0 ) |
---|
579 | <a name="l00787"></a>00787 { |
---|
580 | <a name="l00788"></a>00788 <a class="code" href="classbdm_1_1mgamma__fix.html#1bfd30e90db9dc1fbda4a9fbb0b716b2" title="Set value of k.">mgamma::set_parameters</a> ( k0, ref0 ); |
---|
581 | <a name="l00789"></a>00789 <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>=pow ( ref0,1.0-l0 );<a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a>=l0; |
---|
582 | <a name="l00790"></a>00790 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=dimension(); |
---|
583 | <a name="l00791"></a>00791 }; |
---|
584 | <a name="l00792"></a>00792 |
---|
585 | <a name="l00793"></a><a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7">00793</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma__fix.html#1d539591deb7a38bb3403c2b396c8ff7" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) {vec mean=elem_mult ( <a class="code" href="classbdm_1_1mgamma__fix.html#018c6f901a04e419455308a07eb3b0b2" title="reference vector">refl</a>,pow ( val,<a class="code" href="classbdm_1_1mgamma__fix.html#1eb701506aabb2e6af007e487212d6fa" title="parameter l">l</a> ) ); <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/mean;}; |
---|
586 | <a name="l00794"></a>00794 }; |
---|
587 | <a name="l00795"></a>00795 |
---|
588 | <a name="l00796"></a>00796 |
---|
589 | <a name="l00809"></a><a class="code" href="classbdm_1_1migamma__ref.html">00809</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma__ref.html" title="Inverse-Gamma random walk around a fixed point.">migamma_ref</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> |
---|
590 | <a name="l00810"></a>00810 { |
---|
591 | <a name="l00811"></a>00811 <span class="keyword">protected</span>: |
---|
592 | <a name="l00813"></a><a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d">00813</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>; |
---|
593 | <a name="l00815"></a><a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6">00815</a> vec <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>; |
---|
594 | <a name="l00816"></a>00816 <span class="keyword">public</span>: |
---|
595 | <a name="l00818"></a><a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f">00818</a> <a class="code" href="classbdm_1_1migamma__ref.html#f45b15a10f084991ba6b48295f10421f" title="Constructor.">migamma_ref</a> ( ) : <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> (),<a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a> ( ) {}; |
---|
596 | <a name="l00820"></a><a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800">00820</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> k0 , vec ref0, <span class="keywordtype">double</span> l0 ) |
---|
597 | <a name="l00821"></a>00821 { |
---|
598 | <a name="l00822"></a>00822 <a class="code" href="classbdm_1_1migamma__ref.html#b0b4eb278ef5d0831ec4954ba7bd2800" title="Set value of k.">migamma::set_parameters</a> ( ref0.length(), k0 ); |
---|
599 | <a name="l00823"></a>00823 <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>=pow ( ref0,1.0-l0 ); |
---|
600 | <a name="l00824"></a>00824 <a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a>=l0; |
---|
601 | <a name="l00825"></a>00825 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
---|
602 | <a name="l00826"></a>00826 }; |
---|
603 | <a name="l00827"></a>00827 |
---|
604 | <a name="l00828"></a><a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a">00828</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) |
---|
605 | <a name="l00829"></a>00829 { |
---|
606 | <a name="l00830"></a>00830 vec mean=elem_mult ( <a class="code" href="classbdm_1_1migamma__ref.html#3692dc67caf4367e15564d37f45476f6" title="reference vector">refl</a>,pow ( val,<a class="code" href="classbdm_1_1migamma__ref.html#cdc1345ba8375fbdb18a69322d2f841d" title="parameter l">l</a> ) ); |
---|
607 | <a name="l00831"></a>00831 <a class="code" href="classbdm_1_1migamma__ref.html#ae86b2e4ff963d62e05d4e130514634a" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">migamma::condition</a> ( mean ); |
---|
608 | <a name="l00832"></a>00832 }; |
---|
609 | <a name="l00833"></a>00833 |
---|
610 | <a name="l00854"></a>00854 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma__ref.html#9e7e0f7d2aa9ecca8ec1af8cbcb5ef1d">from_setting</a>( <span class="keyword">const</span> Setting &<span class="keyword">set</span> ); |
---|
611 | <a name="l00855"></a>00855 |
---|
612 | <a name="l00856"></a>00856 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
---|
613 | <a name="l00857"></a>00857 }; |
---|
614 | <a name="l00858"></a>00858 |
---|
615 | <a name="l00859"></a>00859 |
---|
616 | <a name="l00860"></a>00860 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(migamma_ref); |
---|
617 | <a name="l00861"></a>00861 |
---|
618 | <a name="l00871"></a><a class="code" href="classbdm_1_1elognorm.html">00871</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1elognorm.html">elognorm</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><ldmat> |
---|
619 | <a name="l00872"></a>00872 { |
---|
620 | <a name="l00873"></a>00873 <span class="keyword">public</span>: |
---|
621 | <a name="l00874"></a><a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba">00874</a> vec <a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> exp ( <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<ldmat>::sample</a>() );}; |
---|
622 | <a name="l00875"></a><a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea">00875</a> vec <a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec var=<a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">enorm<ldmat>::variance</a>();<span class="keywordflow">return</span> exp ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> - 0.5*var );}; |
---|
623 | <a name="l00876"></a>00876 |
---|
624 | <a name="l00877"></a>00877 }; |
---|
625 | <a name="l00878"></a>00878 |
---|
626 | <a name="l00890"></a><a class="code" href="classbdm_1_1mlognorm.html">00890</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlognorm.html" title="Log-Normal random walk.">mlognorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> |
---|
627 | <a name="l00891"></a>00891 { |
---|
628 | <a name="l00892"></a>00892 <span class="keyword">protected</span>: |
---|
629 | <a name="l00893"></a>00893 <a class="code" href="classbdm_1_1elognorm.html">elognorm</a> eno; |
---|
630 | <a name="l00895"></a><a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a">00895</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
---|
631 | <a name="l00897"></a><a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2">00897</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
---|
632 | <a name="l00898"></a>00898 <span class="keyword">public</span>: |
---|
633 | <a name="l00900"></a><a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41">00900</a> <a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a> ( ) : eno (), <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> ( eno._mu() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&eno;}; |
---|
634 | <a name="l00902"></a><a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f">00902</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">int</span> size, <span class="keywordtype">double</span> k ) |
---|
635 | <a name="l00903"></a>00903 { |
---|
636 | <a name="l00904"></a>00904 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5*log ( k*k+1 ); |
---|
637 | <a name="l00905"></a>00905 eno.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( zeros ( size ),2*<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye ( size ) ); |
---|
638 | <a name="l00906"></a>00906 |
---|
639 | <a name="l00907"></a>00907 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
---|
640 | <a name="l00908"></a>00908 }; |
---|
641 | <a name="l00909"></a>00909 |
---|
642 | <a name="l00910"></a><a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">00910</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) |
---|
643 | <a name="l00911"></a>00911 { |
---|
644 | <a name="l00912"></a>00912 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>=log ( val )-<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>;<span class="comment">//elem_mult ( refl,pow ( val,l ) );</span> |
---|
645 | <a name="l00913"></a>00913 }; |
---|
646 | <a name="l00914"></a>00914 |
---|
647 | <a name="l00933"></a>00933 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#49e45ea13a869da607ef9be7a229128a">from_setting</a>( <span class="keyword">const</span> Setting &<span class="keyword">set</span> ); |
---|
648 | <a name="l00934"></a>00934 |
---|
649 | <a name="l00935"></a>00935 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
---|
650 | <a name="l00936"></a>00936 |
---|
651 | <a name="l00937"></a>00937 }; |
---|
652 | <a name="l00938"></a>00938 |
---|
653 | <a name="l00939"></a>00939 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(mlognorm); |
---|
654 | <a name="l00940"></a>00940 |
---|
655 | <a name="l00944"></a><a class="code" href="classbdm_1_1eWishartCh.html">00944</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
---|
656 | <a name="l00945"></a>00945 { |
---|
657 | <a name="l00946"></a>00946 <span class="keyword">protected</span>: |
---|
658 | <a name="l00948"></a><a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490">00948</a> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>; |
---|
659 | <a name="l00950"></a><a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f">00950</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; |
---|
660 | <a name="l00952"></a><a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3">00952</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>; |
---|
661 | <a name="l00953"></a>00953 <span class="keyword">public</span>: |
---|
662 | <a name="l00954"></a>00954 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0 ) {<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>=<a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> ( Y0 );<a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>=delta0; <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>=<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classsqmat.html#071e80ced9cc3b8cbb360fa7462eb646" title="Reimplementing common functions of mat: cols().">rows</a>(); <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>*<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; } |
---|
663 | <a name="l00955"></a>00955 mat sample_mat()<span class="keyword"> const</span> |
---|
664 | <a name="l00956"></a>00956 <span class="keyword"> </span>{ |
---|
665 | <a name="l00957"></a>00957 mat X=zeros ( <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>,<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> ); |
---|
666 | <a name="l00958"></a>00958 |
---|
667 | <a name="l00959"></a>00959 <span class="comment">//sample diagonal</span> |
---|
668 | <a name="l00960"></a>00960 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>;i++ ) |
---|
669 | <a name="l00961"></a>00961 { |
---|
670 | <a name="l00962"></a>00962 GamRNG.setup ( 0.5* ( <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>-i ) , 0.5 ); <span class="comment">// no +1 !! index if from 0</span> |
---|
671 | <a name="l00963"></a>00963 <span class="preprocessor">#pragma omp critical</span> |
---|
672 | <a name="l00964"></a>00964 <span class="preprocessor"></span> X ( i,i ) =sqrt ( GamRNG() ); |
---|
673 | <a name="l00965"></a>00965 } |
---|
674 | <a name="l00966"></a>00966 <span class="comment">//do the rest</span> |
---|
675 | <a name="l00967"></a>00967 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<p;i++ ) |
---|
676 | <a name="l00968"></a>00968 { |
---|
677 | <a name="l00969"></a>00969 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> j=i+1;j<p;j++ ) |
---|
678 | <a name="l00970"></a>00970 { |
---|
679 | <a name="l00971"></a>00971 <span class="preprocessor">#pragma omp critical</span> |
---|
680 | <a name="l00972"></a>00972 <span class="preprocessor"></span> X ( i,j ) =NorRNG.sample(); |
---|
681 | <a name="l00973"></a>00973 } |
---|
682 | <a name="l00974"></a>00974 } |
---|
683 | <a name="l00975"></a>00975 <span class="keywordflow">return</span> X*<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>();<span class="comment">// return upper triangular part of the decomposition</span> |
---|
684 | <a name="l00976"></a>00976 } |
---|
685 | <a name="l00977"></a><a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a">00977</a> vec <a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a" title="Returns a sample, from density .">sample</a> ()<span class="keyword"> const</span> |
---|
686 | <a name="l00978"></a>00978 <span class="keyword"> </span>{ |
---|
687 | <a name="l00979"></a>00979 <span class="keywordflow">return</span> vec ( sample_mat()._data(),p*p ); |
---|
688 | <a name="l00980"></a>00980 } |
---|
689 | <a name="l00982"></a><a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981">00982</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> ( <span class="keyword">const</span> mat &Ch0 ) {copy_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,Ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>()._data() );} |
---|
690 | <a name="l00984"></a><a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a">00984</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a" title="fast access function y0 will be copied into Y.Ch.">_setY</a> ( <span class="keyword">const</span> vec &ch0 ) {copy_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>()._data() ); } |
---|
691 | <a name="l00986"></a><a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e">00986</a> <span class="keyword">const</span> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& <a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>()<span class="keyword">const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>;} |
---|
692 | <a name="l00987"></a>00987 }; |
---|
693 | <a name="l00988"></a>00988 |
---|
694 | <a name="l00989"></a>00989 <span class="keyword">class </span>eiWishartCh: <span class="keyword">public</span> epdf |
---|
695 | <a name="l00990"></a>00990 { |
---|
696 | <a name="l00991"></a>00991 <span class="keyword">protected</span>: |
---|
697 | <a name="l00992"></a>00992 eWishartCh W; |
---|
698 | <a name="l00993"></a>00993 <span class="keywordtype">int</span> p; |
---|
699 | <a name="l00994"></a>00994 <span class="keywordtype">double</span> delta; |
---|
700 | <a name="l00995"></a>00995 <span class="keyword">public</span>: |
---|
701 | <a name="l00996"></a>00996 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) { |
---|
702 | <a name="l00997"></a>00997 delta = delta0; |
---|
703 | <a name="l00998"></a>00998 W.set_parameters ( inv ( Y0 ),delta0 ); |
---|
704 | <a name="l00999"></a>00999 dim = W.dimension(); p=Y0.rows(); |
---|
705 | <a name="l01000"></a>01000 } |
---|
706 | <a name="l01001"></a>01001 vec sample()<span class="keyword"> const </span>{mat iCh; iCh=inv ( W.sample_mat() ); <span class="keywordflow">return</span> vec ( iCh._data(),<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> );} |
---|
707 | <a name="l01002"></a>01002 <span class="keywordtype">void</span> _setY ( <span class="keyword">const</span> vec &y0 ) |
---|
708 | <a name="l01003"></a>01003 { |
---|
709 | <a name="l01004"></a>01004 mat Ch ( p,p ); |
---|
710 | <a name="l01005"></a>01005 mat iCh ( p,p ); |
---|
711 | <a name="l01006"></a>01006 copy_vector ( dim, y0._data(), Ch._data() ); |
---|
712 | <a name="l01007"></a>01007 |
---|
713 | <a name="l01008"></a>01008 iCh=inv ( Ch ); |
---|
714 | <a name="l01009"></a>01009 W.setY ( iCh ); |
---|
715 | <a name="l01010"></a>01010 } |
---|
716 | <a name="l01011"></a>01011 <span class="keyword">virtual</span> <span class="keywordtype">double</span> evallog ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
717 | <a name="l01012"></a>01012 <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> X(p); |
---|
718 | <a name="l01013"></a>01013 <span class="keyword">const</span> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& Y=W.getY(); |
---|
719 | <a name="l01014"></a>01014 |
---|
720 | <a name="l01015"></a>01015 copy_vector(p*p,val._data(),X._Ch()._data()); |
---|
721 | <a name="l01016"></a>01016 <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> iX(p);X.inv(iX); |
---|
722 | <a name="l01017"></a>01017 <span class="comment">// compute </span> |
---|
723 | <a name="l01018"></a>01018 <span class="comment">// \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)},</span> |
---|
724 | <a name="l01019"></a>01019 mat M=Y.<a class="code" href="classchmat.html#045addd685f8d978efda232d7dcb070e" title="Conversion to full matrix.">to_mat</a>()*iX.to_mat(); |
---|
725 | <a name="l01020"></a>01020 |
---|
726 | <a name="l01021"></a>01021 <span class="keywordtype">double</span> log1 = 0.5*p*(2*Y.<a class="code" href="classchmat.html#b504ca818203b13e667cb3c503980382" title="Logarithm of a determinant.">logdet</a>())-0.5*(delta+p+1)*(2*X.logdet())-0.5*trace(M); |
---|
727 | <a name="l01022"></a>01022 <span class="comment">//Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!!</span> |
---|
728 | <a name="l01023"></a>01023 |
---|
729 | <a name="l01024"></a>01024 <span class="comment">/* if (0) {</span> |
---|
730 | <a name="l01025"></a>01025 <span class="comment"> mat XX=X.to_mat();</span> |
---|
731 | <a name="l01026"></a>01026 <span class="comment"> mat YY=Y.to_mat();</span> |
---|
732 | <a name="l01027"></a>01027 <span class="comment"> </span> |
---|
733 | <a name="l01028"></a>01028 <span class="comment"> double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX)); </span> |
---|
734 | <a name="l01029"></a>01029 <span class="comment"> cout << log1 << "," << log2 << endl;</span> |
---|
735 | <a name="l01030"></a>01030 <span class="comment"> }*/</span> |
---|
736 | <a name="l01031"></a>01031 <span class="keywordflow">return</span> log1; |
---|
737 | <a name="l01032"></a>01032 }; |
---|
738 | <a name="l01033"></a>01033 |
---|
739 | <a name="l01034"></a>01034 }; |
---|
740 | <a name="l01035"></a>01035 |
---|
741 | <a name="l01036"></a>01036 <span class="keyword">class </span>rwiWishartCh : <span class="keyword">public</span> mpdf |
---|
742 | <a name="l01037"></a>01037 { |
---|
743 | <a name="l01038"></a>01038 <span class="keyword">protected</span>: |
---|
744 | <a name="l01039"></a>01039 eiWishartCh eiW; |
---|
745 | <a name="l01041"></a>01041 <span class="keywordtype">double</span> sqd; |
---|
746 | <a name="l01042"></a>01042 <span class="comment">//reference point for diagonal</span> |
---|
747 | <a name="l01043"></a>01043 vec refl; |
---|
748 | <a name="l01044"></a>01044 <span class="keywordtype">double</span> l; |
---|
749 | <a name="l01045"></a>01045 <span class="keywordtype">int</span> p; |
---|
750 | <a name="l01046"></a>01046 <span class="keyword">public</span>: |
---|
751 | <a name="l01047"></a>01047 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> p0, <span class="keywordtype">double</span> k, vec ref0, <span class="keywordtype">double</span> l0 ) |
---|
752 | <a name="l01048"></a>01048 { |
---|
753 | <a name="l01049"></a>01049 p=p0; |
---|
754 | <a name="l01050"></a>01050 <span class="keywordtype">double</span> delta = 2/(k*k)+p+3; |
---|
755 | <a name="l01051"></a>01051 sqd=sqrt ( delta-p-1 ); |
---|
756 | <a name="l01052"></a>01052 l=l0; |
---|
757 | <a name="l01053"></a>01053 refl=pow(ref0,1-l); |
---|
758 | <a name="l01054"></a>01054 |
---|
759 | <a name="l01055"></a>01055 eiW.set_parameters ( eye ( p ),delta ); |
---|
760 | <a name="l01056"></a>01056 <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&eiW; |
---|
761 | <a name="l01057"></a>01057 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=eiW.dimension(); |
---|
762 | <a name="l01058"></a>01058 } |
---|
763 | <a name="l01059"></a>01059 <span class="keywordtype">void</span> condition ( <span class="keyword">const</span> vec &c ) { |
---|
764 | <a name="l01060"></a>01060 vec z=c; |
---|
765 | <a name="l01061"></a>01061 <span class="keywordtype">int</span> ri=0; |
---|
766 | <a name="l01062"></a>01062 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<p*p;i+=(p+1)){<span class="comment">//trace diagonal element</span> |
---|
767 | <a name="l01063"></a>01063 z(i) = pow(z(i),l)*refl(ri); |
---|
768 | <a name="l01064"></a>01064 ri++; |
---|
769 | <a name="l01065"></a>01065 } |
---|
770 | <a name="l01066"></a>01066 |
---|
771 | <a name="l01067"></a>01067 eiW._setY ( sqd*z ); |
---|
772 | <a name="l01068"></a>01068 } |
---|
773 | <a name="l01069"></a>01069 }; |
---|
774 | <a name="l01070"></a>01070 |
---|
775 | <a name="l01072"></a>01072 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
---|
776 | <a name="l01078"></a><a class="code" href="classbdm_1_1eEmp.html">01078</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
---|
777 | <a name="l01079"></a>01079 { |
---|
778 | <a name="l01080"></a>01080 <span class="keyword">protected</span> : |
---|
779 | <a name="l01082"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">01082</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
---|
780 | <a name="l01084"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">01084</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
---|
781 | <a name="l01086"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">01086</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
---|
782 | <a name="l01087"></a>01087 <span class="keyword">public</span>: |
---|
783 | <a name="l01090"></a>01090 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ),<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( ),<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( ) {}; |
---|
784 | <a name="l01092"></a><a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076">01092</a> <a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076" title="copy constructor">eEmp</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &e ) : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( e ), <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( e.<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ), <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( e.<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ) {}; |
---|
785 | <a name="l01094"></a>01094 |
---|
786 | <a name="l01096"></a>01096 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#7cfd383180b486fe4526bdf0179350c0" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> vec &w0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); |
---|
787 | <a name="l01098"></a><a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7">01098</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 , <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> ) {<a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( ones ( n ) /n,pdf0 );}; |
---|
788 | <a name="l01100"></a>01100 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b62d802b8ef39f7c4dcbeb366c90951a" title="Set sample.">set_samples</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); |
---|
789 | <a name="l01102"></a><a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1">01102</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> ( <span class="keywordtype">int</span> n0, <span class="keywordtype">bool</span> copy=<span class="keyword">true</span> ) {<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>=n0; <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>.set_size ( n0,copy );<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>.set_size ( n0,copy );}; |
---|
790 | <a name="l01104"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">01104</a> vec& <a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
---|
791 | <a name="l01106"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">01106</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714" title="Potentially dangerous, use with care.">_w</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
---|
792 | <a name="l01108"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">01108</a> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
---|
793 | <a name="l01110"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">01110</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2" title="access function">_samples</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
---|
794 | <a name="l01112"></a>01112 ivec <a class="code" href="classbdm_1_1eEmp.html#f06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> ( RESAMPLING_METHOD method=SYSTEMATIC ); |
---|
795 | <a name="l01114"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">01114</a> vec <a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270" title="inherited operation : NOT implemneted">sample</a>()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0;} |
---|
796 | <a name="l01116"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">01116</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09" title="inherited operation : NOT implemneted">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0.0;} |
---|
797 | <a name="l01117"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">01117</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const</span> |
---|
798 | <a name="l01118"></a>01118 <span class="keyword"> </span>{ |
---|
799 | <a name="l01119"></a>01119 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
800 | <a name="l01120"></a>01120 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) {pom+=<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) *<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( i );} |
---|
801 | <a name="l01121"></a>01121 <span class="keywordflow">return</span> pom; |
---|
802 | <a name="l01122"></a>01122 } |
---|
803 | <a name="l01123"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">01123</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const</span> |
---|
804 | <a name="l01124"></a>01124 <span class="keyword"> </span>{ |
---|
805 | <a name="l01125"></a>01125 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
806 | <a name="l01126"></a>01126 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) {pom+=pow ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ),2 ) *<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( i );} |
---|
807 | <a name="l01127"></a>01127 <span class="keywordflow">return</span> pom-pow ( <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(),2 ); |
---|
808 | <a name="l01128"></a>01128 } |
---|
809 | <a name="l01130"></a><a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f">01130</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f" title="For this class, qbounds are minimum and maximum value of the population!">qbounds</a> ( vec &lb, vec &ub, <span class="keywordtype">double</span> perc=0.95 )<span class="keyword"> const</span> |
---|
810 | <a name="l01131"></a>01131 <span class="keyword"> </span>{ |
---|
811 | <a name="l01132"></a>01132 <span class="comment">// lb in inf so than it will be pushed below;</span> |
---|
812 | <a name="l01133"></a>01133 lb.set_size ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
813 | <a name="l01134"></a>01134 ub.set_size ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
814 | <a name="l01135"></a>01135 lb = std::numeric_limits<double>::infinity(); |
---|
815 | <a name="l01136"></a>01136 ub = -std::numeric_limits<double>::infinity(); |
---|
816 | <a name="l01137"></a>01137 <span class="keywordtype">int</span> j; |
---|
817 | <a name="l01138"></a>01138 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) |
---|
818 | <a name="l01139"></a>01139 { |
---|
819 | <a name="l01140"></a>01140 <span class="keywordflow">for</span> ( j=0;j<<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>; j++ ) |
---|
820 | <a name="l01141"></a>01141 { |
---|
821 | <a name="l01142"></a>01142 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) <lb ( j ) ) {lb ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
---|
822 | <a name="l01143"></a>01143 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) >ub ( j ) ) {ub ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
---|
823 | <a name="l01144"></a>01144 } |
---|
824 | <a name="l01145"></a>01145 } |
---|
825 | <a name="l01146"></a>01146 } |
---|
826 | <a name="l01147"></a>01147 }; |
---|
827 | <a name="l01148"></a>01148 |
---|
828 | <a name="l01149"></a>01149 |
---|
829 | <a name="l01151"></a>01151 |
---|
830 | <a name="l01152"></a>01152 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
831 | <a name="l01153"></a>01153 <span class="keywordtype">void</span> enorm<sq_T>::set_parameters ( <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0 ) |
---|
832 | <a name="l01154"></a>01154 { |
---|
833 | <a name="l01155"></a>01155 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
---|
834 | <a name="l01156"></a>01156 mu = mu0; |
---|
835 | <a name="l01157"></a>01157 R = R0; |
---|
836 | <a name="l01158"></a>01158 <a class="code" href="classbdm_1_1root.html#1c314bd6d6dacb8ba78ea5eb88fd9516" title="This method TODO.">validate</a>(); |
---|
837 | <a name="l01159"></a>01159 }; |
---|
838 | <a name="l01160"></a>01160 |
---|
839 | <a name="l01161"></a>01161 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
840 | <a name="l01162"></a><a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">01162</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">enorm<sq_T>::from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
---|
841 | <a name="l01163"></a>01163 <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">epdf::from_setting</a>(<span class="keyword">set</span>); <span class="comment">//reads rv</span> |
---|
842 | <a name="l01164"></a>01164 |
---|
843 | <a name="l01165"></a>01165 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>,<span class="keyword">set</span>,<span class="stringliteral">"mu"</span>); |
---|
844 | <a name="l01166"></a>01166 mat Rtmp;<span class="comment">// necessary for conversion</span> |
---|
845 | <a name="l01167"></a>01167 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="The existing instance of type T is initialized with values stored in the Setting...">UI::get</a>(Rtmp,<span class="keyword">set</span>,<span class="stringliteral">"R"</span>); |
---|
846 | <a name="l01168"></a>01168 <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>=Rtmp; <span class="comment">// conversion</span> |
---|
847 | <a name="l01169"></a>01169 <a class="code" href="classbdm_1_1enorm.html#38eb17ecb75d94a50b6782fcf735cfea" title="This method TODO.">validate</a>(); |
---|
848 | <a name="l01170"></a>01170 } |
---|
849 | <a name="l01171"></a>01171 |
---|
850 | <a name="l01172"></a>01172 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
851 | <a name="l01173"></a><a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2">01173</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">enorm<sq_T>::dupdate</a> ( mat &v, <span class="keywordtype">double</span> nu ) |
---|
852 | <a name="l01174"></a>01174 { |
---|
853 | <a name="l01175"></a>01175 <span class="comment">//</span> |
---|
854 | <a name="l01176"></a>01176 }; |
---|
855 | <a name="l01177"></a>01177 |
---|
856 | <a name="l01178"></a>01178 <span class="comment">// template<class sq_T></span> |
---|
857 | <a name="l01179"></a>01179 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
---|
858 | <a name="l01180"></a>01180 <span class="comment">// //</span> |
---|
859 | <a name="l01181"></a>01181 <span class="comment">// };</span> |
---|
860 | <a name="l01182"></a>01182 |
---|
861 | <a name="l01183"></a>01183 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
862 | <a name="l01184"></a><a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766">01184</a> vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a>()<span class="keyword"> const</span> |
---|
863 | <a name="l01185"></a>01185 <span class="keyword"> </span>{ |
---|
864 | <a name="l01186"></a>01186 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
865 | <a name="l01187"></a>01187 <span class="preprocessor">#pragma omp critical</span> |
---|
866 | <a name="l01188"></a>01188 <span class="preprocessor"></span> NorRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
---|
867 | <a name="l01189"></a>01189 vec smp = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
---|
868 | <a name="l01190"></a>01190 |
---|
869 | <a name="l01191"></a>01191 smp += <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
---|
870 | <a name="l01192"></a>01192 <span class="keywordflow">return</span> smp; |
---|
871 | <a name="l01193"></a>01193 }; |
---|
872 | <a name="l01194"></a>01194 |
---|
873 | <a name="l01195"></a>01195 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
874 | <a name="l01196"></a>01196 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a> ( <span class="keywordtype">int</span> N )<span class="keyword"> const</span> |
---|
875 | <a name="l01197"></a>01197 <span class="keyword"> </span>{ |
---|
876 | <a name="l01198"></a>01198 mat X ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,N ); |
---|
877 | <a name="l01199"></a>01199 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
---|
878 | <a name="l01200"></a>01200 vec pom; |
---|
879 | <a name="l01201"></a>01201 <span class="keywordtype">int</span> i; |
---|
880 | <a name="l01202"></a>01202 |
---|
881 | <a name="l01203"></a>01203 <span class="keywordflow">for</span> ( i=0;i<N;i++ ) |
---|
882 | <a name="l01204"></a>01204 { |
---|
883 | <a name="l01205"></a>01205 <span class="preprocessor">#pragma omp critical</span> |
---|
884 | <a name="l01206"></a>01206 <span class="preprocessor"></span> NorRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
---|
885 | <a name="l01207"></a>01207 pom = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
---|
886 | <a name="l01208"></a>01208 pom +=<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
---|
887 | <a name="l01209"></a>01209 X.set_col ( i, pom ); |
---|
888 | <a name="l01210"></a>01210 } |
---|
889 | <a name="l01211"></a>01211 |
---|
890 | <a name="l01212"></a>01212 <span class="keywordflow">return</span> X; |
---|
891 | <a name="l01213"></a>01213 }; |
---|
892 | <a name="l01214"></a>01214 |
---|
893 | <a name="l01215"></a>01215 <span class="comment">// template<class sq_T></span> |
---|
894 | <a name="l01216"></a>01216 <span class="comment">// double enorm<sq_T>::eval ( const vec &val ) const {</span> |
---|
895 | <a name="l01217"></a>01217 <span class="comment">// double pdfl,e;</span> |
---|
896 | <a name="l01218"></a>01218 <span class="comment">// pdfl = evallog ( val );</span> |
---|
897 | <a name="l01219"></a>01219 <span class="comment">// e = exp ( pdfl );</span> |
---|
898 | <a name="l01220"></a>01220 <span class="comment">// return e;</span> |
---|
899 | <a name="l01221"></a>01221 <span class="comment">// };</span> |
---|
900 | <a name="l01222"></a>01222 |
---|
901 | <a name="l01223"></a>01223 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
902 | <a name="l01224"></a><a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3">01224</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">enorm<sq_T>::evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const</span> |
---|
903 | <a name="l01225"></a>01225 <span class="keyword"> </span>{ |
---|
904 | <a name="l01226"></a>01226 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
---|
905 | <a name="l01227"></a>01227 <span class="keywordtype">double</span> tmp=-0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.invqform ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>-val ) );<span class="comment">// - lognc();</span> |
---|
906 | <a name="l01228"></a>01228 <span class="keywordflow">return</span> tmp; |
---|
907 | <a name="l01229"></a>01229 }; |
---|
908 | <a name="l01230"></a>01230 |
---|
909 | <a name="l01231"></a>01231 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
910 | <a name="l01232"></a><a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32">01232</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">enorm<sq_T>::lognc</a> ()<span class="keyword"> const</span> |
---|
911 | <a name="l01233"></a>01233 <span class="keyword"> </span>{ |
---|
912 | <a name="l01234"></a>01234 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
---|
913 | <a name="l01235"></a>01235 <span class="keywordtype">double</span> tmp=0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.cols() * 1.83787706640935 +<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.logdet() ); |
---|
914 | <a name="l01236"></a>01236 <span class="keywordflow">return</span> tmp; |
---|
915 | <a name="l01237"></a>01237 }; |
---|
916 | <a name="l01238"></a>01238 |
---|
917 | <a name="l01239"></a>01239 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
918 | <a name="l01240"></a><a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f">01240</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">mlnorm<sq_T>::set_parameters</a> ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0 ) |
---|
919 | <a name="l01241"></a>01241 { |
---|
920 | <a name="l01242"></a>01242 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
---|
921 | <a name="l01243"></a>01243 it_assert_debug ( A0.rows() ==R0.rows(),<span class="stringliteral">""</span> ); |
---|
922 | <a name="l01244"></a>01244 |
---|
923 | <a name="l01245"></a>01245 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( A0.rows() ),R0 ); |
---|
924 | <a name="l01246"></a>01246 A = A0; |
---|
925 | <a name="l01247"></a>01247 mu_const = mu0; |
---|
926 | <a name="l01248"></a>01248 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=A0.cols(); |
---|
927 | <a name="l01249"></a>01249 } |
---|
928 | <a name="l01250"></a>01250 |
---|
929 | <a name="l01251"></a>01251 <span class="comment">// template<class sq_T></span> |
---|
930 | <a name="l01252"></a>01252 <span class="comment">// vec mlnorm<sq_T>::samplecond (const vec &cond, double &lik ) {</span> |
---|
931 | <a name="l01253"></a>01253 <span class="comment">// this->condition ( cond );</span> |
---|
932 | <a name="l01254"></a>01254 <span class="comment">// vec smp = epdf.sample();</span> |
---|
933 | <a name="l01255"></a>01255 <span class="comment">// lik = epdf.eval ( smp );</span> |
---|
934 | <a name="l01256"></a>01256 <span class="comment">// return smp;</span> |
---|
935 | <a name="l01257"></a>01257 <span class="comment">// }</span> |
---|
936 | <a name="l01258"></a>01258 |
---|
937 | <a name="l01259"></a>01259 <span class="comment">// template<class sq_T></span> |
---|
938 | <a name="l01260"></a>01260 <span class="comment">// mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) {</span> |
---|
939 | <a name="l01261"></a>01261 <span class="comment">// int i;</span> |
---|
940 | <a name="l01262"></a>01262 <span class="comment">// int dim = rv.count();</span> |
---|
941 | <a name="l01263"></a>01263 <span class="comment">// mat Smp ( dim,n );</span> |
---|
942 | <a name="l01264"></a>01264 <span class="comment">// vec smp ( dim );</span> |
---|
943 | <a name="l01265"></a>01265 <span class="comment">// this->condition ( cond );</span> |
---|
944 | <a name="l01266"></a>01266 <span class="comment">//</span> |
---|
945 | <a name="l01267"></a>01267 <span class="comment">// for ( i=0; i<n; i++ ) {</span> |
---|
946 | <a name="l01268"></a>01268 <span class="comment">// smp = epdf.sample();</span> |
---|
947 | <a name="l01269"></a>01269 <span class="comment">// lik ( i ) = epdf.eval ( smp );</span> |
---|
948 | <a name="l01270"></a>01270 <span class="comment">// Smp.set_col ( i ,smp );</span> |
---|
949 | <a name="l01271"></a>01271 <span class="comment">// }</span> |
---|
950 | <a name="l01272"></a>01272 <span class="comment">//</span> |
---|
951 | <a name="l01273"></a>01273 <span class="comment">// return Smp;</span> |
---|
952 | <a name="l01274"></a>01274 <span class="comment">// }</span> |
---|
953 | <a name="l01275"></a>01275 |
---|
954 | <a name="l01276"></a>01276 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
955 | <a name="l01277"></a><a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">01277</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">mlnorm<sq_T>::condition</a> ( <span class="keyword">const</span> vec &cond ) |
---|
956 | <a name="l01278"></a>01278 { |
---|
957 | <a name="l01279"></a>01279 _mu = A*cond + mu_const; |
---|
958 | <a name="l01280"></a>01280 <span class="comment">//R is already assigned;</span> |
---|
959 | <a name="l01281"></a>01281 } |
---|
960 | <a name="l01282"></a>01282 |
---|
961 | <a name="l01283"></a>01283 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
962 | <a name="l01284"></a><a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80">01284</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">enorm<sq_T>::marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn )<span class="keyword"> const</span> |
---|
963 | <a name="l01285"></a>01285 <span class="keyword"> </span>{ |
---|
964 | <a name="l01286"></a>01286 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(), <span class="stringliteral">"rv description is not assigned"</span> ); |
---|
965 | <a name="l01287"></a>01287 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
---|
966 | <a name="l01288"></a>01288 |
---|
967 | <a name="l01289"></a>01289 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,irvn ); <span class="comment">//select rows and columns of R</span> |
---|
968 | <a name="l01290"></a>01290 |
---|
969 | <a name="l01291"></a>01291 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* tmp = <span class="keyword">new</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>; |
---|
970 | <a name="l01292"></a>01292 tmp-><a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
---|
971 | <a name="l01293"></a>01293 tmp-><a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ), Rn ); |
---|
972 | <a name="l01294"></a>01294 <span class="keywordflow">return</span> tmp; |
---|
973 | <a name="l01295"></a>01295 } |
---|
974 | <a name="l01296"></a>01296 |
---|
975 | <a name="l01297"></a>01297 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
976 | <a name="l01298"></a><a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26">01298</a> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">enorm<sq_T>::condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn )<span class="keyword"> const</span> |
---|
977 | <a name="l01299"></a>01299 <span class="keyword"> </span>{ |
---|
978 | <a name="l01300"></a>01300 |
---|
979 | <a name="l01301"></a>01301 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(),<span class="stringliteral">"rvs are not assigned"</span> ); |
---|
980 | <a name="l01302"></a>01302 |
---|
981 | <a name="l01303"></a>01303 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvc = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#aec44dabdf0a6d90fbae95e1356eda39" title="Subtract another variable from the current one.">subt</a> ( rvn ); |
---|
982 | <a name="l01304"></a>01304 it_assert_debug ( ( rvc.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() +rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ==<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ),<span class="stringliteral">"wrong rvn"</span> ); |
---|
983 | <a name="l01305"></a>01305 <span class="comment">//Permutation vector of the new R</span> |
---|
984 | <a name="l01306"></a>01306 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
---|
985 | <a name="l01307"></a>01307 ivec irvc = rvc.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
---|
986 | <a name="l01308"></a>01308 ivec perm=concat ( irvn , irvc ); |
---|
987 | <a name="l01309"></a>01309 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,perm ); |
---|
988 | <a name="l01310"></a>01310 |
---|
989 | <a name="l01311"></a>01311 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
---|
990 | <a name="l01312"></a>01312 mat S=Rn.to_mat(); |
---|
991 | <a name="l01313"></a>01313 <span class="comment">//fixme</span> |
---|
992 | <a name="l01314"></a>01314 <span class="keywordtype">int</span> n=rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>()-1; |
---|
993 | <a name="l01315"></a>01315 <span class="keywordtype">int</span> end=<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows()-1; |
---|
994 | <a name="l01316"></a>01316 mat S11 = S.get ( 0,n, 0, n ); |
---|
995 | <a name="l01317"></a>01317 mat S12 = S.get ( 0, n , rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
---|
996 | <a name="l01318"></a>01318 mat S22 = S.get ( rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end, rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
---|
997 | <a name="l01319"></a>01319 |
---|
998 | <a name="l01320"></a>01320 vec mu1 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ); |
---|
999 | <a name="l01321"></a>01321 vec mu2 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvc ); |
---|
1000 | <a name="l01322"></a>01322 mat A=S12*inv ( S22 ); |
---|
1001 | <a name="l01323"></a>01323 sq_T R_n ( S11 - A *S12.T() ); |
---|
1002 | <a name="l01324"></a>01324 |
---|
1003 | <a name="l01325"></a>01325 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a>* tmp=<span class="keyword">new</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a> ( ); |
---|
1004 | <a name="l01326"></a>01326 tmp->set_rv ( rvn ); tmp->set_rvc ( rvc ); |
---|
1005 | <a name="l01327"></a>01327 tmp->set_parameters ( A,mu1-A*mu2,R_n ); |
---|
1006 | <a name="l01328"></a>01328 <span class="keywordflow">return</span> tmp; |
---|
1007 | <a name="l01329"></a>01329 } |
---|
1008 | <a name="l01330"></a>01330 |
---|
1009 | <a name="l01332"></a>01332 |
---|
1010 | <a name="l01333"></a>01333 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
---|
1011 | <a name="l01334"></a>01334 std::ostream &operator<< ( std::ostream &os, mlnorm<sq_T> &ml ) |
---|
1012 | <a name="l01335"></a>01335 { |
---|
1013 | <a name="l01336"></a>01336 os << <span class="stringliteral">"A:"</span><< ml.A<<endl; |
---|
1014 | <a name="l01337"></a>01337 os << <span class="stringliteral">"mu:"</span><< ml.mu_const<<endl; |
---|
1015 | <a name="l01338"></a>01338 os << <span class="stringliteral">"R:"</span> << ml.epdf._R().to_mat() <<endl; |
---|
1016 | <a name="l01339"></a>01339 <span class="keywordflow">return</span> os; |
---|
1017 | <a name="l01340"></a>01340 }; |
---|
1018 | <a name="l01341"></a>01341 |
---|
1019 | <a name="l01342"></a>01342 } |
---|
1020 | <a name="l01343"></a>01343 <span class="preprocessor">#endif //EF_H</span> |
---|
1021 | </pre></div></div> |
---|
1022 | <hr size="1"><address style="text-align: right;"><small>Generated on Wed Jul 1 13:05:55 2009 for mixpp by |
---|
1023 | <a href="http://www.doxygen.org/index.html"> |
---|
1024 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
1025 | </body> |
---|
1026 | </html> |
---|