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