1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
---|
5 | <title>mixpp: mixtures.h Source File</title> |
---|
6 | <link href="tabs.css" rel="stylesheet" type="text/css"/> |
---|
7 | <link href="doxygen.css" rel="stylesheet" type="text/css"/> |
---|
8 | </head> |
---|
9 | <body> |
---|
10 | <!-- Generated by Doxygen 1.6.1 --> |
---|
11 | <script type="text/javascript"> |
---|
12 | <!-- |
---|
13 | function changeDisplayState (e){ |
---|
14 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
15 | var button=this.firstChild; |
---|
16 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
17 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
18 | sectionDiv.style.display='block'; |
---|
19 | button.src='open.gif'; |
---|
20 | }else{ |
---|
21 | sectionDiv.style.display='none'; |
---|
22 | button.src='closed.gif'; |
---|
23 | } |
---|
24 | } |
---|
25 | function initDynSections(){ |
---|
26 | var divs=document.getElementsByTagName('div'); |
---|
27 | var sectionCounter=1; |
---|
28 | for(var i=0;i<divs.length-1;i++){ |
---|
29 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
30 | var header=divs[i]; |
---|
31 | var section=divs[i+1]; |
---|
32 | var button=header.firstChild; |
---|
33 | if (button!='IMG'){ |
---|
34 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
35 | button=document.createElement('img'); |
---|
36 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
37 | } |
---|
38 | header.style.cursor='pointer'; |
---|
39 | header.onclick=changeDisplayState; |
---|
40 | header.id='dynheader'+sectionCounter; |
---|
41 | button.src='closed.gif'; |
---|
42 | section.id='dynsection'+sectionCounter; |
---|
43 | section.style.display='none'; |
---|
44 | section.style.marginLeft='14px'; |
---|
45 | sectionCounter++; |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | window.onload = initDynSections; |
---|
50 | --> |
---|
51 | </script> |
---|
52 | <div class="navigation" id="top"> |
---|
53 | <div class="tabs"> |
---|
54 | <ul> |
---|
55 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
56 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
57 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
58 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
59 | </ul> |
---|
60 | </div> |
---|
61 | <div class="tabs"> |
---|
62 | <ul> |
---|
63 | <li><a href="files.html"><span>File List</span></a></li> |
---|
64 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
65 | </ul> |
---|
66 | </div> |
---|
67 | <h1>mixtures.h</h1><a href="mixtures_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
68 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef MIXTURES_H</span> |
---|
69 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define MIXTURES_H</span> |
---|
70 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
71 | <a name="l00016"></a>00016 |
---|
72 | <a name="l00017"></a>00017 <span class="preprocessor">#include "../math/functions.h"</span> |
---|
73 | <a name="l00018"></a>00018 <span class="preprocessor">#include "../stat/exp_family.h"</span> |
---|
74 | <a name="l00019"></a>00019 <span class="preprocessor">#include "../stat/emix.h"</span> |
---|
75 | <a name="l00020"></a>00020 |
---|
76 | <a name="l00021"></a>00021 <span class="keyword">namespace </span>bdm { |
---|
77 | <a name="l00022"></a>00022 |
---|
78 | <a name="l00024"></a>00024 <span class="keyword">enum</span> MixEF_METHOD { EM = 0, QB = 1}; |
---|
79 | <a name="l00025"></a>00025 |
---|
80 | <a name="l00042"></a><a class="code" href="classbdm_1_1MixEF.html">00042</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1MixEF.html" title="Mixture of Exponential Family Densities.">MixEF</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> { |
---|
81 | <a name="l00043"></a>00043 <span class="keyword">protected</span>: |
---|
82 | <a name="l00045"></a><a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5">00045</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a>; |
---|
83 | <a name="l00047"></a><a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08">00047</a> Array<BMEF*> <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a>; |
---|
84 | <a name="l00049"></a><a class="code" href="classbdm_1_1MixEF.html#ae39faa70cebadc3296bd249040105e86">00049</a> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> <a class="code" href="classbdm_1_1MixEF.html#ae39faa70cebadc3296bd249040105e86" title="Statistics for weights.">weights</a>; |
---|
85 | <a name="l00051"></a><a class="code" href="classbdm_1_1MixEF.html#a9413fb7f1836237aac807fb9f245e4f6">00051</a> <a class="code" href="classbdm_1_1eprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a>* <a class="code" href="classbdm_1_1MixEF.html#a9413fb7f1836237aac807fb9f245e4f6" title="Posterior on component parameters.">est</a>; |
---|
86 | <a name="l00053"></a>00053 |
---|
87 | <a name="l00055"></a><a class="code" href="classbdm_1_1MixEF.html#aa2376ddadb7573532404452d0c2dd28a">00055</a> MixEF_METHOD <a class="code" href="classbdm_1_1MixEF.html#aa2376ddadb7573532404452d0c2dd28a" title="Flag for a method that is used in the inference.">method</a>; |
---|
88 | <a name="l00056"></a>00056 |
---|
89 | <a name="l00058"></a><a class="code" href="classbdm_1_1MixEF.html#ad74a8d1370c63c93ec554908ae3e6006">00058</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MixEF.html#ad74a8d1370c63c93ec554908ae3e6006" title="Auxiliary function for use in constructors.">build_est</a>() { |
---|
90 | <a name="l00059"></a>00059 <a class="code" href="classbdm_1_1MixEF.html#a9413fb7f1836237aac807fb9f245e4f6" title="Posterior on component parameters.">est</a> = <span class="keyword">new</span> <a class="code" href="classbdm_1_1eprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a>; |
---|
91 | <a name="l00060"></a>00060 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> > 0 ) { |
---|
92 | <a name="l00061"></a>00061 Array<const epdf*> epdfs ( <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> + 1 ); |
---|
93 | <a name="l00062"></a>00062 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a>.length(); i++ ) { |
---|
94 | <a name="l00063"></a>00063 epdfs ( i ) = & ( <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( i )->posterior() ); |
---|
95 | <a name="l00064"></a>00064 } |
---|
96 | <a name="l00065"></a>00065 <span class="comment">// last in the product is the weight</span> |
---|
97 | <a name="l00066"></a>00066 epdfs ( <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> ) = & ( <a class="code" href="classbdm_1_1MixEF.html#ae39faa70cebadc3296bd249040105e86" title="Statistics for weights.">weights</a>.<a class="code" href="classbdm_1_1multiBM.html#a31ff93f89473f099e489b9e1dc8d9513" title="reimplemnetation of BM::posterior()">posterior</a>() ); |
---|
98 | <a name="l00067"></a>00067 <a class="code" href="classbdm_1_1MixEF.html#a9413fb7f1836237aac807fb9f245e4f6" title="Posterior on component parameters.">est</a>-><a class="code" href="classbdm_1_1eprod.html#a7f0f526ddcd028c5edaecf250ef780f6" title="Set internal.">set_parameters</a> ( epdfs, <span class="keyword">false</span> ); |
---|
99 | <a name="l00068"></a>00068 } |
---|
100 | <a name="l00069"></a>00069 } |
---|
101 | <a name="l00070"></a>00070 |
---|
102 | <a name="l00071"></a>00071 <span class="keyword">public</span>: |
---|
103 | <a name="l00073"></a><a class="code" href="classbdm_1_1MixEF.html#a4efe67d414ff34a1e7534004fd061241">00073</a> <a class="code" href="classbdm_1_1MixEF.html#a0266854387338ba757e6192d62907984" title="Constructor of empty mixture.">MixEF</a> ( <span class="keyword">const</span> Array<BMEF*> &Coms0, <span class="keyword">const</span> vec &alpha0 ) : |
---|
104 | <a name="l00074"></a>00074 <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( ), <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> ( Coms0.length() ), <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> ), |
---|
105 | <a name="l00075"></a>00075 <a class="code" href="classbdm_1_1MixEF.html#ae39faa70cebadc3296bd249040105e86" title="Statistics for weights.">weights</a> (), <a class="code" href="classbdm_1_1MixEF.html#aa2376ddadb7573532404452d0c2dd28a" title="Flag for a method that is used in the inference.">method</a> ( QB ) { |
---|
106 | <a name="l00076"></a>00076 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a>; i++ ) { |
---|
107 | <a name="l00077"></a>00077 <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( i ) = ( <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* ) Coms0 ( i )->_copy_(); |
---|
108 | <a name="l00078"></a>00078 } |
---|
109 | <a name="l00079"></a>00079 <a class="code" href="classbdm_1_1MixEF.html#ad74a8d1370c63c93ec554908ae3e6006" title="Auxiliary function for use in constructors.">build_est</a>(); |
---|
110 | <a name="l00080"></a>00080 } |
---|
111 | <a name="l00081"></a>00081 |
---|
112 | <a name="l00083"></a><a class="code" href="classbdm_1_1MixEF.html#a0266854387338ba757e6192d62907984">00083</a> <a class="code" href="classbdm_1_1MixEF.html#a0266854387338ba757e6192d62907984" title="Constructor of empty mixture.">MixEF</a> () : |
---|
113 | <a name="l00084"></a>00084 <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( ), <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> ( 0 ), <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( 0 ), |
---|
114 | <a name="l00085"></a>00085 <a class="code" href="classbdm_1_1MixEF.html#ae39faa70cebadc3296bd249040105e86" title="Statistics for weights.">weights</a> (), <a class="code" href="classbdm_1_1MixEF.html#aa2376ddadb7573532404452d0c2dd28a" title="Flag for a method that is used in the inference.">method</a> ( QB ) { |
---|
115 | <a name="l00086"></a>00086 <a class="code" href="classbdm_1_1MixEF.html#ad74a8d1370c63c93ec554908ae3e6006" title="Auxiliary function for use in constructors.">build_est</a>(); |
---|
116 | <a name="l00087"></a>00087 } |
---|
117 | <a name="l00089"></a><a class="code" href="classbdm_1_1MixEF.html#a9577de85c3e3481f7c0e23cf8f87c482">00089</a> <a class="code" href="classbdm_1_1MixEF.html#a0266854387338ba757e6192d62907984" title="Constructor of empty mixture.">MixEF</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1MixEF.html" title="Mixture of Exponential Family Densities.">MixEF</a> &M2 ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( ), <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> ( M2.<a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> ), <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a> ), |
---|
118 | <a name="l00090"></a>00090 <a class="code" href="classbdm_1_1MixEF.html#ae39faa70cebadc3296bd249040105e86" title="Statistics for weights.">weights</a> ( M2.<a class="code" href="classbdm_1_1MixEF.html#ae39faa70cebadc3296bd249040105e86" title="Statistics for weights.">weights</a> ), <a class="code" href="classbdm_1_1MixEF.html#aa2376ddadb7573532404452d0c2dd28a" title="Flag for a method that is used in the inference.">method</a> ( M2.<a class="code" href="classbdm_1_1MixEF.html#aa2376ddadb7573532404452d0c2dd28a" title="Flag for a method that is used in the inference.">method</a> ) { |
---|
119 | <a name="l00091"></a>00091 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a>; i++ ) { |
---|
120 | <a name="l00092"></a>00092 <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( i ) = M2.<a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( i )->_copy_(); |
---|
121 | <a name="l00093"></a>00093 } |
---|
122 | <a name="l00094"></a>00094 <a class="code" href="classbdm_1_1MixEF.html#ad74a8d1370c63c93ec554908ae3e6006" title="Auxiliary function for use in constructors.">build_est</a>(); |
---|
123 | <a name="l00095"></a>00095 } |
---|
124 | <a name="l00096"></a>00096 |
---|
125 | <a name="l00101"></a>00101 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MixEF.html#a0c2a50789b30769964a909d217125ed2">init</a> ( <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* Com0, <span class="keyword">const</span> mat &Data, <span class="keywordtype">int</span> c = 5 ); |
---|
126 | <a name="l00102"></a>00102 <span class="comment">//Destructor</span> |
---|
127 | <a name="l00103"></a>00103 ~<a class="code" href="classbdm_1_1MixEF.html" title="Mixture of Exponential Family Densities.">MixEF</a>() { |
---|
128 | <a name="l00104"></a>00104 <span class="keyword">delete</span> <a class="code" href="classbdm_1_1MixEF.html#a9413fb7f1836237aac807fb9f245e4f6" title="Posterior on component parameters.">est</a>; |
---|
129 | <a name="l00105"></a>00105 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1MixEF.html#a38ca1d86e977d1c38810a3c95bf074a5" title="Number of components.">n</a>; i++ ) { |
---|
130 | <a name="l00106"></a>00106 <span class="keyword">delete</span> <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( i ); |
---|
131 | <a name="l00107"></a>00107 } |
---|
132 | <a name="l00108"></a>00108 } |
---|
133 | <a name="l00110"></a>00110 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MixEF.html#a5bd7da667da183eed1577f11dff0c1f1" title="Recursive EM-like algorithm (QB-variant), see Karny et. al, 2006.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
---|
134 | <a name="l00112"></a>00112 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MixEF.html#a5bd7da667da183eed1577f11dff0c1f1" title="Recursive EM-like algorithm (QB-variant), see Karny et. al, 2006.">bayes</a> ( <span class="keyword">const</span> mat &dt ); |
---|
135 | <a name="l00113"></a>00113 <span class="keywordtype">void</span> bayesB ( <span class="keyword">const</span> mat &dt, <span class="keyword">const</span> vec &wData ); |
---|
136 | <a name="l00114"></a>00114 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1MixEF.html#ada724da464a75e07521941e430929efa">logpred</a> ( <span class="keyword">const</span> vec &dt ) <span class="keyword">const</span>; |
---|
137 | <a name="l00115"></a>00115 <span class="keyword">const</span> epdf& posterior()<span class="keyword"> const </span>{ |
---|
138 | <a name="l00116"></a>00116 <span class="keywordflow">return</span> *<a class="code" href="classbdm_1_1MixEF.html#a9413fb7f1836237aac807fb9f245e4f6" title="Posterior on component parameters.">est</a>; |
---|
139 | <a name="l00117"></a>00117 } |
---|
140 | <a name="l00118"></a>00118 emix* <a class="code" href="classbdm_1_1MixEF.html#aedc50e9640f049b846084748b18469a2" title="Constructs a predictive density .">epredictor</a>() <span class="keyword">const</span>; |
---|
141 | <a name="l00120"></a>00120 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MixEF.html#af0dfb4375fef4e61c4cb062e5bac7c8c" title="Flatten the density as if it was not estimated from the data.">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html#a2def512872ed8a4fc3b702371ec0be55" title="Default constructor (=empty constructor).">BMEF</a>* M2 ); |
---|
142 | <a name="l00122"></a><a class="code" href="classbdm_1_1MixEF.html#a251ef6fc51757712693da5faae5317c9">00122</a> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* <a class="code" href="classbdm_1_1MixEF.html#a251ef6fc51757712693da5faae5317c9" title="Access function.">_Coms</a> ( <span class="keywordtype">int</span> i ) { |
---|
143 | <a name="l00123"></a>00123 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1MixEF.html#a90c21ab5a2af56d4b49e2eaef6eccc08" title="Models for Components of .">Coms</a> ( i ); |
---|
144 | <a name="l00124"></a>00124 } |
---|
145 | <a name="l00125"></a>00125 |
---|
146 | <a name="l00127"></a><a class="code" href="classbdm_1_1MixEF.html#a664529d52cc667383b39eeb440ccd577">00127</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MixEF.html#a664529d52cc667383b39eeb440ccd577" title="Set which method is to be used.">set_method</a> ( MixEF_METHOD M ) { |
---|
147 | <a name="l00128"></a>00128 <a class="code" href="classbdm_1_1MixEF.html#aa2376ddadb7573532404452d0c2dd28a" title="Flag for a method that is used in the inference.">method</a> = M; |
---|
148 | <a name="l00129"></a>00129 } |
---|
149 | <a name="l00130"></a>00130 }; |
---|
150 | <a name="l00131"></a>00131 |
---|
151 | <a name="l00132"></a>00132 } |
---|
152 | <a name="l00133"></a>00133 <span class="preprocessor">#endif // MIXTURES_H</span> |
---|
153 | <a name="l00134"></a>00134 <span class="preprocessor"></span> |
---|
154 | <a name="l00135"></a>00135 |
---|
155 | </pre></div></div> |
---|
156 | <hr size="1"/><address style="text-align: right;"><small>Generated on Sun Sep 13 23:08:55 2009 for mixpp by |
---|
157 | <a href="http://www.doxygen.org/index.html"> |
---|
158 | <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address> |
---|
159 | </body> |
---|
160 | </html> |
---|