root/doc/html/llr_8h-source.html @ 353

Revision 353, 20.2 kB (checked in by smidl, 16 years ago)

doc

Line 
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: llr.h Source File</title>
4<link href="tabs.css" rel="stylesheet" type="text/css">
5<link href="doxygen.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.5.8 -->
8<script type="text/javascript">
9<!--
10function changeDisplayState (e){
11  var num=this.id.replace(/[^[0-9]/g,'');
12  var button=this.firstChild;
13  var sectionDiv=document.getElementById('dynsection'+num);
14  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
15    sectionDiv.style.display='block';
16    button.src='open.gif';
17  }else{
18    sectionDiv.style.display='none';
19    button.src='closed.gif';
20  }
21}
22function initDynSections(){
23  var divs=document.getElementsByTagName('div');
24  var sectionCounter=1;
25  for(var i=0;i<divs.length-1;i++){
26    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
27      var header=divs[i];
28      var section=divs[i+1];
29      var button=header.firstChild;
30      if (button!='IMG'){
31        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
32        button=document.createElement('img');
33        divs[i].insertBefore(button,divs[i].firstChild);
34      }
35      header.style.cursor='pointer';
36      header.onclick=changeDisplayState;
37      header.id='dynheader'+sectionCounter;
38      button.src='closed.gif';
39      section.id='dynsection'+sectionCounter;
40      section.style.display='none';
41      section.style.marginLeft='14px';
42      sectionCounter++;
43    }
44  }
45}
46window.onload = initDynSections;
47-->
48</script>
49<div class="navigation" id="top">
50  <div class="tabs">
51    <ul>
52      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
53      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
54      <li><a href="modules.html"><span>Modules</span></a></li>
55      <li><a href="annotated.html"><span>Classes</span></a></li>
56      <li class="current"><a href="files.html"><span>Files</span></a></li>
57    </ul>
58  </div>
59  <div class="tabs">
60    <ul>
61      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
62      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
63    </ul>
64  </div>
65<h1>llr.h</h1><a href="llr_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
66<a name="l00029"></a>00029 <span class="preprocessor">#ifndef LLR_H</span>
67<a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#define LLR_H</span>
68<a name="l00031"></a>00031 <span class="preprocessor"></span>
69<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;limits&gt;</span>
70<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;<a class="code" href="vec_8h.html" title="Templated Vector Class Definitions.">itpp/base/vec.h</a>&gt;</span>
71<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;<a class="code" href="mat_8h.html" title="Matrix Class Definitions.">itpp/base/mat.h</a>&gt;</span>
72<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;<a class="code" href="specmat_8h.html" title="Definitions of special vectors and matrices.">itpp/base/specmat.h</a>&gt;</span>
73<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;<a class="code" href="matfunc_8h.html" title="Various functions on vectors and matrices - header file.">itpp/base/matfunc.h</a>&gt;</span>
74<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;limits&gt;</span>
75<a name="l00038"></a>00038
76<a name="l00039"></a>00039 <span class="keyword">namespace </span>itpp
77<a name="l00040"></a>00040 {
78<a name="l00041"></a>00041
79<a name="l00045"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">00045</a> <span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">int</span> QLLR;
80<a name="l00046"></a>00046
81<a name="l00050"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#fa891d6a6bac8f0294368ce6c85aab30">00050</a> <span class="keyword">typedef</span> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">Vec&lt;QLLR&gt;</a> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">QLLRvec</a>;
82<a name="l00051"></a>00051
83<a name="l00055"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#a8108342a0fa77005d7714f27158fa13">00055</a> <span class="keyword">typedef</span> <a class="code" href="classitpp_1_1Mat.html" title="Matrix Class (Templated).">Mat&lt;QLLR&gt;</a> <a class="code" href="classitpp_1_1Mat.html" title="Matrix Class (Templated).">QLLRmat</a>;
84<a name="l00056"></a>00056
85<a name="l00060"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#ead7f08c87fe73a8c33ab94777fa7374">00060</a> <span class="keyword">const</span> QLLR QLLR_MAX = (<a class="code" href="group__protocol.html#g3e4e78a5230c444344a135c661163ef2" title="ADD DOCUMENTATION HERE.">std::numeric_limits&lt;QLLR&gt;::max</a>() &gt;&gt; 4);
86<a name="l00061"></a>00061 <span class="comment">// added some margin to make sure the sum of two LLR is still permissible</span>
87<a name="l00062"></a>00062
88<a name="l00114"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html">00114</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1LLR__calc__unit.html" title="Log-likelihood algebra calculation unit.">LLR_calc_unit</a>
89<a name="l00115"></a>00115 {
90<a name="l00116"></a>00116 <span class="keyword">public</span>:
91<a name="l00118"></a>00118   <a class="code" href="classitpp_1_1LLR__calc__unit.html#d9a5a2abb2ef8b62266207e67f2a0ff4" title="Constructor, using the default table resolution.">LLR_calc_unit</a>();
92<a name="l00119"></a>00119
93<a name="l00125"></a>00125   <a class="code" href="classitpp_1_1LLR__calc__unit.html#d9a5a2abb2ef8b62266207e67f2a0ff4" title="Constructor, using the default table resolution.">LLR_calc_unit</a>(<span class="keywordtype">short</span> <span class="keywordtype">int</span> Dint1, <span class="keywordtype">short</span> <span class="keywordtype">int</span> Dint2, <span class="keywordtype">short</span> <span class="keywordtype">int</span> Dint3);
94<a name="l00126"></a>00126
95<a name="l00155"></a>00155   <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html#531b0a4eca593e439a39ba9de42ee68c" title="Set the quantization and table parameters.">init_llr_tables</a>(<span class="keywordtype">short</span> <span class="keywordtype">int</span> Dint1 = 12, <span class="keywordtype">short</span> <span class="keywordtype">int</span> Dint2 = 300,
96<a name="l00156"></a>00156                        <span class="keywordtype">short</span> <span class="keywordtype">int</span> Dint3 = 7);
97<a name="l00157"></a>00157
98<a name="l00159"></a>00159   <a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> <a class="code" href="classitpp_1_1LLR__calc__unit.html#fdc07e6395053a2a9441c8b13cd2d8ad" title="Convert a &amp;quot;real&amp;quot; LLR value to an LLR type.">to_qllr</a>(<span class="keywordtype">double</span> l) <span class="keyword">const</span>;
99<a name="l00160"></a>00160
100<a name="l00162"></a>00162   <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">QLLRvec</a> <a class="code" href="classitpp_1_1LLR__calc__unit.html#fdc07e6395053a2a9441c8b13cd2d8ad" title="Convert a &amp;quot;real&amp;quot; LLR value to an LLR type.">to_qllr</a>(<span class="keyword">const</span> vec &amp;l) <span class="keyword">const</span>;
101<a name="l00163"></a>00163
102<a name="l00165"></a>00165   <a class="code" href="classitpp_1_1Mat.html" title="Matrix Class (Templated).">QLLRmat</a> <a class="code" href="classitpp_1_1LLR__calc__unit.html#fdc07e6395053a2a9441c8b13cd2d8ad" title="Convert a &amp;quot;real&amp;quot; LLR value to an LLR type.">to_qllr</a>(<span class="keyword">const</span> mat &amp;l) <span class="keyword">const</span>;
103<a name="l00166"></a>00166
104<a name="l00168"></a>00168   <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html#6fe45918d01b24059e4173b7bf939f91" title="Convert an LLR type to a &amp;quot;real&amp;quot; LLR.">to_double</a>(<a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> l) <span class="keyword">const</span>;
105<a name="l00169"></a>00169
106<a name="l00171"></a>00171   vec <a class="code" href="classitpp_1_1LLR__calc__unit.html#6fe45918d01b24059e4173b7bf939f91" title="Convert an LLR type to a &amp;quot;real&amp;quot; LLR.">to_double</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html" title="Vector Class (Templated).">QLLRvec</a> &amp;l) <span class="keyword">const</span>;
107<a name="l00172"></a>00172
108<a name="l00174"></a>00174   mat <a class="code" href="classitpp_1_1LLR__calc__unit.html#6fe45918d01b24059e4173b7bf939f91" title="Convert an LLR type to a &amp;quot;real&amp;quot; LLR.">to_double</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html" title="Matrix Class (Templated).">QLLRmat</a> &amp;l) <span class="keyword">const</span>;
109<a name="l00175"></a>00175
110<a name="l00181"></a>00181   <span class="keyword">inline</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> <a class="code" href="classitpp_1_1LLR__calc__unit.html#217d9cbc322bba5055e1b9098a199e16" title="Jacobian logarithm.">jaclog</a>(<a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> a, <a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> b) <span class="keyword">const</span>;
111<a name="l00182"></a>00182   <span class="comment">// Note: a version of this function taking "double" values as input</span>
112<a name="l00183"></a>00183   <span class="comment">// is deliberately omitted, because this is rather slow.</span>
113<a name="l00184"></a>00184
114<a name="l00193"></a>00193   <a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> <a class="code" href="classitpp_1_1LLR__calc__unit.html#5dd699781fbbbc31f7e641ddca2ba467" title="Hagenauer&amp;#39;s &amp;quot;Boxplus&amp;quot; operator.">Boxplus</a>(<a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> a, <a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> b) <span class="keyword">const</span>;
115<a name="l00194"></a>00194
116<a name="l00200"></a>00200   <span class="keyword">inline</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> <a class="code" href="classitpp_1_1LLR__calc__unit.html#7ec4463a33fc8500fbf1bd9c142a3bcb" title="Logexp operator.">logexp</a>(<a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> x) <span class="keyword">const</span>;
117<a name="l00201"></a>00201
118<a name="l00203"></a>00203   ivec <a class="code" href="classitpp_1_1LLR__calc__unit.html#550e6a46b64e4df849c719ca3c0f038b" title="Retrieve the table resolution values.">get_Dint</a>();
119<a name="l00204"></a>00204
120<a name="l00206"></a>00206   <span class="keyword">friend</span> std::ostream &amp;<a class="code" href="classitpp_1_1LLR__calc__unit.html#e0d7b62e5b9ea86e4b7450dffd7f400f" title="Print some properties of the LLR calculation unit in plain text.">operator&lt;&lt;</a>(std::ostream &amp;os, <span class="keyword">const</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html" title="Log-likelihood algebra calculation unit.">LLR_calc_unit</a> &amp;l);
121<a name="l00207"></a>00207
122<a name="l00208"></a>00208 <span class="keyword">private</span>:
123<a name="l00210"></a>00210   ivec construct_logexp_table();
124<a name="l00211"></a>00211
125<a name="l00213"></a>00213   ivec logexp_table;
126<a name="l00214"></a>00214
127<a name="l00216"></a>00216   <span class="keywordtype">short</span> <span class="keywordtype">int</span> Dint1, Dint2, Dint3;
128<a name="l00217"></a>00217 };
129<a name="l00218"></a>00218
130<a name="l00223"></a>00223 std::ostream &amp;<a class="code" href="group__fixed.html#g46e967850e616363aeabd2cda5bcc159" title="Set output mode.">operator&lt;&lt;</a>(std::ostream &amp;os, <span class="keyword">const</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html" title="Log-likelihood algebra calculation unit.">LLR_calc_unit</a> &amp;lcu);
131<a name="l00224"></a>00224
132<a name="l00225"></a>00225
133<a name="l00226"></a>00226 <span class="comment">// ----------------------------------------------------------------------</span>
134<a name="l00227"></a>00227 <span class="comment">// implementation of some inline functions</span>
135<a name="l00228"></a>00228 <span class="comment">// ----------------------------------------------------------------------</span>
136<a name="l00229"></a>00229
137<a name="l00230"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#6fe45918d01b24059e4173b7bf939f91">00230</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html#6fe45918d01b24059e4173b7bf939f91" title="Convert an LLR type to a &amp;quot;real&amp;quot; LLR.">LLR_calc_unit::to_double</a>(QLLR l)<span class="keyword"> const</span>
138<a name="l00231"></a>00231 <span class="keyword"></span>{
139<a name="l00232"></a>00232   <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(l) / (1 &lt;&lt; Dint1);
140<a name="l00233"></a>00233 }
141<a name="l00234"></a>00234
142<a name="l00235"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#fdc07e6395053a2a9441c8b13cd2d8ad">00235</a> <span class="keyword">inline</span> QLLR <a class="code" href="classitpp_1_1LLR__calc__unit.html#fdc07e6395053a2a9441c8b13cd2d8ad" title="Convert a &amp;quot;real&amp;quot; LLR value to an LLR type.">LLR_calc_unit::to_qllr</a>(<span class="keywordtype">double</span> l)<span class="keyword"> const</span>
143<a name="l00236"></a>00236 <span class="keyword"></span>{
144<a name="l00237"></a>00237   <span class="keywordtype">double</span> QLLR_MAX_double = <a class="code" href="classitpp_1_1LLR__calc__unit.html#6fe45918d01b24059e4173b7bf939f91" title="Convert an LLR type to a &amp;quot;real&amp;quot; LLR.">to_double</a>(<a class="code" href="classitpp_1_1LLR__calc__unit.html#ead7f08c87fe73a8c33ab94777fa7374">QLLR_MAX</a>);
145<a name="l00238"></a>00238   <span class="comment">// Don't abort when overflow occurs, just saturate the QLLR</span>
146<a name="l00239"></a>00239   <span class="keywordflow">if</span> (l &gt; QLLR_MAX_double) {
147<a name="l00240"></a>00240     <a class="code" href="group__errorhandlingfunc.html#ga504b34ee91d002167e90daa5808963c" title="Print information message if NDEBUG is not defined.">it_info_debug</a>(<span class="stringliteral">"LLR_calc_unit::to_qllr(): LLR overflow"</span>);
148<a name="l00241"></a>00241     <span class="keywordflow">return</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html#ead7f08c87fe73a8c33ab94777fa7374">QLLR_MAX</a>;
149<a name="l00242"></a>00242   }
150<a name="l00243"></a>00243   <span class="keywordflow">if</span> (l &lt; -QLLR_MAX_double) {
151<a name="l00244"></a>00244     <a class="code" href="group__errorhandlingfunc.html#ga504b34ee91d002167e90daa5808963c" title="Print information message if NDEBUG is not defined.">it_info_debug</a>(<span class="stringliteral">"LLR_calc_unit::to_qllr(): LLR overflow"</span>);
152<a name="l00245"></a>00245     <span class="keywordflow">return</span> -<a class="code" href="classitpp_1_1LLR__calc__unit.html#ead7f08c87fe73a8c33ab94777fa7374">QLLR_MAX</a>;
153<a name="l00246"></a>00246   }
154<a name="l00247"></a>00247   <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a><span class="keyword">&gt;</span>(<a class="code" href="group__convertfunc.html#g0f932e63be26b95c4d9c6603b6355e89" title="Round to nearest lower integer.">std::floor</a>(0.5 + (1 &lt;&lt; Dint1) * l));
155<a name="l00248"></a>00248 }
156<a name="l00249"></a>00249
157<a name="l00250"></a>00250
158<a name="l00251"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#7ec4463a33fc8500fbf1bd9c142a3bcb">00251</a> <span class="keyword">inline</span> QLLR <a class="code" href="classitpp_1_1LLR__calc__unit.html#7ec4463a33fc8500fbf1bd9c142a3bcb" title="Logexp operator.">LLR_calc_unit::logexp</a>(QLLR x)<span class="keyword"> const</span>
159<a name="l00252"></a>00252 <span class="keyword"></span>{
160<a name="l00253"></a>00253   <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(x &gt;= 0, <span class="stringliteral">"LLR_calc_unit::logexp(): Wrong LLR value"</span>);
161<a name="l00254"></a>00254   <span class="keywordtype">int</span> ind = x &gt;&gt; Dint3;
162<a name="l00255"></a>00255   <span class="keywordflow">if</span> (ind &gt;= Dint2) <span class="comment">// outside table</span>
163<a name="l00256"></a>00256     <span class="keywordflow">return</span> 0;
164<a name="l00257"></a>00257
165<a name="l00258"></a>00258   <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(ind &gt;= 0, <span class="stringliteral">"LLR_calc_unit::logexp(): Internal error"</span>);
166<a name="l00259"></a>00259   <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(ind &lt; Dint2, <span class="stringliteral">"LLR_calc_unit::logexp(): internal error"</span>);
167<a name="l00260"></a>00260
168<a name="l00261"></a>00261   <span class="comment">// With interpolation</span>
169<a name="l00262"></a>00262   <span class="comment">// int delta=x-(ind&lt;&lt;Dint3);</span>
170<a name="l00263"></a>00263   <span class="comment">// return ((delta*logexp_table(ind+1) + ((1&lt;&lt;Dint3)-delta)*logexp_table(ind)) &gt;&gt; Dint3);</span>
171<a name="l00264"></a>00264
172<a name="l00265"></a>00265   <span class="comment">// Without interpolation</span>
173<a name="l00266"></a>00266   <span class="keywordflow">return</span> logexp_table(ind);
174<a name="l00267"></a>00267 }
175<a name="l00268"></a>00268
176<a name="l00269"></a>00269
177<a name="l00270"></a><a class="code" href="classitpp_1_1LLR__calc__unit.html#217d9cbc322bba5055e1b9098a199e16">00270</a> <span class="keyword">inline</span> QLLR <a class="code" href="classitpp_1_1LLR__calc__unit.html#217d9cbc322bba5055e1b9098a199e16" title="Jacobian logarithm.">LLR_calc_unit::jaclog</a>(QLLR a, QLLR b)<span class="keyword"> const</span>
178<a name="l00271"></a>00271 <span class="keyword"></span>{
179<a name="l00272"></a>00272   <a class="code" href="classitpp_1_1LLR__calc__unit.html#09afad8f68db048f87a252605c40a7b9">QLLR</a> x, maxab;
180<a name="l00273"></a>00273
181<a name="l00274"></a>00274   <span class="keywordflow">if</span> (a &gt; b) {
182<a name="l00275"></a>00275     maxab = a;
183<a name="l00276"></a>00276     x = a - b;
184<a name="l00277"></a>00277   }
185<a name="l00278"></a>00278   <span class="keywordflow">else</span> {
186<a name="l00279"></a>00279     maxab = b;
187<a name="l00280"></a>00280     x = b - a;
188<a name="l00281"></a>00281   }
189<a name="l00282"></a>00282
190<a name="l00283"></a>00283   <span class="keywordflow">if</span> (maxab &gt;= <a class="code" href="classitpp_1_1LLR__calc__unit.html#ead7f08c87fe73a8c33ab94777fa7374">QLLR_MAX</a>)
191<a name="l00284"></a>00284     <span class="keywordflow">return</span> <a class="code" href="classitpp_1_1LLR__calc__unit.html#ead7f08c87fe73a8c33ab94777fa7374">QLLR_MAX</a>;
192<a name="l00285"></a>00285   <span class="keywordflow">else</span>
193<a name="l00286"></a>00286     <span class="keywordflow">return</span> (maxab + <a class="code" href="classitpp_1_1LLR__calc__unit.html#7ec4463a33fc8500fbf1bd9c142a3bcb" title="Logexp operator.">logexp</a>(x));
194<a name="l00287"></a>00287 }
195<a name="l00288"></a>00288
196<a name="l00289"></a>00289 }
197<a name="l00290"></a>00290
198<a name="l00291"></a>00291 <span class="preprocessor">#endif</span>
199</pre></div></div>
200<hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:12 2009 for mixpp by&nbsp;
201<a href="http://www.doxygen.org/index.html">
202<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
203</body>
204</html>
Note: See TracBrowser for help on using the browser.