1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: work/git/mixpp/bdm/stat/emix.h Source File</title> |
---|
4 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.6 --> |
---|
8 | <div class="navigation" id="top"> |
---|
9 | <div class="tabs"> |
---|
10 | <ul> |
---|
11 | <li><a href="index.html"><span>Main Page</span></a></li> |
---|
12 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
13 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
14 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
15 | </ul> |
---|
16 | </div> |
---|
17 | <h1>work/git/mixpp/bdm/stat/emix.h</h1><a href="emix_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
18 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef MX_H</span> |
---|
19 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define MX_H</span> |
---|
20 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
21 | <a name="l00016"></a>00016 <span class="preprocessor">#include "<a class="code" href="libBM_8h.html" title="Bayesian Models (bm) that use Bayes rule to learn from observations.">libBM.h</a>"</span> |
---|
22 | <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="libEF_8h.html" title="Probability distributions for Exponential Family models.">libEF.h</a>"</span> |
---|
23 | <a name="l00018"></a>00018 <span class="comment">//#include <std></span> |
---|
24 | <a name="l00019"></a>00019 |
---|
25 | <a name="l00020"></a>00020 <span class="keyword">using namespace </span>itpp; |
---|
26 | <a name="l00021"></a>00021 |
---|
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="l00038"></a>00038 <span class="keyword">public</span>: |
---|
32 | <a name="l00040"></a><a class="code" href="classemix.html#3a10c8481115a5460877272ddb6532a6">00040</a> <a class="code" href="classemix.html#3a10c8481115a5460877272ddb6532a6" title="Default constructor.">emix</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) : <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {}; |
---|
33 | <a name="l00042"></a>00042 <span class="keywordtype">void</span> <a class="code" href="classemix.html#6ce82b24d7fe540ddbf44b472a005555" title="Set weights w and components R.">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> ); |
---|
34 | <a name="l00043"></a>00043 |
---|
35 | <a name="l00044"></a>00044 vec <a class="code" href="classemix.html#0650601f24e633e0ab09aa1e46c14483" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
36 | <a name="l00045"></a><a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8">00045</a> vec <a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
---|
37 | <a name="l00046"></a>00046 <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>() ); |
---|
38 | <a name="l00047"></a>00047 <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(); } |
---|
39 | <a name="l00048"></a>00048 <span class="keywordflow">return</span> mu; |
---|
40 | <a name="l00049"></a>00049 } |
---|
41 | <a name="l00050"></a><a class="code" href="classemix.html#469e910479b3402589104ef3bb1b5741">00050</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>{ |
---|
42 | <a name="l00051"></a>00051 <span class="keywordtype">int</span> i; |
---|
43 | <a name="l00052"></a>00052 <span class="keywordtype">double</span> sum = 0.0; |
---|
44 | <a name="l00053"></a>00053 <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 );} |
---|
45 | <a name="l00054"></a>00054 <span class="keywordflow">return</span> log ( sum ); |
---|
46 | <a name="l00055"></a>00055 }; |
---|
47 | <a name="l00056"></a>00056 |
---|
48 | <a name="l00057"></a>00057 <span class="comment">//Access methods</span> |
---|
49 | <a name="l00059"></a><a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8">00059</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>;} |
---|
50 | <a name="l00060"></a>00060 }; |
---|
51 | <a name="l00061"></a>00061 |
---|
52 | <a name="l00070"></a><a class="code" href="classmprod.html">00070</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> { |
---|
53 | <a name="l00071"></a>00071 <span class="keyword">protected</span>: |
---|
54 | <a name="l00072"></a>00072 <span class="comment">// pointers to epdfs</span> |
---|
55 | <a name="l00073"></a>00073 Array<epdf*> epdfs; |
---|
56 | <a name="l00075"></a><a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6">00075</a> Array<ivec> <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>; |
---|
57 | <a name="l00076"></a>00076 <span class="keyword">public</span>: |
---|
58 | <a name="l00080"></a><a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4">00080</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>(getrv(true),<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>()), epdfs(<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>) |
---|
59 | <a name="l00081"></a>00081 { setrvc(<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>); |
---|
60 | <a name="l00082"></a>00082 setrvcinrv(<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>); |
---|
61 | <a name="l00083"></a>00083 setindices(<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>); |
---|
62 | <a name="l00084"></a>00084 <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++){epdfs(i)=&(<a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a>(i)->_epdf());} |
---|
63 | <a name="l00085"></a>00085 }; |
---|
64 | <a name="l00086"></a>00086 |
---|
65 | <a name="l00087"></a>00087 <span class="keywordtype">double</span> evalpdflog ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
66 | <a name="l00088"></a>00088 <span class="keywordtype">int</span> i; |
---|
67 | <a name="l00089"></a>00089 <span class="keywordtype">double</span> res = 0.0; |
---|
68 | <a name="l00090"></a>00090 <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++ ) { |
---|
69 | <a name="l00091"></a>00091 <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() > 0 ) |
---|
70 | <a name="l00092"></a>00092 {<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 ) ) );} |
---|
71 | <a name="l00093"></a>00093 <span class="comment">// add logarithms</span> |
---|
72 | <a name="l00094"></a>00094 res += epdfs ( i )->evalpdflog ( val ( <a class="code" href="classcompositepdf.html#4d4a8269f9faefeca8cdc251a5a29a7f" title="Indeces of rvs in common rv.">rvsinrv</a> ( i ) ) ); |
---|
73 | <a name="l00095"></a>00095 } |
---|
74 | <a name="l00096"></a>00096 <span class="keywordflow">return</span> res; |
---|
75 | <a name="l00097"></a>00097 } |
---|
76 | <a name="l00098"></a><a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68">00098</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 ) { |
---|
77 | <a name="l00099"></a>00099 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>() ); |
---|
78 | <a name="l00100"></a>00100 vec condi; |
---|
79 | <a name="l00101"></a>00101 vec smpi; |
---|
80 | <a name="l00102"></a>00102 ll = 0; |
---|
81 | <a name="l00103"></a>00103 <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-- ) { |
---|
82 | <a name="l00104"></a>00104 <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() > 0 ) { |
---|
83 | <a name="l00105"></a>00105 condi = zeros ( <a class="code" href="classcompositepdf.html#3df07bb5e3ed36a3119b145043296676" title="Indeces of rvc in common rv.">rvcsinrv</a>.length() + <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>.length() ); |
---|
84 | <a name="l00106"></a>00106 <span class="comment">// copy data in condition</span> |
---|
85 | <a name="l00107"></a>00107 set_subvector ( condi,<a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ), cond ); |
---|
86 | <a name="l00108"></a>00108 <span class="comment">// copy data in already generated sample</span> |
---|
87 | <a name="l00109"></a>00109 set_subvector ( condi,<a class="code" href="classcompositepdf.html#3df07bb5e3ed36a3119b145043296676" title="Indeces of rvc in common rv.">rvcsinrv</a> ( i ), smp ); |
---|
88 | <a name="l00110"></a>00110 |
---|
89 | <a name="l00111"></a>00111 <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->condition ( condi ); |
---|
90 | <a name="l00112"></a>00112 } |
---|
91 | <a name="l00113"></a>00113 smpi = epdfs ( i )->sample(); |
---|
92 | <a name="l00114"></a>00114 <span class="comment">// copy contribution of this pdf into smp</span> |
---|
93 | <a name="l00115"></a>00115 set_subvector ( smp,<a class="code" href="classcompositepdf.html#4d4a8269f9faefeca8cdc251a5a29a7f" title="Indeces of rvs in common rv.">rvsinrv</a> ( i ), smpi ); |
---|
94 | <a name="l00116"></a>00116 <span class="comment">// add ith likelihood contribution</span> |
---|
95 | <a name="l00117"></a>00117 ll+=epdfs ( i )->evalpdflog ( smpi ); |
---|
96 | <a name="l00118"></a>00118 } |
---|
97 | <a name="l00119"></a>00119 <span class="keywordflow">return</span> smp; |
---|
98 | <a name="l00120"></a>00120 } |
---|
99 | <a name="l00121"></a><a class="code" href="classmprod.html#e171c40e210539c2af01d6237785620b">00121</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 ) { |
---|
100 | <a name="l00122"></a>00122 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 ); |
---|
101 | <a name="l00123"></a>00123 <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 ) ) );} |
---|
102 | <a name="l00124"></a>00124 <span class="keywordflow">return</span> Smp; |
---|
103 | <a name="l00125"></a>00125 } |
---|
104 | <a name="l00126"></a>00126 |
---|
105 | <a name="l00127"></a>00127 ~<a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>() {}; |
---|
106 | <a name="l00128"></a>00128 }; |
---|
107 | <a name="l00129"></a>00129 |
---|
108 | <a name="l00131"></a><a class="code" href="classeprod.html">00131</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> { |
---|
109 | <a name="l00132"></a>00132 <span class="keyword">protected</span>: |
---|
110 | <a name="l00134"></a><a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357">00134</a> Array<const epdf*> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>; |
---|
111 | <a name="l00136"></a><a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3">00136</a> Array<ivec> <a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a>; |
---|
112 | <a name="l00137"></a>00137 <span class="keyword">public</span>: |
---|
113 | <a name="l00138"></a>00138 <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() ) { |
---|
114 | <a name="l00139"></a>00139 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
---|
115 | <a name="l00140"></a>00140 <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++ ) { |
---|
116 | <a name="l00141"></a>00141 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>() ); |
---|
117 | <a name="l00142"></a>00142 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent ."</span> ); |
---|
118 | <a name="l00143"></a>00143 <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> ); |
---|
119 | <a name="l00144"></a>00144 } |
---|
120 | <a name="l00145"></a>00145 } |
---|
121 | <a name="l00146"></a>00146 |
---|
122 | <a name="l00147"></a><a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7">00147</a> vec <a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
---|
123 | <a name="l00148"></a>00148 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>() ); |
---|
124 | <a name="l00149"></a>00149 <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++ ) { |
---|
125 | <a name="l00150"></a>00150 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
---|
126 | <a name="l00151"></a>00151 set_subvector ( tmp,<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ), pom ); |
---|
127 | <a name="l00152"></a>00152 } |
---|
128 | <a name="l00153"></a>00153 <span class="keywordflow">return</span> tmp; |
---|
129 | <a name="l00154"></a>00154 } |
---|
130 | <a name="l00155"></a><a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4">00155</a> vec <a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
---|
131 | <a name="l00156"></a>00156 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>() ); |
---|
132 | <a name="l00157"></a>00157 <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++ ) { |
---|
133 | <a name="l00158"></a>00158 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
---|
134 | <a name="l00159"></a>00159 set_subvector ( tmp,<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ), pom ); |
---|
135 | <a name="l00160"></a>00160 } |
---|
136 | <a name="l00161"></a>00161 <span class="keywordflow">return</span> tmp; |
---|
137 | <a name="l00162"></a>00162 } |
---|
138 | <a name="l00163"></a><a class="code" href="classeprod.html#5adef154e3655a872c284b02635b8b35">00163</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>{ |
---|
139 | <a name="l00164"></a>00164 <span class="keywordtype">double</span> tmp=0; |
---|
140 | <a name="l00165"></a>00165 <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++ ) { |
---|
141 | <a name="l00166"></a>00166 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))); |
---|
142 | <a name="l00167"></a>00167 } |
---|
143 | <a name="l00168"></a>00168 <span class="keywordflow">return</span> tmp; |
---|
144 | <a name="l00169"></a>00169 } |
---|
145 | <a name="l00171"></a><a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f">00171</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);} |
---|
146 | <a name="l00172"></a>00172 }; |
---|
147 | <a name="l00173"></a>00173 |
---|
148 | <a name="l00174"></a>00174 |
---|
149 | <a name="l00178"></a><a class="code" href="classmmix.html">00178</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> { |
---|
150 | <a name="l00179"></a>00179 <span class="keyword">protected</span>: |
---|
151 | <a name="l00181"></a><a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f">00181</a> Array<mpdf*> <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>; |
---|
152 | <a name="l00183"></a><a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914">00183</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>; |
---|
153 | <a name="l00184"></a>00184 <span class="keyword">public</span>: |
---|
154 | <a name="l00186"></a><a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3">00186</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>;}; |
---|
155 | <a name="l00188"></a><a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d">00188</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> ) { |
---|
156 | <a name="l00189"></a>00189 Array<epdf*> Eps ( Coms.length() ); |
---|
157 | <a name="l00190"></a>00190 |
---|
158 | <a name="l00191"></a>00191 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
---|
159 | <a name="l00192"></a>00192 Eps ( i ) = & ( <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
---|
160 | <a name="l00193"></a>00193 } |
---|
161 | <a name="l00194"></a>00194 <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>.<a class="code" href="classemix.html#6ce82b24d7fe540ddbf44b472a005555" title="Set weights w and components R.">set_parameters</a> ( w, Eps ); |
---|
162 | <a name="l00195"></a>00195 }; |
---|
163 | <a name="l00196"></a>00196 |
---|
164 | <a name="l00197"></a><a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193">00197</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 ) { |
---|
165 | <a name="l00198"></a>00198 <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 );} |
---|
166 | <a name="l00199"></a>00199 }; |
---|
167 | <a name="l00200"></a>00200 }; |
---|
168 | <a name="l00201"></a>00201 <span class="preprocessor">#endif //MX_H</span> |
---|
169 | </pre></div></div> |
---|
170 | <hr size="1"><address style="text-align: right;"><small>Generated on Thu Oct 9 21:26:31 2008 for mixpp by |
---|
171 | <a href="http://www.doxygen.org/index.html"> |
---|
172 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> |
---|
173 | </body> |
---|
174 | </html> |
---|