Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Visual C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 29.06.2014, 02:50   #1
AlexVI
Пользователь
 
Регистрация: 25.11.2006
Сообщений: 40
По умолчанию Увеличить скорость обработки

Добрый день
как возможно ускорить этот код

Код:
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);

}
AlexVI вне форума Ответить с цитированием
Старый 18.07.2014, 23:32   #2
AlexVI
Пользователь
 
Регистрация: 25.11.2006
Сообщений: 40
По умолчанию

Цитата:
Сообщение от Matrica63 Посмотреть сообщение
попробуй использовать мосивы и Buffer
Что именно имеется ввиду мосивы и Buffer, если можно пример
AlexVI вне форума Ответить с цитированием
Старый 19.09.2014, 13:33   #3
regit
Заблокирован
 
Регистрация: 12.09.2014
Сообщений: 11
По умолчанию

Здрасвуете, уважаемый 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, а для укорочение подключонных перемменных, можете использовать классы.
А, так вообще то код идеален.
regit вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
как можно увеличить скорость выполнения VITA11111 Microsoft Office Excel 15 04.05.2013 23:44
Как увеличить скорость работы? (C#) Serg121 Помощь студентам 4 06.12.2011 17:19
как увеличить скорость скачивания!!! alex(21) Свободное общение 16 10.09.2010 19:49
как увеличить скорость заполнения данных в mdb из excel Tanuska___:) БД в Delphi 4 22.04.2010 10:50
Скорость обработки операций Alex Cones Общие вопросы Delphi 8 05.06.2009 20:17