22
22
#ifndef INCLUDED_TURBO_LOG_BCJR_H
23
23
#define INCLUDED_TURBO_LOG_BCJR_H
24
24
25
- #include < algorithm>
26
- #include < limits>
27
- #include < vector>
28
- #include < stdexcept>
29
- #include < cmath>
30
- #include < cfloat>
31
- // #include <iostream>
25
+ #include " log_bcjr_base.h"
32
26
33
27
/* !
34
28
* \brief <+description+>
35
29
*
36
30
*/
37
- class log_bcjr
31
+ class log_bcjr : public log_bcjr_base
38
32
{
39
- private:
40
- // ! The number of possible input sequences (e.g. 2 for binary codes).
41
- int d_I;
42
- // ! The number of states in the trellis.
43
- int d_S;
44
- // ! The number of possible output sequences.
45
- int d_O;
46
- /* Gives the next state ns of a branch defined by its
47
- * initial state s and its input symbol i : NS[s*I+i]=ns.
48
- */
49
- std::vector<int > d_NS;
50
- /* Gives the output symbol of of a branch defined by its
51
- * initial state s and its input symbol i : OS[s*I+i]=os.
52
- */
53
- std::vector<int > d_OS;
54
- /* Defined such that d_PS[s] contains all the previous states having a
55
- * branch with state s.
56
- * Such a previous state may appear multiple time if there are multiple
57
- * transistions between two states.
58
- */
59
- std::vector<std::vector<int > > d_PS;
60
- // ! Defined such that d_PI[s] contains all the inputs yielding to state s.
61
- std::vector<std::vector<int > > d_PI;
62
- // ! Generates PS, PI and T tables.
63
- void generate_PS_PI ();
64
-
65
33
public:
66
34
// ! Default constructor.
67
35
log_bcjr ();
@@ -78,7 +46,7 @@ class log_bcjr
78
46
*/
79
47
log_bcjr (int I, int S, int O,
80
48
const std::vector<int > &NS,
81
- const std::vector<int > &OS);
49
+ const std::vector<int > &OS) : log_bcjr_base(I, S, O, NS, OS) {} ;
82
50
83
51
// ! Computes max* of two value.
84
52
/* !
@@ -95,6 +63,8 @@ class log_bcjr
95
63
{
96
64
return std::max (A, B) + log (1.0 + exp (-fabs (A - B)));
97
65
}
66
+ // Override log_bcjr_base method
67
+ float _max_star (float A, float B) { return max_star (A, B); }
98
68
99
69
// ! Recursively compute max* of a vector.
100
70
/* !
@@ -104,112 +74,21 @@ class log_bcjr
104
74
* \param vec Input data.
105
75
* \param n_ele number of elements in the vector.
106
76
*
107
- * \return: max* of vec. If axis is None, the result is a scalar value.
77
+ * \return: max* of vec.
108
78
* If axis is given, the result is an array of dimension vec.ndim - 1.
109
79
*/
110
- static float max_star (const float *vec, size_t n_ele);
111
-
112
- // ! Compute forward log metrics.
113
- /* !
114
- * From A_k(s) the forward log metric for state s at time index k, and
115
- * G_k(s,i) the log metric of the branch identified by state s and
116
- * input symbol i at index k, this function computes:
117
- *
118
- * A_k(s) = max*_{ s' \in [0 ; d_S[, i \in \tau(s',s) } G_{k-1}(s', i) + A_{k-1}(s')
119
- *
120
- * where \tau(s,s') regroups every input symbols that belongs to every
121
- * transitions between s and s'.
122
- *
123
- * Note: in practice, here, we only have the metrics of every possible
124
- * output symbols: G_k(o) with o \in [0 ; d_O[. The correspondance is
125
- * done through d_OS: G_k(s,i) = G_k(d_OS[s*I+i]).
126
- *
127
- * \param G Const reference to the log metrics vector (size: d_O*K).
128
- * \param A0 Const reference to the initial forward state metrics
129
- * (size: d_S).
130
- * \param A Reference to the forward metrics vector (will have a size
131
- * of d_S*(K+1) at the end of function execution).
132
- * \param K Number of observations.
133
- */
134
- virtual void compute_fw_metrics (const std::vector<float > &G,
135
- const std::vector<float > &A0, std::vector<float > &A, size_t K);
136
-
137
- // ! Compute backward log metrics.
138
- /* !
139
- * From B_k(s) the backward log metric for state s at time index k, and
140
- * G_k(s,i) the log metric of the branch identified by state s and
141
- * input symbol i at index k, this function computes:
142
- *
143
- * B_k(s) = max*_{ s' \in [0 ; d_S[, i \in \tau(s,s') } G_k(s, i) + B_{k+1}(s').
144
- *
145
- * where \tau(s,s') regroups every input symbols that belongs to every
146
- * transitions between s and s'.
147
- *
148
- * Note: in practice, here, we only have the metrics of every possible
149
- * output symbols: G_k(o) with o \in [0 ; d_O[. The correspondance is
150
- * done through d_OS: G_k(s,i) = G_k(d_OS[s*I+i]).
151
- *
152
- * \param G Const reference to the log metrics vector (size: d_O*K).
153
- * \param BK Const reference to the final backward state metrics
154
- * (size: d_S).
155
- * \param B Reference to the backward metrics vector (will have a size
156
- * of d_S*(K+1) at the end of function execution).
157
- * \param K Number of observations.
158
- */
159
- virtual void compute_bw_metrics (const std::vector<float > &G,
160
- const std::vector<float > &BK, std::vector<float > &B, size_t K);
161
-
162
- // ! Compute branch log a-posteriori probabilities.
163
- /* !
164
- * From A_k(s) the forward log metric for state s at time index k,
165
- * B_k(s) the backward log metric for state s at time index k, and
166
- * G_k(s,s') the branch log metric between states s' and s at time
167
- * index k, this function computes:
168
- *
169
- * APP_k(s,i) = B_{k+1}(NS(s,i)) + G_k(s,i) + A_k(s),
170
- *
171
- * where s' = NS(s,i) is the next state for transition with initial
172
- * state s and input symbol i (NS[s*I+i]).
173
- * Which is equivalent to log a-posteriori probabilites, up to an
174
- * additive constant.
175
- *
176
- * \param A Const reference to the forward metrics vector (size: d_S*(K+1)).
177
- * \param B Const reference to the backward metrics vector (size: d_S*(K+1)).
178
- * \param G Const reference to the branch log metrics vector (size: d_O*K).
179
- * \param K Number of observations.
180
- * \param out Reference to a posteriori branch log probabilities (will
181
- * have a size of d_S*d_I*K at the end of function execution).
182
- *
183
- */
184
- virtual void compute_app (const std::vector<float > &A,
185
- const std::vector<float > &B, const std::vector<float > &G,
186
- size_t K, std::vector<float > &out);
187
-
188
- /* ! Actually computes logarithm of a-posteriori probabilities for a
189
- * given observation sequence.
190
- *
191
- * \param A0 Log of initial state probabilities of the encoder (size: d_S).
192
- * \param BK Log of final state probabilities of the encoder (size: d_S).
193
- * \param in Log of input branch metrics for the algorithm (size: d_O*k).
194
- * \param out A quantity equivalent to log a-posteriori probabilites, up
195
- * to an additive constant (will have a size of d_S*d_I*K at the end of
196
- * function execution).
197
- */
198
- void log_bcjr_algorithm (const std::vector<float > &A0,
199
- const std::vector<float > &BK,
200
- const std::vector<float > &in,
201
- std::vector<float > &out);
202
-
203
- // ! Getter for d_I.
204
- int get_I () { return d_I; }
205
- // ! Getter for d_S.
206
- int get_S () { return d_S; }
207
- // ! Getter for d_O.
208
- int get_O () { return d_O; }
209
- // ! Getter for d_NS.
210
- std::vector<int >& get_NS () { return d_NS; }
211
- // ! Getter for d_OS.
212
- std::vector<int >& get_OS () { return d_OS; }
80
+ static float max_star (const float *vec, size_t n_ele)
81
+ {
82
+ float ret_val = -std::numeric_limits<float >::max ();
83
+
84
+ for (float *vec_it = (float *)vec ; vec_it < (vec + n_ele) ; ++vec_it) {
85
+ ret_val = max_star (ret_val, *vec_it);
86
+ }
87
+
88
+ return ret_val;
89
+ }
90
+ // Override log_bcjr_base method
91
+ float _max_star (const float *vec, size_t n_ele) { return max_star (vec, n_ele); }
213
92
};
214
93
215
94
#endif /* INCLUDED_TURBO_LOG_BCJR_H */
0 commit comments