Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. // Обучение сети Хопфилда
  2. void Learning()
  3. {
  4.     for (int i =  0; i < N; i++)
  5.     {
  6.         for (int j =  0; j < N; j++)
  7.         {
  8.             if (i == j)
  9.             {
  10.                 continue;
  11.             }
  12.             for (int m =  0; m < M; m++)
  13.             {
  14.                 // корректировка весов
  15.                 w[i, j] += Boxes[m][i] * Boxes[m][j];
  16.             }
  17.             w[i, j] /= N;
  18.         }
  19.     }
  20. }
  21. // восстановление образа
  22. public TBox Find(TBox BS, int T = 1000)
  23. {
  24.     TBox B = new TBox(BS);
  25.     TBox B2 = new TBox(B);
  26.     for (int t =  0; t < T; t++)
  27.     {
  28.         for (int j =  0; j < N; j++)
  29.         {
  30.             double d =  0;
  31.             for (int i =  0; i < N; i++)
  32.             {
  33.                 d += w[j, i] * B[i];
  34.             }
  35.             if (d >  0)
  36.             {
  37.                 B2[j] = 1;
  38.             }
  39.             else
  40.             {
  41.                 B2[j] = -1;
  42.             }
  43.         }
  44.         B = new TBox(B2);
  45.         if (Boxes.Find(B))
  46.         {
  47.             return B;
  48.         }
  49.     }
  50.     return null;
  51. }




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2018