Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;MIT License
  2.  
  3. ;Copyright (c) 2020 Artem Yashin
  4.  
  5. ;Permission is hereby granted, free of charge, to any person obtaining a copy
  6. ;of this software and associated documentation files (the "Software"), to deal
  7. ;in the Software without restriction, including without limitation the rights
  8. ;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. ;copies of the Software, and to permit persons to whom the Software is
  10. ;furnished to do so, subject to the following conditions:
  11.  
  12. ;The above copyright notice and this permission notice shall be included in all
  13. ;copies or substantial portions of the Software.
  14.  
  15. ;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. ;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. ;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. ;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. ;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. ;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. ;SOFTWARE.
  22.  
  23. ;https://www.youtube.com/watch?v=GNcGPw_Kb_0
  24.  
  25. ;https://www.youtube.com/watch?v=wzIOl4hWP3U
  26. ; 1:20 - cats images
  27.  
  28. format MS COFF
  29. public EXPORTS
  30. section '.flat' code readable align 16
  31.  
  32. include "..\..\..\KOSfuncs.inc"
  33. include "..\..\..\proc32.inc"
  34. include "..\..\..\macros.inc"
  35. include "..\..\..\dll.inc"
  36. include "..\..\..\bcc32\include\kos_func.inc"
  37. include "..\..\..\bcc32\include\kos_heap.inc"
  38.  
  39. @@memcpy$qpvpxvui equ @memcpy$qpvpxvui
  40. @@DoubleToStr$qduso equ @DoubleToStr$qduso
  41. @@strlen$qpxc equ @strlen$qpxc
  42. @@strstr$qpxct1 equ @strstr$qpxct1
  43. @@strchr$qpxci equ @strchr$qpxci
  44. @@StrToInt$qpc equ @StrToInt$qpc
  45. @@StrToDouble$qpc equ @StrToDouble$qpc
  46.  
  47. mem.alloc   dd ? ;функция для выделения памяти
  48. mem.free    dd ? ;функция для освобождения памяти
  49. mem.realloc dd ? ;функция для перераспределения памяти
  50. dll.load    dd ?
  51.  
  52. PRECISION equ 16
  53. NNP_FF_BIN  equ 0x6e6962
  54. NNP_FF_JSON equ 0x6e6f736a
  55.  
  56. struct Layer
  57.         c_size  dd ? ;+ 0 curent size - число нейронов в текущем слое
  58.         n_size  dd ? ;+ 4 next size   - число нейронов на следующем слое
  59.         neurons dd ? ;+ 8 []
  60.         biases  dd ? ;+12 []
  61.         weights dd ? ;+16 [][]
  62. ends
  63.  
  64. struct NeuralNetwork
  65.         learningRate  dq ? ;+ 0 скорость обучения
  66.         layers        dd ? ;+ 8 [] слои
  67.         layers_length dd ? ;+12 число слоев
  68.         activation    dd ? ;+16 указатель на функцию активации
  69.         derivative    dd ? ;+20 указатель на функцию
  70.         errors        dd ? ;+24 массив для вычислений
  71.         errorsNext    dd ? ;+28
  72.         gradients     dd ? ;+32
  73.         deltas        dd ? ;+36
  74. ends
  75.  
  76. align 4
  77. _rand_x dd 0
  78.  
  79. txt_QlearningRateQ_ db '"learningRate": ',0
  80. txt_zap_nl   db ",",10,0
  81. txt_Qlayers_lengthQ db '"layers_length": ',0
  82. txt_QlayersQ db '"layers": [',0
  83. txt_nl_t_Qc_sizeQ db 10,9,'{"c_size": ',0
  84. txt_zap_nl_t_Qn_sizeQ db ",",10,9,'"n_size": ',0
  85. txt_t_QneuronsQ db 9,'"neurons": [',0
  86. txt_zap_sp      db ", ",0
  87. txt_sqbr_zap_nl db      "],",10,0
  88. txt_t_QbiasesQ  db 9,'"biases": [',0
  89. txt_sqbr_zap_t_QweightsQ db "],",10,9,'"weights": [',10,9,9,0
  90. txt_zap_nl_t_t  db ",",10,9,9,0
  91. txt_sqbro       db "[",0
  92. txt_sqbr        db "]",0
  93. txt_sqbr_fbr_zap  db "]},",0
  94. txt_nl_t_sqbr     db 10,9,"]",0
  95. txt_learningRate  db '"learningRate"',0
  96. txt_layers_length db '"layers_length"',0
  97. ;txt_pri_zap db '%i,',0
  98. txt_c_size  db '"c_size"',0
  99. txt_n_size  db '"n_size"',0
  100. txt_biases  db '"biases"',0
  101. txt_weights db '"weights"',0
  102.  
  103. align 16
  104. proc lib_init
  105.         mov     [mem.alloc], eax
  106.         mov     [mem.free], ebx
  107.         mov     [mem.realloc], ecx
  108.         mov     [dll.load], edx
  109.  
  110.         or      edx, edx
  111.         jz      @f
  112.                 invoke  dll.load, @IMPORT
  113. @@:
  114.         ret
  115. endp
  116.  
  117. align 16
  118. Math_random:
  119.         imul      eax,dword[_rand_x],22695477
  120.         inc       eax
  121.         push      ecx
  122.         mov       dword[_rand_x],eax
  123.         and       eax,65535
  124.         mov       dword[esp],eax
  125.         fild      dword[esp]
  126.         fmul      dword[@f]
  127.         pop       edx
  128.         ret
  129.         align 4
  130. @@:
  131.         db 0,0,128,55 ;dd 1.0/65536.0
  132.  
  133. align 16
  134. sigmoid:
  135.         push      ebp
  136.         mov       ebp,esp
  137.         add       esp,-8
  138.         fld       qword[ebp+8]
  139.         fchs
  140.         fstp      qword[esp]
  141.         call      dword[_exp]
  142.         add       esp,8
  143.         fadd      dword[f_1_0]
  144.         fdivr     dword[f_1_0]
  145.         pop       ebp
  146.         ret       8
  147.  
  148. align 16
  149. dsigmoid:
  150.         push      ebp
  151.         mov       ebp,esp
  152.         fld1
  153.         fsub      qword[ebp+8]
  154.         fmul      qword[ebp+8]
  155.         pop       ebp
  156.         ret       8
  157.  
  158. align 16
  159. Layer_Create:
  160.         push      ebp
  161.         mov       ebp,esp
  162.         push      ebx esi edi
  163.         mov       esi,[ebp+8]
  164.         mov       edi,[ebp+12]
  165.         mov       ebx,edi
  166.         shl       ebx,3
  167.         mov       dword[esi+Layer.c_size],edi
  168.         mov       eax,[ebp+16]
  169.         mov       dword[esi+Layer.n_size],eax
  170.         push      ebx
  171.         call      @$bnwa$qui
  172.         pop       ecx
  173.         mov       dword[esi+Layer.neurons],eax
  174.         push      ebx
  175.         call      @$bnwa$qui
  176.         pop       ecx
  177.         mov       dword[esi+Layer.biases],eax
  178.         mov       eax,edi
  179.         shl       eax,2
  180.         push      eax
  181.         call      @$bnwa$qui
  182.         pop       ecx
  183.         mov       dword[esi+Layer.weights],eax
  184.         xor       ebx,ebx
  185.         cmp       edi,ebx
  186.         jbe        .end_f
  187. @@:
  188.         mov       eax,[ebp+16]
  189.         shl       eax,3
  190.         push      eax
  191.         call      @$bnwa$qui
  192.         pop       ecx
  193.         mov       edx,[esi+Layer.weights]
  194.         mov       dword[edx+4*ebx],eax
  195.         inc       ebx
  196.         cmp       edi,ebx
  197.         ja         @b
  198. .end_f:
  199.         pop       edi esi ebx ebp
  200.         ret       12
  201.  
  202. ;+ 8 NeuralNetwork* o
  203. ;+12 double learningRate
  204. ;+20 void* activation
  205. ;+24 void* derivative
  206. ;+28 unsigned long* sizes
  207. ;+32 long sizes_length
  208. align 16
  209. NNP_Create:
  210.         push      ebp
  211.         mov       ebp,esp
  212.         add       esp,-12
  213.         push      ebx esi edi
  214.         mov       eax,[ebp+8] ;o
  215.         mov       edx,[ebp+12] ;learningRate
  216.         mov       dword[eax+NeuralNetwork.learningRate],edx
  217.         mov       edx,[ebp+16] ;learningRate (2)
  218.         mov       dword[eax+NeuralNetwork.learningRate+4],edx
  219.         mov       ecx,[ebp+8] ;o
  220.         mov       eax,[ebp+20] ;activation
  221.         or        eax,eax
  222.         jnz       @f
  223.         mov       eax,sigmoid
  224. @@:
  225.         mov       dword[ecx+NeuralNetwork.activation],eax
  226.         mov       edx,[ebp+8] ;o
  227.         mov       eax,[ebp+24] ;derivative
  228.         or        eax,eax
  229.         jnz       @f
  230.         mov       eax,dsigmoid
  231. @@:
  232.         mov       dword[edx+NeuralNetwork.derivative],eax
  233.         mov       eax,[ebp+32] ;sizes_length
  234.         imul      eax,sizeof.Layer
  235.         push      eax
  236.         call      @$bnwa$qui
  237.         pop       ecx
  238.         mov       edx,[ebp+8] ;o
  239.         mov       dword[edx+NeuralNetwork.layers],eax
  240.         mov       ecx,[ebp+8] ;o
  241.         mov       eax,[ebp+32] ;sizes_length
  242.         mov       dword[ecx+NeuralNetwork.layers_length],eax
  243.         xor       edi,edi
  244.         mov       eax,[ebp+28] ;sizes
  245.         lea       edx,[eax+4]
  246.         mov       dword[ebp-8],edx
  247.         jmp       .150
  248. .149:
  249.         xor       ecx,ecx
  250.         mov       dword[ebp-4],ecx
  251.         mov       eax,[ebp+32] ;sizes_length
  252.         dec       eax
  253.         cmp       edi,eax
  254.         jae       .152
  255.         mov       edx,[ebp-8]
  256.         mov       ecx,[edx]
  257.         mov       dword[ebp-4],ecx
  258. .152:
  259.         mov       eax,[ebp-4]
  260.         push      eax
  261.         mov       edx,[ebp-8]
  262.         mov       ecx,[edx-4]
  263.         push      ecx
  264.         mov       ecx,edi
  265.         shl       ecx,2
  266.         mov       eax,[ebp+8] ;o
  267.         mov       edx,[eax+NeuralNetwork.layers]
  268.         lea       ecx,[ecx+4*ecx]
  269.         add       edx,ecx
  270.         push      edx
  271.         call      Layer_Create
  272.         xor       esi,esi
  273.         mov       eax,[ebp-8]
  274.         lea       edx,[eax-4]
  275.         mov       dword[ebp-12],edx
  276.         jmp       .154
  277. .153:
  278.         call      Math_random
  279.         fmul      dword[f_2_0]
  280.         fsub      dword[f_1_0]
  281.         mov       eax,[ebp+8] ;o
  282.         lea       ecx,[edi+4*edi]
  283.         xor       ebx,ebx
  284.         mov       edx,[eax+NeuralNetwork.layers]
  285.         mov       ecx,[edx+4*ecx+12]
  286.         fstp      qword[ecx+8*esi]
  287.         cmp       ebx,[ebp-4]
  288.         jae       .157
  289. @@:
  290.         call      Math_random
  291.         fmul      dword[f_2_0]
  292.         fsub      dword[f_1_0]
  293.         lea       eax,[edi+4*edi]
  294.         mov       edx,[ebp+8] ;o
  295.         mov       ecx,[edx+NeuralNetwork.layers]
  296.         mov       eax,[ecx+4*eax+16]
  297.         mov       edx,[eax+4*esi]
  298.         fstp      qword[edx+8*ebx]
  299.         inc       ebx
  300.         cmp       ebx,[ebp-4]
  301.         jb        @b
  302. .157:
  303.         inc       esi
  304. .154:
  305.         mov       ecx,[ebp-12]
  306.         cmp       esi,[ecx]
  307.         jb        .153
  308.         inc       edi
  309.         add       dword[ebp-8],4
  310. .150:
  311.         cmp       edi,[ebp+32] ;sizes_length
  312.         jb        .149
  313. ;create errors array
  314.         push      dword[ebp+8]
  315.         call      NNP_GetMaxLLen
  316.         mov       esi,eax
  317.         shl       esi,4
  318.         push      esi
  319.         call      @$bnwa$qui
  320.         pop       ecx
  321.         mov       edx,[ebp+8]
  322.         mov       dword[edx+NeuralNetwork.errors],eax
  323.         shr       esi,1
  324.         add       eax,esi
  325.         mov       dword[edx+NeuralNetwork.errorsNext],eax
  326. ;create gradients array
  327.         push      esi
  328.         call      @$bnwa$qui
  329.         pop       ecx
  330.         mov       edx,[ebp+8]
  331.         mov       dword[edx+NeuralNetwork.gradients],eax
  332. ;create deltas array
  333.         shr       esi,1
  334.         push      esi
  335.         call      @$bnwa$qui
  336.         pop       ecx
  337.         mov       edx,[ebp+8]
  338.         mov       dword[edx+NeuralNetwork.deltas],eax
  339.         pop       edi esi ebx
  340.         mov       esp,ebp
  341.         pop       ebp
  342.         ret       28
  343. align 4        
  344. f_2_0:
  345.         dd 2.0
  346. f_1_0:
  347.         dd 1.0
  348.  
  349. ;+ 8 NeuralNetwork* o
  350. ;+12 double* inputs
  351. align 16
  352. NNP_FeedForward:
  353.         push      ebp
  354.         mov       ebp,esp
  355.         add       esp,-4
  356.         push      ebx esi edi
  357.         mov       eax,[ebp+8]
  358.         mov       eax,[eax+NeuralNetwork.layers]
  359.         mov       ecx,[eax+Layer.c_size]
  360.         shl       ecx,1
  361.         mov       edi,[eax+Layer.neurons]
  362.         mov       esi,[ebp+12]
  363.         rep   movsd
  364.         mov       edi,[ebp+8]
  365.         mov       esi,[edi+NeuralNetwork.layers]
  366.         sub       esi,sizeof.Layer
  367.         mov       dword[ebp-4],1 ;i = 1
  368.         jmp       .3
  369. align 4
  370. .cycle_0:
  371.         add       esi,sizeof.Layer
  372.         xor       ebx,ebx ;j=0
  373.         jmp       .2
  374. align 4
  375. .cycle_1:
  376.         mov       edx,[esi+sizeof.Layer+Layer.neurons]
  377.         xor       eax,eax
  378.         mov       dword[edx+8*ebx],eax
  379.         mov       dword[edx+8*ebx+4],eax ;l1.neurons[j] = 0
  380.         ;;xor       eax,eax ;k=0
  381.         jmp        .1
  382. align 4
  383. .cycle_2:
  384.         ;l1.neurons[j] += l.neurons[k] * l.weights[k][j]
  385.         mov       ecx,[esi+Layer.neurons] ;l.neurons
  386.         fld       qword[ecx+8*eax] ;st0 = l.neurons[k]
  387.         mov       ecx,[esi+Layer.weights]
  388.         mov       ecx,[ecx+4*eax]
  389.         fmul      qword[ecx+8*ebx] ;st0 *= l.weights[k][j]
  390.         fadd      qword[edx+8*ebx] ;st0 += l1.neurons[j]
  391.         fstp      qword[edx+8*ebx]
  392.         inc       eax ;k++
  393. .1:
  394.         cmp       eax,[esi+Layer.c_size] ;k < l.c_size
  395.         jb         .cycle_2
  396.         mov       eax,[esi+sizeof.Layer+Layer.biases]
  397.         fld       qword[eax+8*ebx]
  398.         fadd      qword[edx+8*ebx]
  399.         sub       esp,8
  400.         fstp      qword[esp] ;push l1.neurons[j]
  401.         call      dword[edi+NeuralNetwork.activation]
  402.         fstp      qword[edx+8*ebx]
  403.         inc       ebx ;j++
  404. .2:
  405.         cmp       ebx,[esi+sizeof.Layer+Layer.c_size] ;j < l1.c_size
  406.         jb        .cycle_1
  407.         inc       dword[ebp-4] ;i++
  408. .3:
  409.         mov       eax,[edi+NeuralNetwork.layers_length]
  410.         cmp       eax,[ebp-4]
  411.         ja        .cycle_0
  412.         mov       eax,[esi+sizeof.Layer+Layer.neurons]
  413.         pop       edi esi ebx
  414.         mov       esp,ebp
  415.         pop       ebp
  416.         ret       8
  417.  
  418. ;+ 8 NeuralNetwork* o
  419. ;+12 double* targets
  420. align 16
  421. NNP_BackPropagation:
  422. ;cycle_0        for (i = 0; i < l.c_size; i++)
  423. ;cycle_1        for (; k >= 0; k--)
  424. ;cycle_2                for (i = 0; i < l1.c_size; i++)
  425. ;cycle_3                for (i = 0; i < l1.c_size; i++)
  426. ;cycle_4                        for (j = 0; j < l.c_size; j++)
  427. ;cycle_5                for (i = 0; i < l.c_size; i++)
  428. ;cycle_6                        for (j = 0; j < l1.c_size; j++)
  429. ;cycle_7                for (i = 0; i < l1.c_size; i++)
  430. ;cycle_8                        for (j = 0; j < l.c_size; j++)
  431.         push      ebp
  432.         mov       ebp,esp
  433.         add       esp,-12
  434.         push      ebx esi edi
  435.         mov       esi,[ebp+8]
  436.         mov       edi,[esi+NeuralNetwork.layers_length]
  437.         dec       edi
  438.         mov       dword[ebp-4],edi ;k = o->layers_length - 1
  439.         imul      edi,sizeof.Layer
  440.         add       edi,[esi+NeuralNetwork.layers]
  441.         xor       ebx,ebx ;i=0
  442.         mov       eax,[ebp+12] ;eax = targets[]
  443.         jmp       .180
  444. align 4
  445. .cycle_0:
  446.         mov       edx,[edi+Layer.neurons]
  447.         mov       ecx,[esi+NeuralNetwork.errors]
  448.         fld       qword[eax]
  449.         fsub      qword[edx+8*ebx]
  450.         fstp      qword[ecx+8*ebx]
  451.         inc       ebx
  452.         add       eax,8
  453. .180:
  454.         cmp       ebx,[edi+Layer.c_size]
  455.         jb        .cycle_0
  456.         dec       dword[ebp-4] ;k--
  457.         cmp       dword[ebp-4],0
  458.         jl        .end_f
  459. align 4
  460. .cycle_1:
  461.         sub       edi,sizeof.Layer
  462.         xor       ebx,ebx ;i=0
  463.         jmp       .186
  464. align 4
  465. .cycle_2:
  466.         mov       eax,[edi+sizeof.Layer+Layer.neurons]
  467.         push      dword[eax+8*ebx+4]
  468.         push      dword[eax+8*ebx]
  469.         call      dword[esi+NeuralNetwork.derivative]
  470.         mov       ecx,[esi+NeuralNetwork.errors]
  471.         fmul      qword[ecx+8*ebx]
  472.         fmul      qword[esi+NeuralNetwork.learningRate]
  473.         mov       edx,[esi+NeuralNetwork.gradients]    
  474.         fstp      qword[edx+8*ebx]
  475.         inc       ebx
  476. .186:
  477.         cmp       ebx,[edi+sizeof.Layer+Layer.c_size]
  478.         jb        .cycle_2
  479.         mov       edx,[esi+NeuralNetwork.deltas]
  480.         xor       ebx,ebx
  481.         jmp       .189
  482. align 4
  483. .cycle_3:
  484.         mov       eax,[edi+Layer.c_size]
  485.         shl       eax,3
  486.         push      eax
  487.         call      @$bnwa$qui
  488.         pop       ecx
  489.         mov       dword[edx],eax
  490.         xor       eax,eax ;j=0
  491.         jmp       .191
  492. align 4
  493. .cycle_4:
  494.         mov       ecx,[esi+NeuralNetwork.gradients]
  495.         fld       qword[ecx+8*ebx]
  496.         mov       ecx,[edi+Layer.neurons]
  497.         fmul      qword[ecx+8*eax]
  498.         mov       ecx,[edx]
  499.         fstp      qword[ecx+8*eax]
  500.         inc       eax
  501. .191:
  502.         cmp       eax,[edi+Layer.c_size]
  503.         jb        .cycle_4
  504.         inc       ebx
  505.         add       edx,4
  506. .189:
  507.         cmp       ebx,[edi+sizeof.Layer+Layer.c_size]
  508.         jb        .cycle_3
  509.         xor       ebx,ebx
  510.         jmp       .195
  511. align 4
  512. .cycle_5:
  513.         mov       eax,[esi+NeuralNetwork.errorsNext]
  514.         xor       edx,edx
  515.         mov       dword[eax+8*ebx],edx
  516.         mov       dword[eax+8*ebx+4],edx
  517.         xor       eax,eax ;j=0
  518.         jmp       .197
  519. align 4
  520. .cycle_6:
  521.         mov       edx,[edi+Layer.weights]
  522.         mov       ecx,[edx+4*ebx]
  523.         mov       edx,[esi+NeuralNetwork.errors]
  524.         fld       qword[ecx+8*eax]
  525.         fmul      qword[edx+8*eax]
  526.         mov       ecx,[esi+NeuralNetwork.errorsNext]
  527.         fadd      qword[ecx+8*ebx]
  528.         fstp      qword[ecx+8*ebx]
  529.         inc       eax
  530. .197:
  531.         cmp       eax,[edi+sizeof.Layer+Layer.c_size]
  532.         jb        .cycle_6
  533.         inc       ebx
  534. .195:
  535.         cmp       ebx,[edi]
  536.         jb        .cycle_5
  537. ;copy errors to next level
  538.         mov       eax,[esi+NeuralNetwork.errors]
  539.         mov       edx,[esi+NeuralNetwork.errorsNext]
  540.         mov       dword[esi+NeuralNetwork.errors],edx
  541.         mov       dword[esi+NeuralNetwork.errorsNext],eax
  542.         mov       eax,[esi+NeuralNetwork.deltas]
  543.         mov       dword[ebp-12],eax
  544.         xor       ebx,ebx ;i=0
  545.         jmp       .201
  546. align 4
  547. .cycle_7:
  548.         mov       ecx,[esi+NeuralNetwork.gradients]
  549.         mov       eax,[edi+sizeof.Layer+Layer.biases]
  550.         fld       qword[ecx+8*ebx]
  551.         fadd      qword[eax+8*ebx]
  552.         fstp      qword[eax+8*ebx]
  553.         xor       eax,eax ;j=0
  554.         mov       edx,[ebp-12] ;edx = deltas[i]
  555.         jmp       .203
  556. align 4
  557. .cycle_8:
  558. ;       mov       ecx,[edx]
  559. ;       mov       ecx,[ecx+8*eax+4]
  560. ;       and       ecx,0x7ff80000
  561. ;       cmp       ecx,0x7ff80000
  562. ;       jne       @f
  563. ;       push      ebx
  564. ;       mov       ecx,[edx]
  565. ;       xor       ebx,ebx
  566. ;       mov       dword[ecx+8*eax],ebx
  567. ;       mov       dword[ecx+8*eax+4],ebx
  568. ;       pop       ebx
  569. ;@@:
  570.         mov       ecx,[edx]
  571.         fld       qword[ecx+8*eax]
  572.         mov       ecx,[edi+Layer.weights]
  573.         mov       ecx,[ecx+4*eax]
  574.         fadd      qword[ecx+8*ebx]
  575.         fstp      qword[ecx+8*ebx]
  576. ;       mov       ecx,[edi+Layer.weights]
  577. ;       mov       ecx,[ecx+4*eax]
  578. ;       mov       ecx,[ecx+8*ebx+4]
  579. ;       and       ecx,0x7ff80000
  580. ;       cmp       ecx,0x7ff80000
  581. ;       jne       @f
  582. ;       mov       ecx,[edi+Layer.weights]
  583. ;       mov       ecx,[ecx+4*eax]
  584. ;       push      edx
  585. ;       xor       edx,edx
  586. ;       mov       dword[ecx+8*ebx],edx
  587. ;       mov       dword[ecx+8*ebx+4],edx
  588. ;       pop       edx
  589. ;@@:
  590.         inc       eax
  591. .203:
  592.         cmp       eax,[edi+Layer.c_size]
  593.         jb        .cycle_8
  594.         mov       eax,[ebp-12]
  595.         stdcall   @$bdele$qpv, [eax]
  596.         pop       ecx
  597.         inc       ebx
  598.         add       dword[ebp-12],4
  599. .201:
  600.         cmp       ebx,[edi+sizeof.Layer+Layer.c_size]
  601.         jb        .cycle_7
  602.         dec       dword[ebp-4]
  603.         cmp       dword[ebp-4],0
  604.         jge       .cycle_1
  605. .end_f:
  606.         pop       edi esi ebx
  607.         mov       esp,ebp
  608.         pop       ebp
  609.         ret       8
  610.  
  611.  
  612. ;NNP_GetMemSize:
  613. ; todo
  614.  
  615. ;+ 8 NeuralNetwork* o
  616. ;+12 unsigned long fmt
  617. ;+16 char* m_data
  618. align 16
  619. NNP_GetMemData:
  620.         push      ebp
  621.         mov       ebp,esp
  622.         add       esp,-12
  623.         push      ebx esi edi
  624.         cmp       dword[ebp+12],1852797802
  625.         jne       .end_f
  626.         mov       esi,[ebp+16]
  627.         mov       byte[esi],0
  628.         stdcall   [_strcat], esi,txt_QlearningRateQ_
  629.         add       esp,8
  630.         push      1
  631.         push      PRECISION
  632.         mov       eax,[ebp+8]
  633.         push      dword[eax+NeuralNetwork.learningRate+4]
  634.         push      dword[eax+NeuralNetwork.learningRate]
  635.         call      @@DoubleToStr$qduso
  636.         add       esp,16
  637.         stdcall   [_strcat], esi,eax
  638.         add       esp,8
  639.         stdcall   [_strcat], esi,txt_zap_nl
  640.         add       esp,8
  641.         stdcall   [_strcat], esi,txt_Qlayers_lengthQ
  642.         add       esp,8
  643.         push      1
  644.         push      0
  645.         mov       ecx,[ebp+8]
  646.         fild      dword[ecx+NeuralNetwork.layers_length]
  647.         add       esp,-8
  648.         fstp      qword[esp]
  649.         call      @@DoubleToStr$qduso
  650.         add       esp,16
  651.         stdcall   [_strcat], esi,eax
  652.         add       esp,8
  653.         stdcall   [_strcat], esi,txt_zap_nl
  654.         add       esp,8
  655. .230:
  656.         stdcall   [_strcat], esi,txt_QlayersQ
  657.         add       esp,8
  658.         xor       edi,edi ;i=0
  659.         jmp       .232
  660. align 4
  661. .cycle_0:
  662.         push      esi
  663.         call      @@strlen$qpxc
  664.         pop       ecx
  665.         add       esi,eax
  666.         stdcall   [_strcat], esi,txt_nl_t_Qc_sizeQ
  667.         add       esp,8
  668.         lea       ebx,[edi+4*edi]
  669.         push      1
  670.         push      0
  671.         mov       eax,[ebp+8]
  672.         mov       edx,[eax+8]
  673.         xor       eax,eax
  674.         add       esp,-8
  675.         mov       ecx,[edx+4*ebx]
  676.         mov       dword[ebp-12],ecx
  677.         mov       dword[ebp-8],eax
  678.         fild      qword[ebp-12]
  679.         fstp      qword[esp]
  680.         call      @@DoubleToStr$qduso
  681.         add       esp,16
  682.         stdcall   [_strcat], esi,eax
  683.         add       esp,8
  684.         stdcall   [_strcat], esi,txt_zap_nl_t_Qn_sizeQ
  685.         add       esp,8
  686.         push      1
  687.         push      0
  688.         mov       edx,[ebp+8]
  689.         mov       ecx,[edx+8]
  690.         xor       edx,edx
  691.         add       esp,-8
  692.         mov       eax,[ecx+4*ebx+4]
  693.         mov       dword[ebp-12],eax
  694.         mov       dword[ebp-8],edx
  695.         fild      qword[ebp-12]
  696.         fstp      qword[esp]
  697.         call      @@DoubleToStr$qduso
  698.         add       esp,16
  699.         stdcall   [_strcat], esi,eax
  700.         add       esp,8
  701.         stdcall   [_strcat], esi,txt_zap_nl
  702.         add       esp,8
  703.         stdcall   [_strcat], esi,txt_t_QneuronsQ
  704.         add       esp,8
  705.         xor       ebx,ebx ;j=0
  706.         jmp       .234
  707. align 4
  708. .cycle_1:
  709.         test      ebx,ebx
  710.         je        .235
  711.         stdcall   [_strcat], esi,txt_zap_sp
  712.         add       esp,8
  713. .235:
  714.         push      1
  715.         push      PRECISION
  716.         lea       eax,[edi+4*edi]
  717.         mov       edx,[ebp+8]
  718.         mov       ecx,[edx+8]
  719.         mov       eax,[ecx+4*eax+8]
  720.         push      dword[eax+8*ebx+4]
  721.         push      dword[eax+8*ebx]
  722.         call      @@DoubleToStr$qduso
  723.         add       esp,16
  724.         stdcall   [_strcat], esi,eax
  725.         add       esp,8
  726.         inc       ebx
  727. .234:
  728.         mov       ecx,edi
  729.         imul      ecx,sizeof.Layer
  730.         mov       eax,[ebp+8]
  731.         add       ecx,[eax+NeuralNetwork.layers]
  732.         cmp       ebx,[ecx+Layer.c_size]
  733.         jb        .cycle_1
  734.         stdcall   [_strcat], esi,txt_sqbr_zap_nl
  735.         add       esp,8
  736.         stdcall   [_strcat], esi,txt_t_QbiasesQ
  737.         add       esp,8
  738.         xor       ebx,ebx ;j=0
  739.         jmp       .238
  740. align 4
  741. .cycle_2:
  742.         test      ebx,ebx
  743.         je        .239
  744.         stdcall   [_strcat], esi,txt_zap_sp
  745.         add       esp,8
  746. .239:
  747.         push      1
  748.         push      PRECISION
  749.         lea       eax,[edi+4*edi]
  750.         mov       edx,[ebp+8]
  751.         mov       ecx,[edx+8]
  752.         mov       eax,[ecx+4*eax+12]
  753.         push      dword[eax+8*ebx+4]
  754.         push      dword[eax+8*ebx]
  755.         call      @@DoubleToStr$qduso
  756.         add       esp,16
  757.         stdcall   [_strcat], esi,eax
  758.         add       esp,8
  759.         inc       ebx
  760. .238:
  761.         lea       ecx,[edi+4*edi]
  762.         mov       eax,[ebp+8]
  763.         mov       edx,[eax+8]
  764.         cmp       ebx,[edx+4*ecx]
  765.         jb        .cycle_2
  766.         stdcall   [_strcat], esi,txt_sqbr_zap_t_QweightsQ
  767.         add       esp,8
  768.         mov       eax,[ebp+8]
  769.         lea       ecx,[edi+4*edi]
  770.         mov       edx,[eax+8]
  771.         cmp       dword[edx+4*ecx+4],0
  772.         je        .241
  773.         xor       ebx,ebx
  774.         jmp       .243
  775. .242:
  776.         test      ebx,ebx
  777.         je        .244
  778.         stdcall   [_strcat], esi,txt_zap_nl_t_t
  779.         add       esp,8
  780. .244:
  781.         stdcall   [_strcat], esi,txt_sqbro
  782.         add       esp,8
  783.         xor       eax,eax
  784.         mov       dword[ebp-4],eax
  785.         jmp       .246
  786. .245:
  787.         cmp       dword[ebp-4],0
  788.         je        .247
  789.         stdcall   [_strcat], esi,txt_zap_sp
  790.         add       esp,8
  791. .247:
  792.         push      1
  793.         push      PRECISION
  794.         lea       edx,[edi+4*edi]
  795.         mov       ecx,[ebp+8]
  796.         mov       eax,[ecx+8]
  797.         mov       edx,[eax+4*edx+16]
  798.         mov       ecx,[edx+4*ebx]
  799.         mov       eax,[ebp-4]
  800.         push      dword[ecx+8*eax+4]
  801.         push      dword[ecx+8*eax]
  802. @@:
  803.         call      @@DoubleToStr$qduso
  804.         dec       dword[esp+8] ;уменьшаем PRECISION
  805.         jz        @f           ;для избежания зацикливания
  806.         cmp       word[eax],'#'
  807.         je        @b           ;если число не поместилось пробуем перевести с меньшей точностью
  808. @@:
  809.         add       esp,16
  810.         stdcall   [_strcat], esi,eax
  811.         add       esp,8
  812.         inc       dword[ebp-4]
  813. .246:
  814.         lea       ecx,[edi+4*edi]
  815.         mov       eax,[ebp+8]
  816.         mov       edx,[eax+8]
  817.         mov       ecx,[edx+4*ecx+4]
  818.         cmp       ecx,[ebp-4]
  819.         ja        .245
  820.         stdcall   [_strcat], esi,txt_sqbr
  821.         add       esp,8
  822.         inc       ebx
  823. .243:
  824.         lea       eax,[edi+4*edi]
  825.         mov       edx,[ebp+8]
  826.         mov       ecx,[edx+8]
  827.         cmp       ebx,[ecx+4*eax]
  828.         jb        .242
  829. .241:
  830.         stdcall   [_strcat], esi,txt_sqbr_fbr_zap
  831.         add       esp,8
  832.         inc       edi
  833. .232:
  834.         mov       eax,[ebp+8]
  835.         cmp       edi,[eax+NeuralNetwork.layers_length]
  836.         jb        .cycle_0
  837.         stdcall   [_strcat], esi,txt_nl_t_sqbr
  838.         add       esp,8
  839. .end_f:
  840.         pop       edi esi ebx
  841.         mov       esp,ebp
  842.         pop       ebp
  843.         ret       12
  844.  
  845. ;+ 8 NeuralNetwork* o
  846. align 16
  847. NNP_GetMaxLLen:
  848.         push      ebp
  849.         mov       ebp,esp
  850.         push      ebx esi
  851.         mov       ebx,[ebp+8]
  852.         cmp       dword[ebx+NeuralNetwork.layers_length],1
  853.         jge       .1
  854.         xor       eax,eax
  855.         jmp       .5
  856. .1:
  857.         mov       edx,[ebx+NeuralNetwork.layers]
  858.         mov       eax,[ebx+NeuralNetwork.layers]
  859.         add       eax,sizeof.Layer
  860.         mov       ecx,[edx]
  861.         mov       edx,1
  862.         jmp       .4
  863. .2:
  864.         mov       esi,[eax]
  865.         cmp       esi,ecx
  866.         jbe       .3
  867.         mov       ecx,esi
  868. .3:
  869.         inc       edx
  870.         add       eax,sizeof.Layer
  871. .4:
  872.         cmp       edx,[ebx+NeuralNetwork.layers_length]
  873.         jl        .2
  874.         mov       eax,ecx
  875. .5:
  876.         pop       esi ebx ebp
  877.         ret       4
  878.  
  879. ;+ 8 NeuralNetwork* o
  880. ;+12 unsigned long fmt
  881. ;+16 void* m_data
  882. align 16
  883. NNP_SetMemData:
  884.         push      ebp
  885.         mov       ebp,esp
  886.         add       esp,-12
  887.         push      ebx esi edi
  888.         mov       eax,[ebp+16]
  889.         mov       edx,[ebp+12]
  890. ;       cmp       edx,NNP_FF_BIN
  891. ;       jne       .191
  892. ;...
  893. ;.191:
  894.         cmp       edx,NNP_FF_JSON
  895.         jne       .198
  896. .199:
  897.         stdcall   @@strstr$qpxct1, eax,txt_learningRate
  898.         add       esp,8
  899.         mov       esi,eax
  900.         stdcall   @@strstr$qpxct1, esi,txt_layers_length
  901.         add       esp,8
  902.         mov       esi,eax
  903.         test      esi,esi
  904.         jne       .200
  905.         mov       eax,1
  906.         jmp       .193
  907. .200:
  908.         stdcall   @@strchr$qpxci, esi,':'
  909.         add       esp,8
  910.         mov       ebx,eax
  911.         test      ebx,ebx
  912.         jne       .201
  913.         mov       eax,2
  914.         jmp       .193
  915. .201:
  916.         inc       ebx
  917.         stdcall   @@strchr$qpxci, esi,','
  918.         add       esp,8
  919.         mov       esi,eax
  920.         test      esi,esi
  921.         jne       .202
  922.         mov       eax,3
  923.         jmp       .193
  924. .202:
  925.         mov       byte[esi],0
  926.         inc       esi
  927.         stdcall   @@StrToInt$qpc, ebx
  928.         pop       ecx
  929.         mov       dword[ebp-4],eax
  930.         ;lea       eax,[ebp-4]
  931.         ;stdcall   [_scanf], ebx,txt_pri_zap,eax
  932.         ;add       esp,12
  933.         mov       eax,[ebp+8]
  934.         mov       edx,[eax+12]
  935.         cmp       edx,[ebp-4]
  936.         je        .203
  937.         mov       eax,4
  938.         jmp       .193
  939. .203:
  940.         xor       edi,edi
  941.         jmp       .205
  942. .204:
  943.         stdcall   @@strstr$qpxct1, esi,txt_c_size
  944.         add       esp,8
  945.         mov       esi,eax
  946.         test      esi,esi
  947.         jne        .206
  948.         mov       eax,5
  949.         jmp       .193
  950. .206:
  951.         stdcall   @@strchr$qpxci, esi,':'
  952.         add       esp,8
  953.         mov       ebx,eax
  954.         test      ebx,ebx
  955.         jne        .207
  956.         mov       eax,6
  957.         jmp       .193
  958. .207:
  959.         inc       ebx
  960.         stdcall   @@strchr$qpxci, esi,','
  961.         add       esp,8
  962.         mov       esi,eax
  963.         test      esi,esi
  964.         jne        .208
  965.         mov       eax,7
  966.         jmp       .193
  967. .208:
  968.         mov       byte[esi],0
  969.         inc       esi
  970.         stdcall   @@StrToInt$qpc, ebx
  971.         pop       ecx
  972.         mov       dword[ebp-4],eax
  973.         stdcall   @@strstr$qpxct1, esi,txt_n_size
  974.         add       esp,8
  975.         mov       esi,eax
  976.         test      esi,esi
  977.         jne       .209
  978.         mov       eax,8
  979.         jmp       .193
  980. .209:
  981.         stdcall   @@strchr$qpxci, esi,':'
  982.         add       esp,8
  983.         mov       ebx,eax
  984.         test      ebx,ebx
  985.         jne       .210
  986.         mov       eax,9
  987.         jmp       .193
  988. .210:
  989.         inc       ebx
  990.         stdcall   @@strchr$qpxci, esi,','
  991.         add       esp,8
  992.         mov       esi,eax
  993.         test      esi,esi
  994.         jne       .211
  995.         mov       eax,10
  996.         jmp       .193
  997. .211:
  998.         mov       byte[esi],0
  999.         inc       esi
  1000.         push      ebx
  1001.         call      @@StrToInt$qpc
  1002.         pop       ecx
  1003.         mov       dword[ebp-8],eax
  1004.         lea       eax,[edi+4*edi]
  1005.         mov       edx,[ebp+8]
  1006.         mov       ecx,[edx+8]
  1007.         mov       edx,[ecx+4*eax]
  1008.         cmp       edx,[ebp-4]
  1009.         jne       .213
  1010.         mov       ecx,[ebp+8]
  1011.         mov       edx,[ecx+8]
  1012.         mov       eax,[edx+4*eax+4]
  1013.         cmp       eax,[ebp-8]
  1014.         je        .214
  1015. .213:
  1016.         mov       ecx,[ebp+8]
  1017.         push      ecx
  1018.         call      NNP_GetMaxLLen
  1019.         mov       ecx,edi
  1020.         mov       ebx,eax
  1021.         shl       ecx,2
  1022.         mov       eax,[ebp+8]
  1023.         mov       edx,[eax+8]
  1024.         lea       ecx,[ecx+4*ecx]
  1025.         add       edx,ecx
  1026.         push      edx
  1027.         call      Layer_Destroy
  1028.         mov       eax,[ebp-8]
  1029.         push      eax
  1030.         mov       edx,[ebp-4]
  1031.         push      edx
  1032.         mov       edx,edi
  1033.         shl       edx,2
  1034.         mov       ecx,[ebp+8]
  1035.         mov       eax,[ecx+8]
  1036.         lea       edx,[edx+4*edx]
  1037.         add       eax,edx
  1038.         push      eax
  1039.         call      Layer_Create
  1040.         cmp       ebx,[ebp-4] ;if(n>s || k>s)
  1041.         jb        .215
  1042.         cmp       ebx,[ebp-8]
  1043.         jae       .214
  1044. .215:
  1045.         mov       edx,[ebp+8]
  1046.         mov       ecx,[edx+NeuralNetwork.errors]
  1047.         cmp       ecx,[edx+NeuralNetwork.errorsNext]
  1048.         jl        @f
  1049.         mov       ecx,[edx+NeuralNetwork.errorsNext]
  1050. @@:
  1051.         mov       ebx,[ebp-4]
  1052.         cmp       ebx,[ebp-8]
  1053.         jge       @f
  1054.         mov       ebx,[ebp-8]
  1055. @@:
  1056.         shl       ebx,4
  1057.         stdcall   [mem.realloc], ecx,ebx
  1058.         mov       edx,[ebp+8]
  1059.         mov       dword[edx+NeuralNetwork.errors],eax
  1060.         shr       ebx,1
  1061.         add       eax,ebx
  1062.         mov       dword[edx+NeuralNetwork.errorsNext],eax
  1063.         stdcall   [mem.realloc], [edx+NeuralNetwork.gradients],ebx
  1064.         mov       edx,[ebp+8]
  1065.         mov       dword[edx+NeuralNetwork.gradients],eax
  1066.         shr       ebx,1
  1067.         stdcall   [mem.realloc], [edx+NeuralNetwork.deltas],ebx
  1068.         mov       edx,[ebp+8]
  1069.         mov       dword[edx+NeuralNetwork.deltas],eax
  1070. .214:
  1071.         stdcall   @@strstr$qpxct1, esi,txt_biases
  1072.         add       esp,8
  1073.         mov       esi,eax
  1074.         test      esi,esi
  1075.         jne       .216
  1076.         mov       eax,11
  1077.         jmp       .193
  1078. .216:
  1079.         stdcall   @@strchr$qpxci, esi,'['
  1080.         add       esp,8
  1081.         mov       ebx,eax
  1082.         test      ebx,ebx
  1083.         jne        .217
  1084.         mov       eax,12
  1085.         jmp       .193
  1086. .217:
  1087.         inc       ebx
  1088.         xor       edx,edx
  1089.         mov       dword[ebp-8],edx
  1090.         jmp        .219
  1091. .218:
  1092.         mov       esi,[ebp+8]
  1093.         dec       edx
  1094.         cmp       eax,edx
  1095.         lea       ecx,[edi+4*edi]
  1096.         mov       esi,[esi+8]
  1097.         jae        .220
  1098.         stdcall   @@strchr$qpxci, ebx,','
  1099.         add       esp,8
  1100.         mov       esi,eax
  1101.         jmp        .221
  1102. .220:
  1103.         stdcall   @@strchr$qpxci, ebx,']'
  1104.         add       esp,8
  1105.         mov       esi,eax
  1106. .221:
  1107.         test      esi,esi
  1108.         jne        .222
  1109.         mov       eax,13
  1110.         jmp       .193
  1111. .222:
  1112.         mov       byte[esi],0
  1113.         push      ebx
  1114.         call      @@StrToDouble$qpc
  1115.         pop       ecx
  1116.         lea       edx,[edi+4*edi]
  1117.         mov       ecx,[ebp+8]
  1118.         lea       ebx,[esi+1]
  1119.         mov       eax,[ecx+8]
  1120.         mov       ecx,[ebp-8]
  1121.         mov       edx,[eax+4*edx+12]
  1122.         fstp      qword[edx+8*ecx]
  1123.         inc       dword[ebp-8]
  1124. .219:
  1125.         lea       edx,[edi+4*edi]
  1126.         mov       ecx,[ebp+8]
  1127.         mov       ecx,[ecx+8]
  1128.         mov       edx,[ecx+4*edx]
  1129.         mov       eax,[ebp-8]
  1130.         cmp       edx,eax
  1131.         ja        .218
  1132.         mov       esi,ebx
  1133.         stdcall   @@strstr$qpxct1, esi,txt_weights
  1134.         add       esp,8
  1135.         mov       esi,eax
  1136.         test      esi,esi
  1137.         jne       .224
  1138.         mov       eax,14
  1139.         jmp       .193
  1140. .224:
  1141.         stdcall   @@strchr$qpxci, esi,'['
  1142.         add       esp,8
  1143.         mov       esi,eax
  1144.         test      esi,esi
  1145.         jne        .225
  1146.         mov       eax,15
  1147.         jmp       .193
  1148. .225:
  1149.         inc       esi
  1150.         xor       edx,edx
  1151.         mov       dword[ebp-8],edx
  1152.         jmp       .227
  1153. .226:
  1154.         stdcall   @@strchr$qpxci, esi,'['
  1155.         add       esp,8
  1156.         mov       ebx,eax
  1157.         test      ebx,ebx
  1158.         jne        .228
  1159.         mov       eax,16
  1160.         jmp       .193
  1161. .228:
  1162.         inc       ebx
  1163.         xor       edx,edx
  1164.         mov       dword[ebp-12],edx
  1165.         jmp        .230
  1166. .229:
  1167.         mov       esi,[ebp+8]
  1168.         dec       edx
  1169.         cmp       eax,edx
  1170.         lea       ecx,[edi+4*edi]
  1171.         mov       esi,[esi+8]
  1172.         jae        .231
  1173.         stdcall   @@strchr$qpxci, ebx,','
  1174.         add       esp,8
  1175.         mov       esi,eax
  1176.         jmp        .232
  1177. .231:
  1178.         stdcall   @@strchr$qpxci, ebx,']'
  1179.         add       esp,8
  1180.         mov       esi,eax
  1181. .232:
  1182.         test      esi,esi
  1183.         jne        .233
  1184.         mov       eax,17
  1185.         jmp        .193
  1186. .233:
  1187.         mov       byte[esi],0
  1188.         push      ebx
  1189.         call      @@StrToDouble$qpc
  1190.         pop       ecx
  1191.         lea       edx,[edi+4*edi]
  1192.         mov       ecx,[ebp+8]
  1193.         lea       ebx,[esi+1]
  1194.         mov       eax,[ecx+8]
  1195.         mov       ecx,[ebp-8]
  1196.         mov       edx,[eax+4*edx+16]
  1197.         mov       eax,[edx+4*ecx]
  1198.         mov       edx,[ebp-12]
  1199.         fstp      qword[eax+8*edx]
  1200.         inc       dword[ebp-12]
  1201. .230:
  1202.         lea       edx,[edi+4*edi]
  1203.         mov       ecx,[ebp+8]
  1204.         mov       ecx,[ecx+8]
  1205.         mov       edx,[ecx+4*edx+4]
  1206.         mov       eax,[ebp-12]
  1207.         cmp       edx,eax
  1208.         ja         .229
  1209.         mov       esi,ebx
  1210.         inc       dword[ebp-8]
  1211. .227:
  1212.         lea       eax,[edi+4*edi]
  1213.         mov       edx,[ebp+8]
  1214.         mov       ecx,[edx+8]
  1215.         mov       eax,[ecx+4*eax]
  1216.         cmp       eax,[ebp-8]
  1217.         ja        .226
  1218.         inc       edi
  1219. .205:
  1220.         mov       edx,[ebp+8]
  1221.         cmp       edi,[edx+12]
  1222.         jb        .204
  1223.         xor       eax,eax
  1224.         jmp        .193
  1225. .198:
  1226.         mov       eax,1000
  1227. .193:
  1228.         pop       edi esi ebx
  1229.         mov       esp,ebp
  1230.         pop       ebp
  1231.         ret       12
  1232.  
  1233. align 16
  1234. Layer_Destroy:
  1235.         push      ebp
  1236.         mov       ebp,esp
  1237.         push      ebx esi
  1238.         mov       esi,[ebp+8]
  1239.         push      dword[esi+Layer.neurons]
  1240.         call      @$bdele$qpv
  1241.         pop       ecx
  1242.         push      dword[esi+Layer.biases]
  1243.         call      @$bdele$qpv
  1244.         pop       ecx
  1245.         xor       ebx,ebx
  1246.         jmp       .143
  1247. .142:
  1248.         mov       eax,[esi+Layer.weights]
  1249.         push      dword[eax+4*ebx]
  1250.         call      @$bdele$qpv
  1251.         pop       ecx
  1252.         inc       ebx
  1253. .143:
  1254.         cmp       ebx,[esi+Layer.c_size]
  1255.         jb        .142
  1256.         push      dword[esi+Layer.weights]
  1257.         call      @$bdele$qpv
  1258.         pop       ecx
  1259. .145:
  1260.         pop       esi ebx ebp
  1261.         ret       4
  1262.  
  1263. align 16
  1264. NNP_Destroy:
  1265.         push      ebp
  1266.         mov       ebp,esp
  1267.         push      ebx esi
  1268.         mov       esi,[ebp+8]
  1269.         xor       ebx,ebx
  1270.         jmp       .232
  1271. .231:
  1272.         mov       eax,ebx
  1273.         imul      eax,sizeof.Layer
  1274.         add       eax,[esi+NeuralNetwork.layers]
  1275.         push      eax
  1276.         call      Layer_Destroy
  1277.         inc       ebx
  1278. .232:
  1279.         cmp       ebx,[esi+NeuralNetwork.layers_length]
  1280.         jb        .231
  1281.         push      dword[esi+NeuralNetwork.layers]
  1282.         call      @$bdele$qpv
  1283.         pop       ecx
  1284. ;
  1285.         mov       ecx,[esi+NeuralNetwork.errors]
  1286.         cmp       ecx,[esi+NeuralNetwork.errorsNext]
  1287.         jl        @f
  1288.         mov       ecx,[esi+NeuralNetwork.errorsNext]
  1289. @@:
  1290.         push      ecx
  1291.         call      @$bdele$qpv
  1292.         pop       ecx
  1293. ;
  1294.         push      dword[esi+NeuralNetwork.gradients]
  1295.         call      @$bdele$qpv
  1296.         pop       ecx
  1297. ;
  1298.         push      dword[esi+NeuralNetwork.deltas]
  1299.         call      @$bdele$qpv
  1300.         pop       ecx
  1301.         pop       esi ebx ebp
  1302.         ret       4
  1303.  
  1304.  
  1305. align 16
  1306. EXPORTS:
  1307.         dd sz_lib_init, lib_init
  1308.         dd sz_create, NNP_Create
  1309.         dd sz_feedforward, NNP_FeedForward
  1310.         dd sz_backpropagation, NNP_BackPropagation
  1311.         dd sz_getmemdata, NNP_GetMemData
  1312.         dd sz_setmemdata, NNP_SetMemData
  1313.         dd sz_destroy, NNP_Destroy
  1314.         dd 0,0
  1315.         sz_lib_init db 'lib_init',0
  1316.         sz_create db 'NNP_Create',0
  1317.         sz_feedforward db 'NNP_FeedForward',0
  1318.         sz_backpropagation db 'NNP_BackPropagation',0
  1319.         sz_getmemdata db 'NNP_GetMemData',0
  1320.         sz_setmemdata db 'NNP_SetMemData',0
  1321.         sz_destroy db 'NNP_Destroy',0
  1322.  
  1323. align 16
  1324. @IMPORT:
  1325.  
  1326. library \
  1327.         libc, 'libc.obj'
  1328.  
  1329. import libc, \
  1330. _strcat, 'strcat',\
  1331. _exp,    'exp'
  1332. ;_scanf,  'scanf',\ ;???
  1333.