27 | | <a name="l00032"></a><a class="code" href="classemix.html">00032</a> <span class="keyword">class </span><a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a> : <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
28 | | <a name="l00033"></a>00033 <span class="keyword">protected</span>: |
29 | | <a name="l00035"></a><a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab">00035</a> vec <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>; |
30 | | <a name="l00037"></a><a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4">00037</a> Array<epdf*> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>; |
31 | | <a name="l00039"></a><a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8">00039</a> <span class="keywordtype">bool</span> <a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a>; |
32 | | <a name="l00040"></a>00040 <span class="keyword">public</span>: |
33 | | <a name="l00042"></a><a class="code" href="classemix.html#62194619791d5f1da88cad01cfc9339d">00042</a> <a class="code" href="classemix.html#62194619791d5f1da88cad01cfc9339d" title="Default constructor.">emix</a> (<span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) : <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {}; |
34 | | <a name="l00044"></a>00044 <span class="keywordtype">void</span> <a class="code" href="classemix.html#d3789d50a3327a6de552db077af5e4c5" title="Set weights w and components Coms , Coms are not copied!">set_parameters</a> ( <span class="keyword">const</span> vec &<a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>, <span class="keyword">const</span> Array<epdf*> &<a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>, <span class="keywordtype">bool</span> copy=<span class="keyword">true</span> ); |
35 | | <a name="l00045"></a>00045 |
36 | | <a name="l00046"></a>00046 vec <a class="code" href="classemix.html#0650601f24e633e0ab09aa1e46c14483" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
37 | | <a name="l00047"></a><a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8">00047</a> vec <a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
38 | | <a name="l00048"></a>00048 <span class="keywordtype">int</span> i; vec mu = zeros ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
39 | | <a name="l00049"></a>00049 <span class="keywordflow">for</span> ( i = 0;i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length();i++ ) {mu += <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) * <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )->mean(); } |
40 | | <a name="l00050"></a>00050 <span class="keywordflow">return</span> mu; |
41 | | <a name="l00051"></a>00051 } |
42 | | <a name="l00052"></a><a class="code" href="classemix.html#469e910479b3402589104ef3bb1b5741">00052</a> <span class="keywordtype">double</span> <a class="code" href="classemix.html#469e910479b3402589104ef3bb1b5741" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
43 | | <a name="l00053"></a>00053 <span class="keywordtype">int</span> i; |
44 | | <a name="l00054"></a>00054 <span class="keywordtype">double</span> sum = 0.0; |
45 | | <a name="l00055"></a>00055 <span class="keywordflow">for</span> ( i = 0;i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length();i++ ) {sum += <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) * <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )->evalpdflog ( val );} |
46 | | <a name="l00056"></a>00056 <span class="keywordflow">return</span> log ( sum ); |
47 | | <a name="l00057"></a>00057 }; |
48 | | <a name="l00058"></a>00058 |
49 | | <a name="l00059"></a>00059 <span class="comment">//Access methods</span> |
50 | | <a name="l00061"></a><a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8">00061</a> <span class="comment"></span> vec& <a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8" title="returns a pointer to the internal mean value. Use with Care!">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>;} |
51 | | <a name="l00062"></a>00062 <span class="keyword">virtual</span> ~<a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a>(){<span class="keywordflow">if</span> (<a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a>){<span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<<a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>.length();i++){<span class="keyword">delete</span> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>(i);}}} |
52 | | <a name="l00064"></a><a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d">00064</a> <span class="keywordtype">void</span> <a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d" title="Auxiliary function for taking ownership of the Coms().">ownComs</a>(){<a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a>=<span class="keyword">true</span>;} |
53 | | <a name="l00065"></a>00065 }; |
54 | | <a name="l00066"></a>00066 |
55 | | <a name="l00075"></a><a class="code" href="classmprod.html">00075</a> <span class="keyword">class </span><a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>: <span class="keyword">public</span> <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes.">compositepdf</a>, <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
56 | | <a name="l00076"></a>00076 <span class="keyword">protected</span>: |
57 | | <a name="l00078"></a><a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e">00078</a> Array<epdf*> <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a>; |
58 | | <a name="l00080"></a><a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6">00080</a> Array<ivec> <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>; |
59 | | <a name="l00081"></a>00081 <span class="keyword">public</span>: |
60 | | <a name="l00085"></a><a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4">00085</a> <a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4" title="Constructor from list of mFacs, Additional parameter overlap is left for future use...">mprod</a> ( Array<mpdf*> mFacs): <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes.">compositepdf</a>(mFacs), <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>(<a class="code" href="classcompositepdf.html#635d219fb3e32852400d6f98aa4bdc93" title="find common rv, flag">getrv</a>(true),<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>()), <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a>(<a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a>), <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>(<a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a>) |
61 | | <a name="l00086"></a>00086 { <a class="code" href="classcompositepdf.html#5a4479785c1fdb2cc351fbea07b899ac" title="common rvc of all mpdfs is written to rvc">setrvc</a>(<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>,<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a>); |
62 | | <a name="l00087"></a>00087 <a class="code" href="classcompositepdf.html#3bd4ada95f381ea6c4cff2dc86e957c4" title="Function fills Array by indeces of mpdfs inside given rv.">setrvcinrv</a>(<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a>,<a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>); |
63 | | <a name="l00088"></a>00088 <a class="code" href="classcompositepdf.html#08958c8f76d65de94ecc37b8d90bc77a" title="fill all rv*inrv* according to">setindices</a>(<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>); |
64 | | <a name="l00089"></a>00089 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<<a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a>;i++){<a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a>(i)=&(<a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a>(i)->_epdf());} |
65 | | <a name="l00090"></a>00090 }; |
66 | | <a name="l00091"></a>00091 |
67 | | <a name="l00092"></a>00092 <span class="keywordtype">double</span> evalpdflog ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
68 | | <a name="l00093"></a>00093 <span class="keywordtype">int</span> i; |
69 | | <a name="l00094"></a>00094 <span class="keywordtype">double</span> res = 0.0; |
70 | | <a name="l00095"></a>00095 <span class="keywordflow">for</span> ( i = <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1;i > 0;i++ ) { |
71 | | <a name="l00096"></a>00096 <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() > 0 ) |
72 | | <a name="l00097"></a>00097 {<a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->condition ( val ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ) ) );} |
73 | | <a name="l00098"></a>00098 <span class="comment">// add logarithms</span> |
74 | | <a name="l00099"></a>00099 res += <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->evalpdflog ( val ( <a class="code" href="classcompositepdf.html#4d4a8269f9faefeca8cdc251a5a29a7f" title="Indeces of rvs in common rv.">rvsinrv</a> ( i ) ) ); |
75 | | <a name="l00100"></a>00100 } |
76 | | <a name="l00101"></a>00101 <span class="keywordflow">return</span> res; |
77 | | <a name="l00102"></a>00102 } |
78 | | <a name="l00103"></a><a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68">00103</a> vec <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( <span class="keyword">const</span> vec &cond, <span class="keywordtype">double</span> &ll ) { |
79 | | <a name="l00104"></a>00104 vec smp=zeros ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
80 | | <a name="l00105"></a>00105 vec condi; |
81 | | <a name="l00106"></a>00106 vec smpi; |
82 | | <a name="l00107"></a>00107 ll = 0; |
83 | | <a name="l00108"></a>00108 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1 );i >= 0;i-- ) { |
84 | | <a name="l00109"></a>00109 <span class="keywordflow">if</span> (( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() > 0 )||( <a class="code" href="classcompositepdf.html#3df07bb5e3ed36a3119b145043296676" title="Indeces of rvc in common rv.">rvcsinrv</a> ( i ).length() > 0 )) { |
85 | | <a name="l00110"></a>00110 condi = zeros ( <a class="code" href="classcompositepdf.html#3df07bb5e3ed36a3119b145043296676" title="Indeces of rvc in common rv.">rvcsinrv</a>(i).length() + <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>(i).length() ); |
86 | | <a name="l00111"></a>00111 <span class="comment">// copy data in condition</span> |
87 | | <a name="l00112"></a>00112 set_subvector ( condi,<a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ), cond ); |
88 | | <a name="l00113"></a>00113 <span class="comment">// copy data in already generated sample</span> |
89 | | <a name="l00114"></a>00114 set_subvector ( condi,<a class="code" href="classcompositepdf.html#de3bd289a26d5549dcf1ed19e5b13569" title="Indeces of common rv in rvc.">rvinrvcs</a> ( i ), get_vec(smp,<a class="code" href="classcompositepdf.html#3df07bb5e3ed36a3119b145043296676" title="Indeces of rvc in common rv.">rvcsinrv</a>(i)) ); |
90 | | <a name="l00115"></a>00115 |
91 | | <a name="l00116"></a>00116 <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->condition ( condi ); |
92 | | <a name="l00117"></a>00117 } |
93 | | <a name="l00118"></a>00118 smpi = <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->sample(); |
94 | | <a name="l00119"></a>00119 <span class="comment">// copy contribution of this pdf into smp</span> |
95 | | <a name="l00120"></a>00120 set_subvector ( smp,<a class="code" href="classcompositepdf.html#4d4a8269f9faefeca8cdc251a5a29a7f" title="Indeces of rvs in common rv.">rvsinrv</a> ( i ), smpi ); |
96 | | <a name="l00121"></a>00121 <span class="comment">// add ith likelihood contribution</span> |
97 | | <a name="l00122"></a>00122 ll+=<a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->evalpdflog ( smpi ); |
98 | | <a name="l00123"></a>00123 } |
99 | | <a name="l00124"></a>00124 <span class="keywordflow">return</span> smp; |
100 | | <a name="l00125"></a>00125 } |
101 | | <a name="l00126"></a><a class="code" href="classmprod.html#e171c40e210539c2af01d6237785620b">00126</a> mat <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( <span class="keyword">const</span> vec &cond, vec &ll, <span class="keywordtype">int</span> N ) { |
102 | | <a name="l00127"></a>00127 mat Smp ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(),N ); |
103 | | <a name="l00128"></a>00128 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<N;i++ ) {Smp.set_col ( i,<a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( cond,ll ( i ) ) );} |
104 | | <a name="l00129"></a>00129 <span class="keywordflow">return</span> Smp; |
105 | | <a name="l00130"></a>00130 } |
106 | | <a name="l00131"></a>00131 |
107 | | <a name="l00132"></a>00132 ~<a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>() {}; |
108 | | <a name="l00133"></a>00133 }; |
| 27 | <a name="l00022"></a>00022 <span class="comment">//this comes first because it is used inside emix!</span> |
| 28 | <a name="l00023"></a>00023 |
| 29 | <a name="l00036"></a><a class="code" href="classmratio.html">00036</a> <span class="keyword">class </span><a class="code" href="classmratio.html" title="Class representing ratio of two densities which arise e.g. by applying the Bayes...">mratio</a>: <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
| 30 | <a name="l00037"></a>00037 <span class="keyword">protected</span>: |
| 31 | <a name="l00039"></a><a class="code" href="classmratio.html#8a3e60f5a532237e4450cd06039a28db">00039</a> <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classmratio.html#8a3e60f5a532237e4450cd06039a28db" title="Nominator in the form of mpdf.">nom</a>; |
| 32 | <a name="l00041"></a><a class="code" href="classmratio.html#d34916f6403460fbcac71902f32aa791">00041</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classmratio.html#d34916f6403460fbcac71902f32aa791" title="Denominator in the form of epdf.">den</a>; |
| 33 | <a name="l00043"></a><a class="code" href="classmratio.html#f8ea9dd72239dc24b1d83ae034424285">00043</a> <span class="keywordtype">bool</span> <a class="code" href="classmratio.html#f8ea9dd72239dc24b1d83ae034424285" title="flag for destructor">destroynom</a>; |
| 34 | <a name="l00045"></a><a class="code" href="classmratio.html#aa50f2cca2b959391f449241ef89012d">00045</a> <a class="code" href="classdatalink__m2e.html" title="data link between">datalink_m2e</a> <a class="code" href="classmratio.html#aa50f2cca2b959391f449241ef89012d" title="datalink between conditional and nom">dl</a>; |
| 35 | <a name="l00046"></a>00046 <span class="keyword">public</span>: |
| 36 | <a name="l00049"></a><a class="code" href="classmratio.html#c2452f4fc3046cfe8f2453deb343b3ac">00049</a> <a class="code" href="classmratio.html#c2452f4fc3046cfe8f2453deb343b3ac">mratio</a> ( <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* nom0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <span class="keywordtype">bool</span> copy=<span class="keyword">false</span> ) :<a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv,nom0-><a class="code" href="classmpdf.html#71256ffb5fbd08f41d650e606a5bd585" title="access function">_rv</a>().subt ( rv ) ), <a class="code" href="classmratio.html#aa50f2cca2b959391f449241ef89012d" title="datalink between conditional and nom">dl</a> ( rv,<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a>,nom0-><a class="code" href="classmpdf.html#71256ffb5fbd08f41d650e606a5bd585" title="access function">_rv</a>() ) { |
| 37 | <a name="l00050"></a>00050 <span class="keywordflow">if</span> ( copy ) { |
| 38 | <a name="l00051"></a>00051 <span class="comment">// nom = nom0->_copy_();</span> |
| 39 | <a name="l00052"></a>00052 it_error ( <span class="stringliteral">"todo"</span> ); |
| 40 | <a name="l00053"></a>00053 <a class="code" href="classmratio.html#f8ea9dd72239dc24b1d83ae034424285" title="flag for destructor">destroynom</a>=<span class="keyword">true</span>; |
| 41 | <a name="l00054"></a>00054 } |
| 42 | <a name="l00055"></a>00055 <span class="keywordflow">else</span> { |
| 43 | <a name="l00056"></a>00056 <a class="code" href="classmratio.html#8a3e60f5a532237e4450cd06039a28db" title="Nominator in the form of mpdf.">nom</a> = nom0; |
| 44 | <a name="l00057"></a>00057 <a class="code" href="classmratio.html#f8ea9dd72239dc24b1d83ae034424285" title="flag for destructor">destroynom</a> = <span class="keyword">false</span>; |
| 45 | <a name="l00058"></a>00058 } |
| 46 | <a name="l00059"></a>00059 it_assert_debug ( <a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a>.<a class="code" href="classRV.html#c114a6f3ff06796cc2f4dacba74291eb" title="Return length (number of entries) of the RV.">length</a>() >0,<span class="stringliteral">"Makes no sense to use this object!"</span> ); |
| 47 | <a name="l00060"></a>00060 <a class="code" href="classmratio.html#d34916f6403460fbcac71902f32aa791" title="Denominator in the form of epdf.">den</a> = <a class="code" href="classmratio.html#8a3e60f5a532237e4450cd06039a28db" title="Nominator in the form of mpdf.">nom</a>-><a class="code" href="classepdf.html#38de9f59b65ee06028554f3f74b66025" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
| 48 | <a name="l00061"></a>00061 }; |
| 49 | <a name="l00062"></a><a class="code" href="classmratio.html#6d440ca39571004425c2bffbc227d3dc">00062</a> <span class="keywordtype">double</span> <a class="code" href="classmratio.html#6d440ca39571004425c2bffbc227d3dc" title="Shortcut for conditioning and evaluation of the internal epdf. In some cases, this...">evalcond</a> ( <span class="keyword">const</span> vec &val, <span class="keyword">const</span> vec &cond ) { |
| 50 | <a name="l00063"></a>00063 vec nom_val ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() +<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
| 51 | <a name="l00064"></a>00064 <a class="code" href="classmratio.html#aa50f2cca2b959391f449241ef89012d" title="datalink between conditional and nom">dl</a>.<a class="code" href="classdatalink__m2e.html#bbe57e0c65273ff237ca6c98bdf0b09c">fill_val_cond</a> ( nom_val,val,cond ); |
| 52 | <a name="l00065"></a>00065 <span class="keywordflow">return</span> exp ( <a class="code" href="classmratio.html#8a3e60f5a532237e4450cd06039a28db" title="Nominator in the form of mpdf.">nom</a>-><a class="code" href="classepdf.html#6aef3eca74899692503769c18add1a4c" title="Compute log-probability of argument val.">evalpdflog</a> ( nom_val ) - <a class="code" href="classmratio.html#d34916f6403460fbcac71902f32aa791" title="Denominator in the form of epdf.">den</a>-><a class="code" href="classepdf.html#6aef3eca74899692503769c18add1a4c" title="Compute log-probability of argument val.">evalpdflog</a> ( cond ) ); |
| 53 | <a name="l00066"></a>00066 } |
| 54 | <a name="l00068"></a><a class="code" href="classmratio.html#41d6d8f4245f67c732299ba7167aacb9">00068</a> <span class="keywordtype">void</span> <a class="code" href="classmratio.html#41d6d8f4245f67c732299ba7167aacb9" title="Object takes ownership of nom and will destroy it.">ownnom</a>() {<a class="code" href="classmratio.html#f8ea9dd72239dc24b1d83ae034424285" title="flag for destructor">destroynom</a>=<span class="keyword">true</span>;} |
| 55 | <a name="l00070"></a><a class="code" href="classmratio.html#e62904f18041e73228d8db671e517280">00070</a> <a class="code" href="classmratio.html#e62904f18041e73228d8db671e517280" title="Default destructor.">~mratio</a>() {<span class="keyword">delete</span> <a class="code" href="classmratio.html#d34916f6403460fbcac71902f32aa791" title="Denominator in the form of epdf.">den</a>; <span class="keywordflow">if</span> ( <a class="code" href="classmratio.html#f8ea9dd72239dc24b1d83ae034424285" title="flag for destructor">destroynom</a> ) {<span class="keyword">delete</span> <a class="code" href="classmratio.html#8a3e60f5a532237e4450cd06039a28db" title="Nominator in the form of mpdf.">nom</a>;}} |
| 56 | <a name="l00071"></a>00071 }; |
| 57 | <a name="l00072"></a>00072 |
| 58 | <a name="l00083"></a><a class="code" href="classemix.html">00083</a> <span class="keyword">class </span><a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a> : <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
| 59 | <a name="l00084"></a>00084 <span class="keyword">protected</span>: |
| 60 | <a name="l00086"></a><a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab">00086</a> vec <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>; |
| 61 | <a name="l00088"></a><a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4">00088</a> Array<epdf*> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>; |
| 62 | <a name="l00090"></a><a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8">00090</a> <span class="keywordtype">bool</span> <a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a>; |
| 63 | <a name="l00091"></a>00091 <span class="keyword">public</span>: |
| 64 | <a name="l00093"></a><a class="code" href="classemix.html#62194619791d5f1da88cad01cfc9339d">00093</a> <a class="code" href="classemix.html#62194619791d5f1da88cad01cfc9339d" title="Default constructor.">emix</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) : <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {}; |
| 65 | <a name="l00096"></a>00096 <span class="keywordtype">void</span> <a class="code" href="classemix.html#d3789d50a3327a6de552db077af5e4c5">set_parameters</a> ( <span class="keyword">const</span> vec &<a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>, <span class="keyword">const</span> Array<epdf*> &<a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>, <span class="keywordtype">bool</span> copy=<span class="keyword">true</span> ); |
| 66 | <a name="l00097"></a>00097 |
| 67 | <a name="l00098"></a>00098 vec <a class="code" href="classemix.html#0650601f24e633e0ab09aa1e46c14483" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 68 | <a name="l00099"></a><a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8">00099</a> vec <a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 69 | <a name="l00100"></a>00100 <span class="keywordtype">int</span> i; vec mu = zeros ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
| 70 | <a name="l00101"></a>00101 <span class="keywordflow">for</span> ( i = 0;i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length();i++ ) {mu += <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) * <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )->mean(); } |
| 71 | <a name="l00102"></a>00102 <span class="keywordflow">return</span> mu; |
| 72 | <a name="l00103"></a>00103 } |
| 73 | <a name="l00104"></a><a class="code" href="classemix.html#469e910479b3402589104ef3bb1b5741">00104</a> <span class="keywordtype">double</span> <a class="code" href="classemix.html#469e910479b3402589104ef3bb1b5741" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
| 74 | <a name="l00105"></a>00105 <span class="keywordtype">int</span> i; |
| 75 | <a name="l00106"></a>00106 <span class="keywordtype">double</span> sum = 0.0; |
| 76 | <a name="l00107"></a>00107 <span class="keywordflow">for</span> ( i = 0;i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length();i++ ) {sum += <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) * exp ( <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classemix.html#469e910479b3402589104ef3bb1b5741" title="Compute log-probability of argument val.">evalpdflog</a> ( val ) );} |
| 77 | <a name="l00108"></a>00108 <span class="keywordflow">return</span> log ( sum ); |
| 78 | <a name="l00109"></a>00109 }; |
| 79 | <a name="l00110"></a><a class="code" href="classemix.html#375bfba7c79915c88c2e612bcf83dacb">00110</a> vec <a class="code" href="classemix.html#375bfba7c79915c88c2e612bcf83dacb" title="Compute log-probability of multiple values argument val.">evalpdflog_m</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
| 80 | <a name="l00111"></a>00111 vec x=zeros ( Val.cols() ); |
| 81 | <a name="l00112"></a>00112 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(); i++ ) { |
| 82 | <a name="l00113"></a>00113 x+= <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) *exp ( <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classemix.html#375bfba7c79915c88c2e612bcf83dacb" title="Compute log-probability of multiple values argument val.">evalpdflog_m</a> ( Val ) ); |
| 83 | <a name="l00114"></a>00114 } |
| 84 | <a name="l00115"></a>00115 <span class="keywordflow">return</span> log ( x ); |
| 85 | <a name="l00116"></a>00116 }; |
| 86 | <a name="l00117"></a>00117 mat evalpdflog_M ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
| 87 | <a name="l00118"></a>00118 mat X ( <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(), Val.cols() ); |
| 88 | <a name="l00119"></a>00119 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(); i++ ) { |
| 89 | <a name="l00120"></a>00120 X.set_row ( i, <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) *exp ( <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classemix.html#375bfba7c79915c88c2e612bcf83dacb" title="Compute log-probability of multiple values argument val.">evalpdflog_m</a> ( Val ) ) ); |
| 90 | <a name="l00121"></a>00121 } |
| 91 | <a name="l00122"></a>00122 <span class="keywordflow">return</span> X; |
| 92 | <a name="l00123"></a>00123 }; |
| 93 | <a name="l00124"></a>00124 |
| 94 | <a name="l00125"></a>00125 <a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a>* <a class="code" href="classemix.html#33afde698093d458ce71875f7ee7384a" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; |
| 95 | <a name="l00126"></a>00126 <a class="code" href="classmratio.html" title="Class representing ratio of two densities which arise e.g. by applying the Bayes...">mratio</a>* <a class="code" href="classemix.html#ebf50c387034f72040c83d38738549b3" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; <span class="comment">//why not mratio!!</span> |
| 96 | <a name="l00127"></a>00127 |
| 97 | <a name="l00128"></a>00128 <span class="comment">//Access methods</span> |
| 98 | <a name="l00130"></a><a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8">00130</a> <span class="comment"></span> vec& <a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8" title="returns a pointer to the internal mean value. Use with Care!">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>;} |
| 99 | <a name="l00131"></a>00131 <span class="keyword">virtual</span> ~<a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a>() {<span class="keywordflow">if</span> ( <a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a> ) {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i );}}} |
| 100 | <a name="l00133"></a><a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d">00133</a> <span class="keywordtype">void</span> <a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d" title="Auxiliary function for taking ownership of the Coms().">ownComs</a>() {<a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a>=<span class="keyword">true</span>;} |
110 | | <a name="l00136"></a><a class="code" href="classeprod.html">00136</a> <span class="keyword">class </span><a class="code" href="classeprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a>: <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
111 | | <a name="l00137"></a>00137 <span class="keyword">protected</span>: |
112 | | <a name="l00139"></a><a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357">00139</a> Array<const epdf*> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>; |
113 | | <a name="l00141"></a><a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3">00141</a> Array<ivec> <a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a>; |
114 | | <a name="l00142"></a>00142 <span class="keyword">public</span>: |
115 | | <a name="l00143"></a>00143 <a class="code" href="classeprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a> ( <span class="keyword">const</span> Array<const epdf*> epdfs0 ) : <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>() ),<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( epdfs0 ),<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length() ) { |
116 | | <a name="l00144"></a>00144 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
117 | | <a name="l00145"></a>00145 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
118 | | <a name="l00146"></a>00146 independent=<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#935790526b630dec4ffefa9ec0c2b6fb" title="Add (concat) another variable to the current one,.">add</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() ); |
119 | | <a name="l00147"></a>00147 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent ."</span> ); |
120 | | <a name="l00148"></a>00148 <a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ) = ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->_rv() ).dataind ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
121 | | <a name="l00149"></a>00149 } |
122 | | <a name="l00150"></a>00150 } |
123 | | <a name="l00151"></a>00151 |
124 | | <a name="l00152"></a><a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7">00152</a> vec <a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
125 | | <a name="l00153"></a>00153 vec tmp ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
126 | | <a name="l00154"></a>00154 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
127 | | <a name="l00155"></a>00155 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
128 | | <a name="l00156"></a>00156 set_subvector ( tmp,<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ), pom ); |
129 | | <a name="l00157"></a>00157 } |
130 | | <a name="l00158"></a>00158 <span class="keywordflow">return</span> tmp; |
131 | | <a name="l00159"></a>00159 } |
132 | | <a name="l00160"></a><a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4">00160</a> vec <a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
133 | | <a name="l00161"></a>00161 vec tmp ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
134 | | <a name="l00162"></a>00162 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
135 | | <a name="l00163"></a>00163 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
136 | | <a name="l00164"></a>00164 set_subvector ( tmp,<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ), pom ); |
| 102 | <a name="l00136"></a><a class="code" href="classemix.html#95d175b2daa1d896ceffd69b70e02efb">00136</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classemix.html#95d175b2daa1d896ceffd69b70e02efb" title="access function">_Coms</a> ( <span class="keywordtype">int</span> i ) {<span class="keywordflow">return</span> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i );} |
| 103 | <a name="l00137"></a>00137 }; |
| 104 | <a name="l00138"></a>00138 |
| 105 | <a name="l00147"></a><a class="code" href="classmprod.html">00147</a> <span class="keyword">class </span><a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>: <span class="keyword">public</span> <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes this abstract class is...">compositepdf</a>, <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
| 106 | <a name="l00148"></a>00148 <span class="keyword">protected</span>: |
| 107 | <a name="l00150"></a><a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e">00150</a> Array<epdf*> <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a>; |
| 108 | <a name="l00152"></a><a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c">00152</a> Array<datalink_m2m*> <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a>; |
| 109 | <a name="l00153"></a>00153 <span class="keyword">public</span>: |
| 110 | <a name="l00156"></a><a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4">00156</a> <a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4" title="Constructor from list of mFacs,.">mprod</a> ( Array<mpdf*> mFacs ) : <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes this abstract class is...">compositepdf</a> ( mFacs ), <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( <a class="code" href="classcompositepdf.html#635d219fb3e32852400d6f98aa4bdc93" title="find common rv, flag">getrv</a> ( true ),<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>() ), <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> ), <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> ) { |
| 111 | <a name="l00157"></a>00157 <a class="code" href="classcompositepdf.html#5a4479785c1fdb2cc351fbea07b899ac" title="common rvc of all mpdfs is written to rvc">setrvc</a> ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>,<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
| 112 | <a name="l00158"></a>00158 <span class="comment">// rv and rvc established = > we can link them with mpdfs</span> |
| 113 | <a name="l00159"></a>00159 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a>;i++ ) { |
| 114 | <a name="l00160"></a>00160 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classdatalink__m2m.html">datalink_m2m</a> ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classmpdf.html#71256ffb5fbd08f41d650e606a5bd585" title="access function">_rv</a>(), <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classmpdf.html#15ef062183b1ccdf794732d5fa0b77cd" title="access function">_rvc</a>(), <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
| 115 | <a name="l00161"></a>00161 } |
| 116 | <a name="l00162"></a>00162 |
| 117 | <a name="l00163"></a>00163 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<n;i++ ) { |
| 118 | <a name="l00164"></a>00164 <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i ) =& ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->_epdf() ); |
138 | | <a name="l00166"></a>00166 <span class="keywordflow">return</span> tmp; |
139 | | <a name="l00167"></a>00167 } |
140 | | <a name="l00168"></a><a class="code" href="classeprod.html#5adef154e3655a872c284b02635b8b35">00168</a> <span class="keywordtype">double</span> <a class="code" href="classeprod.html#5adef154e3655a872c284b02635b8b35" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
141 | | <a name="l00169"></a>00169 <span class="keywordtype">double</span> tmp=0; |
142 | | <a name="l00170"></a>00170 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
143 | | <a name="l00171"></a>00171 tmp+=<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>(i)->evalpdflog(val(<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a>(i))); |
144 | | <a name="l00172"></a>00172 } |
145 | | <a name="l00173"></a>00173 <span class="keywordflow">return</span> tmp; |
146 | | <a name="l00174"></a>00174 } |
147 | | <a name="l00176"></a><a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f">00176</a> <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f" title="access function">operator () </a>(<span class="keywordtype">int</span> i)<span class="keyword"> const </span>{it_assert_debug(i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length(),<span class="stringliteral">"wrong index"</span>);<span class="keywordflow">return</span> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>(i);} |
148 | | <a name="l00177"></a>00177 }; |
149 | | <a name="l00178"></a>00178 |
150 | | <a name="l00179"></a>00179 |
151 | | <a name="l00183"></a><a class="code" href="classmmix.html">00183</a> <span class="keyword">class </span><a class="code" href="classmmix.html" title="Mixture of mpdfs with constant weights, all mpdfs are of equal type.">mmix</a> : <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
152 | | <a name="l00184"></a>00184 <span class="keyword">protected</span>: |
153 | | <a name="l00186"></a><a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f">00186</a> Array<mpdf*> <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>; |
154 | | <a name="l00188"></a><a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914">00188</a> <a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a> <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>; |
155 | | <a name="l00189"></a>00189 <span class="keyword">public</span>: |
156 | | <a name="l00191"></a><a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3">00191</a> <a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3" title="Default constructor.">mmix</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ) : <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv, rvc ), <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a> ( rv ) {<a class="code" href="classmpdf.html#7aa894208a32f3487827df6d5054424c" title="pointer to internal epdf">ep</a> = &<a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>;}; |
157 | | <a name="l00193"></a><a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d">00193</a> <span class="keywordtype">void</span> <a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d" title="Set weights w and components R.">set_parameters</a> ( <span class="keyword">const</span> vec &w, <span class="keyword">const</span> Array<mpdf*> &<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ) { |
158 | | <a name="l00194"></a>00194 Array<epdf*> Eps ( Coms.length() ); |
159 | | <a name="l00195"></a>00195 |
160 | | <a name="l00196"></a>00196 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
161 | | <a name="l00197"></a>00197 Eps ( i ) = & ( <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
162 | | <a name="l00198"></a>00198 } |
163 | | <a name="l00199"></a>00199 <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>.<a class="code" href="classemix.html#d3789d50a3327a6de552db077af5e4c5" title="Set weights w and components Coms , Coms are not copied!">set_parameters</a> ( w, Eps ); |
164 | | <a name="l00200"></a>00200 }; |
165 | | <a name="l00201"></a>00201 |
166 | | <a name="l00202"></a><a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193">00202</a> <span class="keywordtype">void</span> <a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &cond ) { |
167 | | <a name="l00203"></a>00203 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>.length();i++ ) {<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )->condition ( cond );} |
168 | | <a name="l00204"></a>00204 }; |
169 | | <a name="l00205"></a>00205 }; |
170 | | <a name="l00206"></a>00206 <span class="preprocessor">#endif //MX_H</span> |
| 120 | <a name="l00166"></a>00166 }; |
| 121 | <a name="l00167"></a>00167 |
| 122 | <a name="l00168"></a><a class="code" href="classmprod.html#1e662c8d90a96bf19235a05373d6887a">00168</a> <span class="keywordtype">double</span> <a class="code" href="classmprod.html#1e662c8d90a96bf19235a05373d6887a" title="Shortcut for conditioning and evaluation of the internal epdf. In some cases, this...">evalcond</a> ( <span class="keyword">const</span> vec &val, <span class="keyword">const</span> vec &cond ) { |
| 123 | <a name="l00169"></a>00169 <span class="keywordtype">int</span> i; |
| 124 | <a name="l00170"></a>00170 <span class="keywordtype">double</span> res = 1.0; |
| 125 | <a name="l00171"></a>00171 <span class="keywordflow">for</span> ( i = <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1;i >= 0;i-- ) { |
| 126 | <a name="l00172"></a>00172 <span class="comment">/* if ( mpdfs(i)->_rvc().count() >0) {</span> |
| 127 | <a name="l00173"></a>00173 <span class="comment"> mpdfs ( i )->condition ( dls ( i )->get_cond ( val,cond ) );</span> |
| 128 | <a name="l00174"></a>00174 <span class="comment"> }</span> |
| 129 | <a name="l00175"></a>00175 <span class="comment"> // add logarithms</span> |
| 130 | <a name="l00176"></a>00176 <span class="comment"> res += epdfs ( i )->evalpdflog ( dls ( i )->get_val ( val ) );*/</span> |
| 131 | <a name="l00177"></a>00177 res *= <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->evalcond ( |
| 132 | <a name="l00178"></a>00178 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_val ( val ), |
| 133 | <a name="l00179"></a>00179 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( val, cond ) |
| 134 | <a name="l00180"></a>00180 ); |
| 135 | <a name="l00181"></a>00181 } |
| 136 | <a name="l00182"></a>00182 <span class="keywordflow">return</span> res; |
| 137 | <a name="l00183"></a>00183 } |
| 138 | <a name="l00184"></a><a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68">00184</a> vec <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( <span class="keyword">const</span> vec &cond, <span class="keywordtype">double</span> &ll ) { |
| 139 | <a name="l00186"></a>00186 vec smp= std::numeric_limits<double>::infinity() * ones ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
| 140 | <a name="l00187"></a>00187 vec smpi; |
| 141 | <a name="l00188"></a>00188 ll = 0; |
| 142 | <a name="l00189"></a>00189 <span class="comment">// Hard assumption here!!! We are going backwards, to assure that samples that are needed from smp are already generated!</span> |
| 143 | <a name="l00190"></a>00190 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1 );i >= 0;i-- ) { |
| 144 | <a name="l00191"></a>00191 <span class="keywordflow">if</span> ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->_rvc().count() ) { |
| 145 | <a name="l00192"></a>00192 <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->condition ( <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( smp ,cond ) ); <span class="comment">// smp is val here!!</span> |
| 146 | <a name="l00193"></a>00193 } |
| 147 | <a name="l00194"></a>00194 smpi = <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->sample(); |
| 148 | <a name="l00195"></a>00195 <span class="comment">// copy contribution of this pdf into smp</span> |
| 149 | <a name="l00196"></a>00196 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->fill_val ( smp, smpi ); |
| 150 | <a name="l00197"></a>00197 <span class="comment">// add ith likelihood contribution</span> |
| 151 | <a name="l00198"></a>00198 ll+=<a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->evalpdflog ( smpi ); |
| 152 | <a name="l00199"></a>00199 } |
| 153 | <a name="l00200"></a>00200 <span class="keywordflow">return</span> smp; |
| 154 | <a name="l00201"></a>00201 } |
| 155 | <a name="l00202"></a><a class="code" href="classmprod.html#e171c40e210539c2af01d6237785620b">00202</a> mat <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( <span class="keyword">const</span> vec &cond, vec &ll, <span class="keywordtype">int</span> N ) { |
| 156 | <a name="l00203"></a>00203 mat Smp ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(),N ); |
| 157 | <a name="l00204"></a>00204 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<N;i++ ) {Smp.set_col ( i,<a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( cond,ll ( i ) ) );} |
| 158 | <a name="l00205"></a>00205 <span class="keywordflow">return</span> Smp; |
| 159 | <a name="l00206"></a>00206 } |
| 160 | <a name="l00207"></a>00207 |
| 161 | <a name="l00208"></a>00208 ~<a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>() {}; |
| 162 | <a name="l00209"></a>00209 }; |
| 163 | <a name="l00210"></a>00210 |
| 164 | <a name="l00212"></a><a class="code" href="classeprod.html">00212</a> <span class="keyword">class </span><a class="code" href="classeprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a>: <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
| 165 | <a name="l00213"></a>00213 <span class="keyword">protected</span>: |
| 166 | <a name="l00215"></a><a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357">00215</a> Array<const epdf*> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>; |
| 167 | <a name="l00217"></a><a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29">00217</a> Array<datalink_e2e*> <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a>; |
| 168 | <a name="l00218"></a>00218 <span class="keyword">public</span>: |
| 169 | <a name="l00219"></a>00219 <a class="code" href="classeprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a> ( <span class="keyword">const</span> Array<const epdf*> epdfs0 ) : <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>() ),<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( epdfs0 ),<a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length() ) { |
| 170 | <a name="l00220"></a>00220 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
| 171 | <a name="l00221"></a>00221 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 172 | <a name="l00222"></a>00222 independent=<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#935790526b630dec4ffefa9ec0c2b6fb" title="Add (concat) another variable to the current one,.">add</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() ); |
| 173 | <a name="l00223"></a>00223 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent ."</span> ); |
| 174 | <a name="l00224"></a>00224 } |
| 175 | <a name="l00225"></a>00225 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 176 | <a name="l00226"></a>00226 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classdatalink__e2e.html">datalink_e2e</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() , <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
| 177 | <a name="l00227"></a>00227 } |
| 178 | <a name="l00228"></a>00228 } |
| 179 | <a name="l00229"></a>00229 |
| 180 | <a name="l00230"></a><a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7">00230</a> vec <a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 181 | <a name="l00231"></a>00231 vec tmp ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
| 182 | <a name="l00232"></a>00232 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 183 | <a name="l00233"></a>00233 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
| 184 | <a name="l00234"></a>00234 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
| 185 | <a name="l00235"></a>00235 } |
| 186 | <a name="l00236"></a>00236 <span class="keywordflow">return</span> tmp; |
| 187 | <a name="l00237"></a>00237 } |
| 188 | <a name="l00238"></a><a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4">00238</a> vec <a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 189 | <a name="l00239"></a>00239 vec tmp ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); |
| 190 | <a name="l00240"></a>00240 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 191 | <a name="l00241"></a>00241 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
| 192 | <a name="l00242"></a>00242 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
| 193 | <a name="l00243"></a>00243 } |
| 194 | <a name="l00244"></a>00244 <span class="keywordflow">return</span> tmp; |
| 195 | <a name="l00245"></a>00245 } |
| 196 | <a name="l00246"></a><a class="code" href="classeprod.html#5adef154e3655a872c284b02635b8b35">00246</a> <span class="keywordtype">double</span> <a class="code" href="classeprod.html#5adef154e3655a872c284b02635b8b35" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
| 197 | <a name="l00247"></a>00247 <span class="keywordtype">double</span> tmp=0; |
| 198 | <a name="l00248"></a>00248 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 199 | <a name="l00249"></a>00249 tmp+=<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->evalpdflog ( <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->get_val ( val ) ); |
| 200 | <a name="l00250"></a>00250 } |
| 201 | <a name="l00251"></a>00251 <span class="keywordflow">return</span> tmp; |
| 202 | <a name="l00252"></a>00252 } |
| 203 | <a name="l00254"></a><a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f">00254</a> <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f" title="access function">operator () </a>( <span class="keywordtype">int</span> i )<span class="keyword"> const </span>{it_assert_debug ( i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length(),<span class="stringliteral">"wrong index"</span> );<span class="keywordflow">return</span> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i );} |
| 204 | <a name="l00255"></a>00255 |
| 205 | <a name="l00257"></a><a class="code" href="classeprod.html#fe8cc34921cb43558654455007676f05">00257</a> <a class="code" href="classeprod.html#fe8cc34921cb43558654455007676f05" title="Destructor.">~eprod</a>() {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i );}} |
| 206 | <a name="l00258"></a>00258 }; |
| 207 | <a name="l00259"></a>00259 |
| 208 | <a name="l00260"></a>00260 |
| 209 | <a name="l00264"></a><a class="code" href="classmmix.html">00264</a> <span class="keyword">class </span><a class="code" href="classmmix.html" title="Mixture of mpdfs with constant weights, all mpdfs are of equal type.">mmix</a> : <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
| 210 | <a name="l00265"></a>00265 <span class="keyword">protected</span>: |
| 211 | <a name="l00267"></a><a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f">00267</a> Array<mpdf*> <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>; |
| 212 | <a name="l00269"></a><a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914">00269</a> <a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a> <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>; |
| 213 | <a name="l00270"></a>00270 <span class="keyword">public</span>: |
| 214 | <a name="l00272"></a><a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3">00272</a> <a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3" title="Default constructor.">mmix</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ) : <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv, rvc ), <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a> ( rv ) {<a class="code" href="classmpdf.html#7aa894208a32f3487827df6d5054424c" title="pointer to internal epdf">ep</a> = &<a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>;}; |
| 215 | <a name="l00274"></a><a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d">00274</a> <span class="keywordtype">void</span> <a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d" title="Set weights w and components R.">set_parameters</a> ( <span class="keyword">const</span> vec &w, <span class="keyword">const</span> Array<mpdf*> &<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ) { |
| 216 | <a name="l00275"></a>00275 Array<epdf*> Eps ( Coms.length() ); |
| 217 | <a name="l00276"></a>00276 |
| 218 | <a name="l00277"></a>00277 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
| 219 | <a name="l00278"></a>00278 Eps ( i ) = & ( <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
| 220 | <a name="l00279"></a>00279 } |
| 221 | <a name="l00280"></a>00280 <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>.<a class="code" href="classemix.html#d3789d50a3327a6de552db077af5e4c5">set_parameters</a> ( w, Eps ); |
| 222 | <a name="l00281"></a>00281 }; |
| 223 | <a name="l00282"></a>00282 |
| 224 | <a name="l00283"></a><a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193">00283</a> <span class="keywordtype">void</span> <a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &cond ) { |
| 225 | <a name="l00284"></a>00284 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>.length();i++ ) {<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )->condition ( cond );} |
| 226 | <a name="l00285"></a>00285 }; |
| 227 | <a name="l00286"></a>00286 }; |
| 228 | <a name="l00287"></a>00287 |
| 229 | <a name="l00288"></a>00288 <span class="preprocessor">#endif //MX_H</span> |