Здрасвуете, уважаемый AlexVi вы писали.
Цитата:
Сообщение от AlexVI
Добрый день
как возможно ускорить этот код
Код:
void log_belprop()
{
//
// Iterative decoding by belief propagation in code's Bayesian network
// Based on Pearl's book and MacKay's paper
// Using the logarithms of the probabilities
//
int i,j,l,iter;
int m,aux;
float alpha;
float delt;
int sign;
float llrp1[NODES]; // Prior probabilities (channel)
float q0[NODES], q1[NODES]; // Pseudo-posterior probabilities
// -------------------
// ***** STEP 0 *****
// INITIALIZATION STEP
// -------------------
// Prior log-likelihood ratios (channel metrics)
for (i=0;i<N;i++)
{
// LOOK-UP TABLE (LUT)
llrp1[i] = received[i]*snr_rms;
}
// For every (m,l) such that there is a link between parents and
// children, qm0[i][j] and qm1[i][j] are initialized to pl[j].
// Notation: pi (Pearl) = q (MacKay)
for (i=0; i<N; i++) // run over code nodes
{
for (j=0; j<code_node[i].size; j++) // run over check nodes
{
code_node[i].pi1[j] = llrp1[i];
}
}
iter = 0; // Counter of iterations
do {
// ---------------------------------------
// ***** STEP 1 *****
// HORIZONTAL STEP = BOTTOM-UP PROPAGATION
// ---------------------------------------
//
// MacKay:
// Run through the checks m and compute, for each n in N(m) the
// probabilitiy of a check symbol when code symbol is 0 (or 1)
// given that the other code symbols have distribution qm0, qm1
//
// Pearl:
// Node x_m computes new "lambda" messages to be sent to its parents
// u_1, u_2, ..., u_K
for (i=0; i<M; i++)
for (j=0; j<check_node[i].size; j++)
{
delt = 0.0;
sign = 0; // Keep track of sign of delt
for (l=0; l<check_node[i].size; l++)
{
aux = check_node[i].index[l];
if (aux != check_node[i].index[j])
{
// --------------------------------------------------------
// Compute the index "m" of the message from parent node
// --------------------------------------------------------
m = 0;
while ( ( (code_node[aux-1].index[m]-1) != i )
&& ( m < code_node[aux-1].size) ) m++;
if (code_node[aux-1].pi1[m] < 0.0) sign ^= 1;
delt += F(fabs(code_node[aux-1].pi1[m]));
}
}
if (sign == 0)
check_node[i].lambda1[j] = F(delt);
else
check_node[i].lambda1[j] = -F(delt);
// Normalization
if (check_node[i].lambda1[j] < -30.0)
check_node[i].lambda1[j] = -30.0;
}
// ------------------------------------
// ***** STEP 2 *****
// VERTICAL STEP = TOP-DOWN PROPAGATION
// ------------------------------------
//
// MacKay:
// Take the computed values of rm0, rm1 and update the values of
// the probabilities qm0, qm1
//
// Pearl:
// Each node u_l computes new "pi" messages to be send to its
// children x_1, x_2, ..., x_J
for (i=0; i<N; i++)
for (j=0; j<code_node[i].size; j++)
{
code_node[i].pi1[j] = 0.0;
for (l=0; l<code_node[i].size; l++)
{
aux = code_node[i].index[l]-1;
if ( aux != (code_node[i].index[j]-1) )
{
// Compute index "m" of message from children
m = 0;
while ( ( (check_node[aux].index[m]-1) != i )
&& ( m < check_node[aux].size ) ) m++;
code_node[i].pi1[j] += check_node[aux].lambda1[m];
}
}
code_node[i].pi1[j] += llrp1[i];
if (code_node[i].pi1[j] < -30.0)
code_node[i].pi1[j] = -30.0;
}
// DECODING:
// MacKay: At this step we also compute the (unconditional) pseudo-
// posterior probalilities "q0, q1" to make tentative decisions
for (i=0; i<N; i++)
{
q1[i] = 0.0;
for (j=0; j<code_node[i].size; j++)
{
aux = code_node[i].index[j]-1;
// Compute index "m" of message from children
m = 0;
while ( ( (check_node[aux].index[m]-1) != i )
&& ( m < check_node[aux].size ) ) m++;
q1[i] += check_node[aux].lambda1[m];
}
q1[i] += llrp1[i];
if (q1[i] < 0.0)
decoded[i] = 1;
else
decoded[i] = 0;
}
// Increment the number of iterations, and check if maximum reached
iter++;
} while (iter < max_iter);
}
|
Здесь почему то переменная N неподкльючено.
вы используйте это хорошо, это укорачивает но немного замедлят, где то в 1.4 раза,
если вы хотите ускорить, надо писать без for, а для укорочение подключонных перемменных, можете использовать классы.
А, так вообще то код идеален.