update library 'nnp.obj'

git-svn-id: svn://kolibrios.org@9821 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2022-05-28 12:21:03 +00:00
parent f483bc78e4
commit 2ee9123f08
9 changed files with 1008 additions and 162 deletions

View File

@ -53,6 +53,7 @@ table { font-size: 15px; }
<ul> <ul>
<li><a href="#f_init">lib_init</a></li> <li><a href="#f_init">lib_init</a></li>
<li><a href="#f_create">NNP_Create</a></li> <li><a href="#f_create">NNP_Create</a></li>
<li><a href="#f_reset">NNP_Reset</a></li>
<li><a href="#f_feedf">NNP_FeedForward</a></li> <li><a href="#f_feedf">NNP_FeedForward</a></li>
<li><a href="#f_backp">NNP_BackPropagation</a></li> <li><a href="#f_backp">NNP_BackPropagation</a></li>
<li><a href="#f_getmd">NNP_GetMemData</a></li> <li><a href="#f_getmd">NNP_GetMemData</a></li>
@ -62,6 +63,7 @@ table { font-size: 15px; }
</li> </li>
<li><a href="#const">Константы</a></li> <li><a href="#const">Константы</a></li>
<li><a href="#tabl_e">Таблица экспорта</a></li> <li><a href="#tabl_e">Таблица экспорта</a></li>
<li><a href="#ex1">Пример</a></li>
<li><a href="#hist">История</a></li> <li><a href="#hist">История</a></li>
</ul> </ul>
@ -69,7 +71,7 @@ table { font-size: 15px; }
<p>Документация к библиотеке <b>nnp.obj</b>, для <b>ОС Колибри</b>. Эта библиотека создана для работы с нейросетями (neural network perceptron). Видео по нейросетям: <a href="https://www.youtube.com/watch?v=GNcGPw_Kb_0">1</a>, <p>Документация к библиотеке <b>nnp.obj</b>, для <b>ОС Колибри</b>. Эта библиотека создана для работы с нейросетями (neural network perceptron). Видео по нейросетям: <a href="https://www.youtube.com/watch?v=GNcGPw_Kb_0">1</a>,
<a href="https://www.youtube.com/watch?v=wzIOl4hWP3U">2</a>. Исходный код (язык java), на основе которого делалсь библиотека: <a href="https://github.com/ArtemOnigiri/SimpleNN">3</a>.</p> <a href="https://www.youtube.com/watch?v=wzIOl4hWP3U">2</a>. Исходный код (язык java), на основе которого делалсь библиотека: <a href="https://github.com/ArtemOnigiri/SimpleNN">3</a>.</p>
<p>Последнее обновление библиотеки 01.03.22.</p> <p>Последнее обновление библиотеки 28.05.22.</p>
<h1><a name="fun">Функции</a></h1> <h1><a name="fun">Функции</a></h1>
@ -96,40 +98,45 @@ ends</pre>
nnlopt dd 2,8,8,8,8,8,3 nnlopt dd 2,8,8,8,8,8,3
... ...
stdcall [NNP_Create], nnp_0, 0.01, 0, 0, nnlopt, NNLOPT_LEN</pre> stdcall [NNP_Create], nnp_0, 0.01, 0, 0, nnlopt, NNLOPT_LEN</pre>
<p>где nnp_0 - структура буфера.</p> <p>где nnp_0 - структура нейросети.</p>
<p>0.01 - скорость обучения.</p> <p>0.01 - скорость обучения.</p>
<p>0 - адрес функции активации, если 0 то берется стандартная функция внутри библиотеки.</p> <p>0 - адрес функции активации, если 0 то берется стандартная функция внутри библиотеки.</p>
<p>0 - адрес функции свёртки, если 0 то берется стандартная функция внутри библиотеки.</p> <p>0 - адрес функции свёртки, если 0 то берется стандартная функция внутри библиотеки.</p>
<p>nnlopt - массив с числом нейронов на каждом слое.</p> <p>nnlopt - массив с числом нейронов на каждом слое.</p>
<p>NNLOPT_LEN - длинна массива nnlopt.</p> <p>NNLOPT_LEN - длинна массива nnlopt.</p>
<h4><a name="f_reset">NNP_Reset</a></h4>
<p>Сброс параметров нейросети. Для каждого слоя базисный вектор и веса заполняются случайными числами от -1 до 1. Такие же действия происходят в конструкторе NNP_Create.</p>
<pre>stdcall [NNP_Reset], nnp_0</pre>
<p>где nnp_0 - структура нейросети.</p>
<h4><a name="f_feedf">NNP_FeedForward</a></h4> <h4><a name="f_feedf">NNP_FeedForward</a></h4>
<p>Функция расчета значений выходных нейронов. На вход подаються значения входных нейронов. На выходе возвращается указатель на слой выходных нейронов.</p> <p>Функция расчета значений выходных нейронов. На вход подаються значения входных нейронов. На выходе возвращается указатель на слой выходных нейронов.</p>
<pre>n_input dq ?,?,? <pre>n_input dq ?,?,?
... ...
stdcall [NNP_FeedForward], nnp_0,n_input</pre> stdcall [NNP_FeedForward], nnp_0,n_input</pre>
<p>где nnp_0 - структура буфера, n_input - указатель на данные входных нейронов.</p> <p>где nnp_0 - структура нейросети, n_input - указатель на данные входных нейронов.</p>
<h4><a name="f_backp">NNP_BackPropagation</a></h4> <h4><a name="f_backp">NNP_BackPropagation</a></h4>
<p>Функция для обучения сети. Пример:</p> <p>Функция для обучения сети. Пример:</p>
<pre>n_targ dq ?,?,? <pre>n_targ dq ?,?,?
... ...
stdcall [NNP_BackPropagation], nnp_0, n_targ</pre> stdcall [NNP_BackPropagation], nnp_0, n_targ</pre>
<p>где nnp_0 - структура буфера, n_targ - указатель на данные для обучения сети.</p> <p>где nnp_0 - структура нейросети, n_targ - указатель на данные для обучения сети.</p>
<h4><a name="f_getmd">NNP_GetMemData</a></h4> <h4><a name="f_getmd">NNP_GetMemData</a></h4>
<p>Берет данные нейросети и записывает их в указанное место в памяти. Пример:</p> <p>Берет данные нейросети и записывает их в указанное место в памяти. Пример:</p>
<pre>f_data dd ? <pre>f_data dd ?
... ...
stdcall [NNP_GetMemData], nnp_0, NNP_FF_JSON, [f_data]</pre> stdcall [NNP_GetMemData], nnp_0, NNP_FF_JSON, [f_data]</pre>
<p>где nnp_0 - структура буфера, f_data - указатель на данные для записи параметров сети.</p> <p>где nnp_0 - структура нейросети, f_data - указатель на данные для записи параметров сети.</p>
<h4><a name="f_setmd">NNP_SetMemData</a></h4> <h4><a name="f_setmd">NNP_SetMemData</a></h4>
<p>Берет данные из указанного места памяти и записывает их в нейросеть. Пример:</p> <p>Берет данные из указанного места памяти и записывает их в нейросеть. В случае успеха в регистре eax возвращается 0, иначе указатель на строку с текстом ошибки. Пример:</p>
<pre>f_data dd ? <pre>f_data dd ?
... ...
stdcall [NNP_SetMemData], nnp_0, NNP_FF_JSON, [f_data]</pre> stdcall [NNP_SetMemData], nnp_0, NNP_FF_JSON, [f_data]</pre>
<p>где nnp_0 - структура буфера, f_data - указатель на данные с параметрами сети.</p> <p>где nnp_0 - структура нейросети, f_data - указатель на данные с параметрами сети.</p>
<h4><a name="f_delete">NNP_Destroy</a></h4> <h4><a name="f_delete">NNP_Destroy</a></h4>
<p>Освобождает память занятую нейросетью.</p> <p>Освобождает память занятую нейросетью.</p>
@ -145,24 +152,31 @@ stdcall [NNP_SetMemData], nnp_0, NNP_FF_JSON, [f_data]</pre>
<pre>align 4 <pre>align 4
import_nnp_lib: import_nnp_lib:
dd sz_lib_init dd sz_lib_init
NNP_Create dd sz_nnp_create NNP_Create dd sz_create
NNP_FeedForward dd sz_nnp_FeedForward NNP_Reset dd sz_reset
NNP_BackPropagation dd sz_nnp_BackPropagation NNP_FeedForward dd sz_feedforward
NNP_GetMemData dd sz_nnp_GetMemData NNP_BackPropagation dd sz_backpropagation
NNP_SetMemData dd sz_nnp_SetMemData NNP_GetMemData dd sz_getmemdata
NNP_Destroy dd sz_nnp_Destroy NNP_SetMemData dd sz_setmemdata
dd 0,0 NNP_Destroy dd sz_destroy
dd 0,0
sz_lib_init db 'lib_init',0 sz_lib_init db 'lib_init',0
sz_nnp_create db 'NNP_Create',0 sz_create db 'NNP_Create',0
sz_nnp_FeedForward db 'NNP_FeedForward',0 sz_reset db 'NNP_Reset',0
sz_nnp_BackPropagation db 'NNP_BackPropagation',0 sz_feedforward db 'NNP_FeedForward',0
sz_nnp_GetMemData db 'NNP_GetMemData',0 sz_backpropagation db 'NNP_BackPropagation',0
sz_nnp_SetMemData db 'NNP_SetMemData',0 sz_getmemdata db 'NNP_GetMemData',0
sz_nnp_Destroy db 'NNP_Destroy',0 sz_setmemdata db 'NNP_SetMemData',0
sz_destroy db 'NNP_Destroy',0
</pre> </pre>
<h1><a name="hist">История</a></h1> <h1><a name="ex1">Пример</a></h1>
<p>01.03.22 - самая первая версия библиотеки (примеры использования возможно будут позже).</p> <p>В данном примере создаются 8 объектов (точек с координатами x, y), каждый из которых имеет тип 0 (синие) или 1 (зеленые). При нажатии кнопки <img src="but05.png"> происходит тренировка нейросети. В процессе тренировки нейросеть учится определять какой цвет должен соответствовать заданным координатам x, y. Тренировать сеть можно много раз, число циклов тренировки показано в заголовке окна. Кнопка <img src="but04.png"> переставляет точки случайным образом. Кнопка <img src="but01.png"> сбрасывает состояние нейросети.</p>
<p><img src="img01.png"></p>
<p>Рис. 1. Пример использования библиотеки</p>
<h1><a name="hist">История</a></h1>
<p>01.03.22 - самая первая версия библиотеки.</p>
<p>28.05.22 - пример использования библиотеки, новая функция NNP_Reset, обновление функции NNP_SetMemData.</p>
</body> </body>
</html> </html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

View File

@ -0,0 +1,6 @@
if not exist bin mkdir bin
@fasm.exe ..\nnp.asm bin\nnp.obj
@fasm.exe -m 16384 nnp_points.asm bin\nnp_points.kex
@kpack nnp_points.kex
pause

View File

@ -0,0 +1,747 @@
use32
org 0
db 'MENUET01' ;¨¤¥­â¨ä. ¨á¯®«­ï¥¬®£® ä ©«  ¢á¥£¤  8 ¡ ©â
dd 1, start, i_end, mem, stacktop, 0, sys_path
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../KOSfuncs.inc'
include '../../../../load_img.inc'
include '../../../../load_lib.mac'
include '../../../../develop/libraries/box_lib/trunk/box_lib.mac'
@use_library mem.Alloc,mem.Free,mem.ReAlloc,dll.Load
caption db 'NNP example 28.05.22',0 ;¯®¤¯¨áì ®ª­ 
run_file_70 FileInfoBlock
IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3
image_data_toolbar dd 0
memory_file_size dd 512*1024 ;à §¬¥à ¯ ¬ï⨠¤«ï ®âªàëâ¨ï ä ©«®¢ (¢ ­ ç «¥ 512 Kb, ­® ¬®¦¥â 㢥«¨ç¨¢ âáï ¯à¨ ­¥®¡å®¤¨¬®áâ¨)
NNP_FF_BIN equ 0x6e6962
NNP_FF_JSON equ 0x6e6f736a
struct NeuralNetwork
learningRate dq ? ;+ 0 ᪮à®áâì ®¡ã祭¨ï
layers dd ? ;+ 8 [] á«®¨
layers_length dd ? ;+12 ç¨á«® á«®¥¢
activation dd ? ;+16 㪠§ â¥«ì ­  äã­ªæ¨î  ªâ¨¢ æ¨¨
derivative dd ? ;+20 㪠§ â¥«ì ­  äã­ªæ¨î
errors dd ? ;+24 ¬ áᨢ ¤«ï ¢ëç¨á«¥­¨©
errorsNext dd ? ;+28
gradients dd ? ;+32
deltas dd ? ;+36
ends
struct Point
x dq ? ;double
y dq ?
t dd ? ;long
ends
align 4
NNLOPT_LEN equ 4
nnlopt dd 2,3,3,2
_nn NeuralNetwork
lea_rate dq 0.01
POINTS_COUNT equ 8 ;ç¨á«® â®ç¥ª
_p rb sizeof.Point*POINTS_COUNT
_cycles_st dd 0
_r_op rb 128
txt_error db '"Error open: ',39,'%s',39,'" -tE',0
txt_cycles db 'Cycles = %i000',0
;Œ ªà®á ¤«ï ¯ à ¬¥â஢ ⨯  double (8 ¡ ©â)
macro glpush double_v {
push dword[double_v+4]
push dword[double_v]
}
align 8
proc __ftol
sub esp,12
wait
fstcw word[esp+8]
wait
mov al,[esp+9]
or byte[esp+9],0x0c
fldcw word[esp+8]
fistp qword[esp]
mov [esp+9],al
fldcw word[esp+8]
mov eax,[esp]
mov edx,[esp+4]
add esp,12
ret
endp
align 16
Math_random:
imul eax,dword[_rand_x],22695477
inc eax
push ecx
mov dword[_rand_x],eax
and eax,65535
mov dword[esp],eax
fild dword[esp]
fmul dword[@f]
pop edx
ret
align 4
@@:
db 0,0,128,55 ;dd 1.0/65536.0
_rand_x dd 0
align 8
start:
load_libraries l_libs_start,l_libs_end
;¯à®¢¥àª  ­  ᪮«ìª® 㤠筮 § £ã§¨« áì ¡¨¡«¨®â¥ª 
mov ebp,lib_0
cmp dword [ebp+ll_struc_size-4],0
jz @f
mcall SF_TERMINATE_PROCESS
@@:
mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors
mcall SF_SET_EVENTS_MASK,0xC0000027
stdcall [OpenDialog_Init],OpenDialog_data ;¯®¤£®â®¢ª  ¤¨ «®£ 
stdcall [buf2d_create], buf_0 ;ᮧ¤ ­¨¥ ¡ãä¥à 
include_image_file 'toolbar.png', image_data_toolbar
stdcall mem.Alloc,[memory_file_size]
mov dword[open_file],eax
push NNLOPT_LEN
push nnlopt
push 0
push 0
glpush lea_rate
stdcall [NNP_Create], _nn
call but_update
align 8
red_win:
call draw_window
align 16
still:
mcall SF_WAIT_EVENT
cmp al,1
jz red_win
cmp al,2
jz key
cmp al,3
jz button
cmp al,6 ;¬ëèì
jne @f
jmp mouse
@@:
jmp still
align 8
draw_window:
pushad
mcall SF_REDRAW,SSF_BEGIN_DRAW
; *** à¨á®¢ ­¨¥ £« ¢­®£® ®ª­  (¢ë¯®«­ï¥âáï 1 à § ¯à¨ § ¯ã᪥) ***
mov edx,[sc.work]
or edx,(3 shl 24)+0x30000000
mov edi,caption
mcall SF_CREATE_WINDOW, (20 shl 16)+590, (20 shl 16)+540
; *** ᮧ¤ ­¨¥ ª­®¯®ª ­  ¯ ­¥«ì ***
mov esi,[sc.work_button]
mcall SF_DEFINE_BUTTON, (5 shl 16)+20, (5 shl 16)+20, 3
add ebx,(25 shl 16)
mov edx,4
int 0x40
add ebx,(25 shl 16)
mov edx,5
int 0x40
add ebx,(30 shl 16)
mov edx,6
int 0x40
add ebx,(25 shl 16)
mov edx,7
int 0x40
; *** à¨á®¢ ­¨¥ ¨ª®­®ª ­  ª­®¯ª å ***
mcall SF_PUT_IMAGE, [image_data_toolbar], (16 shl 16)+16, (7 shl 16)+7 ;icon new
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(25 shl 16) ;icon open
int 0x40
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(25 shl 16) ;icon save
int 0x40
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(30 shl 16) ;icon update points
int 0x40
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(25 shl 16) ;icon calculate
int 0x40
call PointsDraw
; *** à¨á®¢ ­¨¥ ¡ãä¥à  ***
stdcall [buf2d_draw], buf_0
mcall SF_REDRAW,SSF_END_DRAW
popad
ret
align 8
key:
mcall SF_GET_KEY
jmp still
align 8
mouse:
jmp still
align 8
button:
mcall SF_GET_BUTTON
cmp ah,3
jne @f
call but_new_file
jmp red_win
@@:
cmp ah,4
jne @f
call but_open_file
jmp red_win
@@:
cmp ah,5
jne @f
call but_save_file
jmp red_win
@@:
cmp ah,6
jne @f
call but_update
jmp red_win
@@:
cmp ah,7
jne @f
call but_calc
jmp red_win
@@:
cmp ah,1
jne still
.exit:
stdcall [buf2d_delete],buf_0
stdcall mem.Free,[image_data_toolbar]
stdcall mem.Free,[open_file]
stdcall [NNP_Destroy], _nn
mcall SF_TERMINATE_PROCESS
align 8
but_calc:
push esi edi ebp
add esp,-32
mov ebp,_p
xor edi,edi ;i=0
.cycle_0: ;for(i=0;i<50000;i++)
call Math_random
fimul dword[.172]
call __ftol
mov esi,eax ;k=(long)(Math_random()*POINTS_COUNT)
imul esi,sizeof.Point
fld qword[ebp+esi+Point.x]
fsub dword[f_0_5]
fstp qword[esp] ;v[0]=p[k].x-.5
fld qword[ebp+esi+Point.y]
fsub dword[f_0_5]
fstp qword[esp+8] ;v[1]=p[k].y-.5
stdcall [NNP_FeedForward], _nn,esp ;r=NNP_FeedForward(&nn,v)
xor eax,eax
mov dword[esp+16],eax
mov dword[esp+20],eax ;t[0]=0.0
mov dword[esp+24],eax
mov dword[esp+28],eax ;t[1]=0.0
cmp dword[ebp+esi+Point.t],eax
je .173
mov dword[esp+16],eax
mov dword[esp+20],1072693248 ;if(p[k].t) t[0]=1.0
jmp .174
.173:
mov dword[esp+24],eax
mov dword[esp+28],1072693248 ;else t[1]=1.0
.174:
lea edx,dword[esp+16]
stdcall [NNP_BackPropagation], _nn,edx ;NNP_BackPropagation(&nn,t)
inc edi ;i++
cmp edi,50000
jl .cycle_0
add dword[_cycles_st],50
stdcall [sprintf], _r_op,txt_cycles,[_cycles_st]
add esp,12
call NNP_DrawInBuf
call PointsDraw
; SaveNN("/tmp0/1/nnp_end.txt")
;push s@+835
;call @@SaveNN$qpxc
;pop ecx
mcall SF_SET_CAPTION,1,_r_op
add esp,32
pop ebp edi esi
ret
align 4
.172:
dd POINTS_COUNT
align 8
but_new_file:
mov dword[_cycles_st],0
stdcall [NNP_Reset], _nn
call NNP_DrawInBuf
call PointsDraw
ret
align 8
but_update:
mov dword[_cycles_st],0
call PointsInit
call NNP_DrawInBuf
call PointsDraw
ret
align 8
PointsInit:
push ebx esi
xor esi,esi ;i=0
mov ebx,_p
.cycle_0: ;for(i=0;i<POINTS_COUNT;i++)
call Math_random
fstp qword[ebx+Point.x] ;p[i].x=Math_random()
call Math_random
fstp qword[ebx+Point.y] ;p[i].y=Math_random()
mov eax,esi
and eax,1
mov dword[ebx+Point.t],eax ;p[i].t=i&1
add ebx,sizeof.Point
inc esi ;i++
cmp esi,POINTS_COUNT
jl .cycle_0
pop esi ebx
ret
align 8
PointsDraw:
push ebx ecx esi edi ebp
xor ecx,ecx
mov ebx,_p
align 4
.cycle_0: ;for(i=0;i<POINTS_COUNT;i++)
fild dword[buf_0.w]
fmul qword[ebx+Point.x]
call __ftol
fild dword[buf_0.h]
mov esi,eax ;x=p[i].x*buf0.w
fmul qword[ebx+Point.y]
call __ftol
mov edi,eax ;y=p[i].y*buf0.h
mov ebp,255 ;c=0xff
cmp dword[ebx+Point.t],0
je @f
shl ebp,8 ;if(p[i].t) c<<=8
@@:
sub esi,4
sub edi,4
stdcall [buf2d_rect_by_size], buf_0,esi,edi,7,7,0xffffff
inc esi
inc edi
stdcall [buf2d_filled_rect_by_size], buf_0,esi,edi,5,5,ebp
inc ecx
add ebx,sizeof.Point
cmp ecx,POINTS_COUNT
jl .cycle_0
pop ebp edi esi ecx ebx
ret
align 8
NNP_DrawInBuf:
push ebx esi ebp
add esp,-32
lea ebp,dword [esp+16]
; ebp = &v
xor eax,eax
mov dword [esp+8],eax
mov dword [esp+12],eax
jmp .cycle_0_end
.cycle_0: ;for(y=0;y<buf0.h;y++)
fild dword [buf_0.h]
fdivr qword [esp+8]
fsub dword [f_0_5]
fstp qword [ebp+8] ;v[1]=(double)y/buf0.h-.5
xor eax,eax
mov dword [esp],eax
mov dword [esp+4],eax
jmp .cycle_1_end
.cycle_1: ;for(x=0;x<buf0.w;x++)
fild dword [buf_0.w]
fdivr qword [esp]
fsub dword [f_0_5]
fstp qword [ebp] ;v[0]=(double)x/buf0.w-.5
stdcall [NNP_FeedForward], _nn,ebp
mov esi,eax ;r=NNP_FeedForward(&nn,v)
fld qword [esi]
fmul dword [f_255_0]
call __ftol
movzx ebx,al ;k=(unsigned char)(r[0]*255.0)
shl ebx,8 ;k<<=8
fld qword [esi+8]
fmul dword [f_255_0]
call __ftol
and eax,0xff
add ebx,eax ;k+=(unsigned char)(r[1]*255.0)
push ebx
fld qword [esp+12]
call __ftol
push eax
fld qword [esp+8]
call __ftol
stdcall [buf2d_set_pixel], buf_0,eax ;buf2d_set_pixel(&buf0,x,y,k)
fld1
fadd qword [esp]
fstp qword [esp]
.cycle_1_end:
fild dword [buf_0.w]
fcomp qword [esp]
fnstsw ax
sahf
ja .cycle_1
fld1
fadd qword [esp+8]
fstp qword [esp+8]
.cycle_0_end:
fild dword [buf_0.h]
fcomp qword [esp+8]
fnstsw ax
sahf
ja .cycle_0
add esp,32
pop ebp esi ebx
ret
align 4
f_0_5 dd 0.5
f_255_0 dd 255.0
open_file dd 0 ;㪠§ â¥«ì ­  ¯ ¬ïâì ¤«ï ®âªàëâ¨ï ä ©«®¢
open_file_size dd 0 ;à §¬¥à ®âªàë⮣® ä ©«  (¤®«¦¥­ ¡ëâì ­¥ ¡®«ìè¥ memory_file_size)
align 8
but_open_file:
pushad
copy_path open_dialog_name,communication_area_default_path,file_name,0
mov [OpenDialog_data.type],0
stdcall [OpenDialog_Start],OpenDialog_data
cmp [OpenDialog_data.status],2
je .end_open_file
;ª®¤ ¯à¨ 㤠筮¬ ®âªàë⨨ ¤¨ «®£ 
mov [run_file_70.Function], SSF_GET_INFO
mov [run_file_70.Position], 0
mov [run_file_70.Flags], 0
mov dword[run_file_70.Count], 0
m2m [run_file_70.Buffer], [open_file]
mov byte[run_file_70+20], 0
mov dword[run_file_70.FileName], openfile_path
mcall SF_FILE,run_file_70
cmp eax,0
jne .end_open_file
mov eax,[open_file]
mov ebx,[eax+32] ;dword[eax+32] - à §¬¥à ®âªà뢠¥¬®£® ä ©« 
mov [open_file_size],ebx ;ebx - à §¬¥à ®âªà뢠¥¬®£® ä ©« 
;memory_file_size - à §¬¥à ¢ë¤¥«¥­­®© ¯ ¬ï⨠¤«ï ä ©« 
cmp [memory_file_size],ebx
jge @f
;㢥«¨ç¨¢ ¥¬ ¯ ¬ïâì ¥á«¨ ­¥ 墠⨫®
mov [memory_file_size],ebx
stdcall mem.ReAlloc, [open_file],ebx
mov [open_file],eax
@@:
mov [run_file_70.Function], SSF_READ_FILE
mov [run_file_70.Position], 0
mov [run_file_70.Flags], 0
m2m dword[run_file_70.Count], dword[open_file_size]
m2m dword[run_file_70.Buffer],dword[open_file]
mov byte[run_file_70+20], 0
mov dword[run_file_70.FileName], openfile_path
mcall SF_FILE,run_file_70 ;§ £à㦠¥¬ ä ©«
cmp ebx,0xffffffff
je .end_open_file
mov [open_file_size],ebx
mcall SF_SET_CAPTION,1,openfile_path
stdcall [NNP_SetMemData], _nn,NNP_FF_JSON,[open_file]
or eax,eax
jnz @f
mov dword[_cycles_st],0
call NNP_DrawInBuf
call PointsDraw
jmp .end_open_file
@@:
stdcall [sprintf], _r_op,txt_error,eax
add esp,12
notify_window_run _r_op
.end_open_file:
popad
ret
align 8
but_save_file:
pushad
copy_path open_dialog_name,communication_area_default_path,file_name,0
mov [OpenDialog_data.type],1
stdcall [OpenDialog_Set_file_ext],OpenDialog_data,Filter.1
stdcall [OpenDialog_Start],OpenDialog_data
cmp [OpenDialog_data.status],2
je .end_save_file
;ª®¤ ¯à¨ 㤠筮¬ ®âªàë⨨ ¤¨ «®£ 
mov [run_file_70.Function], SSF_CREATE_FILE
mov [run_file_70.Position], 0
mov [run_file_70.Flags], 0
stdcall [NNP_GetMemData], _nn,NNP_FF_JSON,[open_file]
stdcall [strlen], [open_file]
pop ebx ;add esp,4
mov ebx, [open_file]
mov [run_file_70.Buffer], ebx
mov [open_file_size],eax
mov dword[run_file_70.Count], eax ;à §¬¥à ä ©« 
mov byte[run_file_70+20], 0
mov dword[run_file_70.FileName], openfile_path
mcall SF_FILE,run_file_70 ;á®å࠭塞 ä ©«
;cmp ebx,0xffffffff
;je .end_save_file
; ... á®®¡é¥­¨¥ ® ­¥ã¤ ç­®¬ á®åà ­¥­¨¨ ...
.end_save_file:
popad
ret
;¤ ­­ë¥ ¤«ï ¤¨ «®£  ®âªàëâ¨ï ä ©«®¢
align 4
OpenDialog_data:
.type dd 0 ;0 - ®âªàëâì, 1 - á®åà ­¨âì, 2 - ¢ë¡à âì ¤â४â®à¨î
.procinfo dd procinfo ;+4
.com_area_name dd communication_area_name ;+8
.com_area dd 0 ;+12
.opendir_path dd plugin_path ;+16
.dir_default_path dd default_dir ;+20
.start_path dd file_name ;+24 ¯ãâì ª ¤¨ «®£ã ®âªàëâ¨ï ä ©«®¢
.draw_window dd draw_window ;+28
.status dd 0 ;+32
.openfile_path dd openfile_path ;+36 ¯ãâì ª ®âªà뢠¥¬®¬ã ä ©«ã
.filename_area dd filename_area ;+40
.filter_area dd Filter
.x:
.x_size dw 420 ;+48 ; Window X size
.x_start dw 10 ;+50 ; Window X position
.y:
.y_size dw 320 ;+52 ; Window y size
.y_start dw 10 ;+54 ; Window Y position
default_dir db '/sys',0
communication_area_name:
db 'FFFFFFFF_open_dialog',0
open_dialog_name:
db 'opendial',0
communication_area_default_path:
db '/sys/File managers/',0
Filter:
dd Filter.end - Filter ;.1
.1:
db 'TXT',0
db 'JSON',0
db 'BIN',0
.end:
db 0
system_dir_0 db '/sys/lib/'
lib_name_0 db 'proc_lib.obj',0
system_dir_1 db '/sys/lib/'
lib_name_1 db 'libimg.obj',0
system_dir_2 db '/sys/lib/'
lib_name_2 db 'buf2d.obj',0
system_dir_3 db '/sys/lib/'
lib_name_3 db 'nnp.obj',0
system_dir_4 db '/sys/lib/'
lib_name_4 db 'libc.obj',0
l_libs_start:
lib_0 l_libs lib_name_0, file_name, system_dir_0, import_proclib
lib_1 l_libs lib_name_1, file_name, system_dir_1, import_libimg
lib_2 l_libs lib_name_2, file_name, system_dir_2, import_buf2d
lib_3 l_libs lib_name_3, file_name, system_dir_3, import_nnp
lib_4 l_libs lib_name_4, file_name, system_dir_4, import_libc
l_libs_end:
sz_lib_init db 'lib_init',0
align 4
import_libimg:
dd sz_lib_init
img_is_img dd aimg_is_img
img_info dd aimg_info
img_from_file dd aimg_from_file
img_to_file dd aimg_to_file
img_from_rgb dd aimg_from_rgb
img_to_rgb dd aimg_to_rgb
img_to_rgb2 dd aimg_to_rgb2
img_decode dd aimg_decode
img_encode dd aimg_encode
img_create dd aimg_create
img_destroy dd aimg_destroy
img_destroy_layer dd aimg_destroy_layer
img_count dd aimg_count
img_lock_bits dd aimg_lock_bits
img_unlock_bits dd aimg_unlock_bits
img_flip dd aimg_flip
img_flip_layer dd aimg_flip_layer
img_rotate dd aimg_rotate
img_rotate_layer dd aimg_rotate_layer
img_draw dd aimg_draw
dd 0,0
aimg_is_img db 'img_is_img',0 ;®¯à¥¤¥«ï¥â ¯® ¤ ­­ë¬, ¬®¦¥â «¨ ¡¨¡«¨®â¥ª  ᤥ« âì ¨§ ­¨å ¨§®¡à ¦¥­¨¥
aimg_info db 'img_info',0
aimg_from_file db 'img_from_file',0
aimg_to_file db 'img_to_file',0
aimg_from_rgb db 'img_from_rgb',0
aimg_to_rgb db 'img_to_rgb',0 ;¯à¥®¡à §®¢ ­¨¥ ¨§®¡à ¦¥­¨ï ¢ ¤ ­­ë¥ RGB
aimg_to_rgb2 db 'img_to_rgb2',0
aimg_decode db 'img_decode',0 ; ¢â®¬ â¨ç¥áª¨ ®¯à¥¤¥«ï¥â ä®à¬ â £à ä¨ç¥áª¨å ¤ ­­ëå
aimg_encode db 'img_encode',0
aimg_create db 'img_create',0
aimg_destroy db 'img_destroy',0
aimg_destroy_layer db 'img_destroy_layer',0
aimg_count db 'img_count',0
aimg_lock_bits db 'img_lock_bits',0
aimg_unlock_bits db 'img_unlock_bits',0
aimg_flip db 'img_flip',0
aimg_flip_layer db 'img_flip_layer',0
aimg_rotate db 'img_rotate',0
aimg_rotate_layer db 'img_rotate_layer',0
aimg_draw db 'img_draw',0
align 4
import_proclib: ;®¯¨á ­¨¥ íªá¯®àâ¨à㥬ëå ä㭪権
OpenDialog_Init dd aOpenDialog_Init
OpenDialog_Start dd aOpenDialog_Start
;OpenDialog_Set_file_name dd aOpenDialog_Set_file_name
OpenDialog_Set_file_ext dd aOpenDialog_Set_file_ext
dd 0,0
aOpenDialog_Init db 'OpenDialog_init',0
aOpenDialog_Start db 'OpenDialog_start',0
;aOpenDialog_Set_file_name db 'OpenDialog_set_file_name',0
aOpenDialog_Set_file_ext db 'OpenDialog_set_file_ext',0
align 4
import_buf2d:
dd sz_lib_init
buf2d_create dd sz_buf2d_create
buf2d_create_f_img dd sz_buf2d_create_f_img
buf2d_clear dd sz_buf2d_clear
buf2d_draw dd sz_buf2d_draw
buf2d_delete dd sz_buf2d_delete
buf2d_resize dd sz_buf2d_resize
buf2d_rect_by_size dd sz_buf2d_rect_by_size
buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size
buf2d_circle dd sz_buf2d_circle
buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8
buf2d_bit_blt dd sz_buf2d_bit_blt
;buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix
;buf2d_draw_text dd sz_buf2d_draw_text
buf2d_set_pixel dd sz_buf2d_set_pixel
dd 0,0
sz_buf2d_create db 'buf2d_create',0
sz_buf2d_create_f_img db 'buf2d_create_f_img',0
sz_buf2d_clear db 'buf2d_clear',0
sz_buf2d_draw db 'buf2d_draw',0
sz_buf2d_delete db 'buf2d_delete',0
sz_buf2d_resize db 'buf2d_resize',0
sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0
sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0
sz_buf2d_circle db 'buf2d_circle',0
sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0
sz_buf2d_bit_blt db 'buf2d_bit_blt',0
;sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0
;sz_buf2d_draw_text db 'buf2d_draw_text',0
sz_buf2d_set_pixel db 'buf2d_set_pixel',0
align 4
import_nnp:
dd sz_lib_init
NNP_Create dd sz_create
NNP_Reset dd sz_reset
NNP_FeedForward dd sz_feedforward
NNP_BackPropagation dd sz_backpropagation
NNP_GetMemData dd sz_getmemdata
NNP_SetMemData dd sz_setmemdata
NNP_Destroy dd sz_destroy
dd 0,0
sz_create db 'NNP_Create',0
sz_reset db 'NNP_Reset',0
sz_feedforward db 'NNP_FeedForward',0
sz_backpropagation db 'NNP_BackPropagation',0
sz_getmemdata db 'NNP_GetMemData',0
sz_setmemdata db 'NNP_SetMemData',0
sz_destroy db 'NNP_Destroy',0
align 4
import_libc:
strlen dd sz_strlen
sprintf dd sz_sprintf
dd 0,0
sz_strlen db 'strlen',0
sz_sprintf db 'sprintf',0
sc system_colors
align 16
procinfo process_information
align 4
buf_0: dd 0 ;㪠§ â¥«ì ­  ¡ãä¥à ¨§®¡à ¦¥­¨ï
dw 5 ;+4 left
dw 31 ;+6 top
.w: dd 570 ;+8 w
.h: dd 480 ;+12 h
.color: dd 0xffffd0 ;+16 color
db 24 ;+20 bit in pixel
align 16
i_end:
rb 2048
stacktop:
sys_path rb 1024
file_name rb 4096
plugin_path rb 4096
openfile_path rb 4096
filename_area rb 256
mem:

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -100,6 +100,13 @@ txt_n_size db '"n_size"',0
txt_biases db '"biases"',0 txt_biases db '"biases"',0
txt_weights db '"weights"',0 txt_weights db '"weights"',0
txt_err_layers_neq db 'number of layers does not match',0
txt_err_c_size db "not found value 'c_size'",0
txt_err_sqbrl_b1 db "not found opening '[' for biases",0
txt_err_sqbrl_w1 db "not found opening '[' for weights",0
txt_err_sqbrl_w2 db "not found opening '[[' for weights",0
txt_err_sqbrr_w2 db "not found closing ']]' for weights",0
align 16 align 16
proc lib_init proc lib_init
mov [mem.alloc], eax mov [mem.alloc], eax
@ -232,29 +239,28 @@ NNP_Create:
mov dword[edx+NeuralNetwork.derivative],eax mov dword[edx+NeuralNetwork.derivative],eax
mov eax,[ebp+32] ;sizes_length mov eax,[ebp+32] ;sizes_length
imul eax,sizeof.Layer imul eax,sizeof.Layer
push eax stdcall @$bnwa$qui,eax
call @$bnwa$qui
pop ecx pop ecx
mov edx,[ebp+8] ;o mov edx,[ebp+8] ;o
mov dword[edx+NeuralNetwork.layers],eax mov dword[edx+NeuralNetwork.layers],eax
mov ecx,[ebp+8] ;o mov ecx,[ebp+8] ;o
mov eax,[ebp+32] ;sizes_length mov eax,[ebp+32] ;sizes_length
mov dword[ecx+NeuralNetwork.layers_length],eax mov dword[ecx+NeuralNetwork.layers_length],eax
xor edi,edi xor edi,edi ;i=0
mov eax,[ebp+28] ;sizes mov eax,[ebp+28] ;sizes
lea edx,[eax+4] lea edx,[eax+4]
mov dword[ebp-8],edx mov dword[ebp-8],edx ;save &sizes[i+1]
jmp .150 jmp .150
.149: .cycle_0: ;for (i=0; i < sizes_length; i++)
xor ecx,ecx xor ecx,ecx
mov dword[ebp-4],ecx mov dword[ebp-4],ecx ;nextSize = 0
mov eax,[ebp+32] ;sizes_length mov eax,[ebp+32] ;sizes_length
dec eax dec eax
cmp edi,eax cmp edi,eax
jae .152 jae .152
mov edx,[ebp-8] mov edx,[ebp-8]
mov ecx,[edx] mov ecx,[edx]
mov dword[ebp-4],ecx mov dword[ebp-4],ecx ;nextSize = sizes[i+1]
.152: .152:
mov eax,[ebp-4] mov eax,[ebp-4]
push eax push eax
@ -262,38 +268,38 @@ NNP_Create:
mov ecx,[edx-4] mov ecx,[edx-4]
push ecx push ecx
mov ecx,edi mov ecx,edi
shl ecx,2 imul ecx,sizeof.Layer
mov eax,[ebp+8] ;o mov eax,[ebp+8] ;o
mov edx,[eax+NeuralNetwork.layers] mov edx,[eax+NeuralNetwork.layers]
lea ecx,[ecx+4*ecx]
add edx,ecx add edx,ecx
push edx stdcall Layer_Create,edx
call Layer_Create xor esi,esi ;j=0
xor esi,esi
mov eax,[ebp-8] mov eax,[ebp-8]
lea edx,[eax-4] lea edx,[eax-4]
mov dword[ebp-12],edx mov dword[ebp-12],edx ;save &sizes[i]
jmp .154 jmp .154
.153: .cycle_1: ;for (j=0; j < sizes[i]; j++)
call Math_random call Math_random
fmul dword[f_2_0] fmul dword[f_2_0]
fsub dword[f_1_0] fsub dword[f_1_0]
mov eax,[ebp+8] ;o mov eax,[ebp+8] ;o
lea ecx,[edi+4*edi] mov ecx,edi
xor ebx,ebx imul ecx,sizeof.Layer
mov edx,[eax+NeuralNetwork.layers] add ecx,[eax+NeuralNetwork.layers]
mov ecx,[edx+4*ecx+12] mov ecx,[ecx+Layer.biases]
fstp qword[ecx+8*esi] fstp qword[ecx+8*esi]
xor ebx,ebx ;k=0
cmp ebx,[ebp-4] cmp ebx,[ebp-4]
jae .157 jae .157
@@: @@: ;for (k=0; k < nextSize; k++)
call Math_random call Math_random
fmul dword[f_2_0] fmul dword[f_2_0]
fsub dword[f_1_0] fsub dword[f_1_0]
lea eax,[edi+4*edi] mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8] ;o mov edx,[ebp+8] ;o
mov ecx,[edx+NeuralNetwork.layers] mov ecx,[edx+NeuralNetwork.layers]
mov eax,[ecx+4*eax+16] mov eax,[ecx+eax+Layer.weights]
mov edx,[eax+4*esi] mov edx,[eax+4*esi]
fstp qword[edx+8*ebx] fstp qword[edx+8*ebx]
inc ebx inc ebx
@ -304,19 +310,18 @@ NNP_Create:
.154: .154:
mov ecx,[ebp-12] mov ecx,[ebp-12]
cmp esi,[ecx] cmp esi,[ecx]
jb .153 jb .cycle_1
inc edi inc edi
add dword[ebp-8],4 add dword[ebp-8],4
.150: .150:
cmp edi,[ebp+32] ;sizes_length cmp edi,[ebp+32] ;sizes_length
jb .149 jb .cycle_0
;create errors array ;create errors array
push dword[ebp+8] push dword[ebp+8]
call NNP_GetMaxLLen call NNP_GetMaxLLen
mov esi,eax mov esi,eax
shl esi,4 shl esi,4
push esi stdcall @$bnwa$qui,esi
call @$bnwa$qui
pop ecx pop ecx
mov edx,[ebp+8] mov edx,[ebp+8]
mov dword[edx+NeuralNetwork.errors],eax mov dword[edx+NeuralNetwork.errors],eax
@ -324,15 +329,13 @@ NNP_Create:
add eax,esi add eax,esi
mov dword[edx+NeuralNetwork.errorsNext],eax mov dword[edx+NeuralNetwork.errorsNext],eax
;create gradients array ;create gradients array
push esi stdcall @$bnwa$qui,esi
call @$bnwa$qui
pop ecx pop ecx
mov edx,[ebp+8] mov edx,[ebp+8]
mov dword[edx+NeuralNetwork.gradients],eax mov dword[edx+NeuralNetwork.gradients],eax
;create deltas array ;create deltas array
shr esi,1 shr esi,1
push esi stdcall @$bnwa$qui,esi
call @$bnwa$qui
pop ecx pop ecx
mov edx,[ebp+8] mov edx,[ebp+8]
mov dword[edx+NeuralNetwork.deltas],eax mov dword[edx+NeuralNetwork.deltas],eax
@ -346,6 +349,71 @@ f_2_0:
f_1_0: f_1_0:
dd 1.0 dd 1.0
;заполнение случайными числами
;+ 8 NeuralNetwork* o
align 16
NNP_Reset:
push ebp
mov ebp,esp
add esp,-8
push ebx esi edi
xor edi,edi ;i=0
jmp .3
.cycle_0: ;for (i=0; i < o->layers_length; i++)
xor esi,esi ;j=0
mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8]
add eax,[edx+NeuralNetwork.layers]
mov edx,[eax+Layer.n_size]
mov [ebp-4],edx
mov edx,[eax+Layer.c_size]
mov [ebp-8],edx
jmp .2
.cycle_1: ;for (j=0; j < o->layers[i].c_size; j++)
call Math_random
fmul dword[f_2_0]
fsub dword[f_1_0]
mov eax,[ebp+8] ;o
mov ecx,edi
imul ecx,sizeof.Layer
add ecx,[eax+NeuralNetwork.layers]
mov ecx,[ecx+Layer.biases]
fstp qword[ecx+8*esi]
xor ebx,ebx ;k=0
cmp ebx,[ebp-4]
jae .1
@@: ;for (k=0; k < o->layers[i].n_size; k++)
call Math_random
fmul dword[f_2_0]
fsub dword[f_1_0]
mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8] ;o
add eax,[edx+NeuralNetwork.layers]
mov eax,[eax+Layer.weights]
mov edx,[eax+4*esi] ;edx = &o->layers[i].weights[j]
fstp qword[edx+8*ebx] ;o->layers[i].weights[j][k] = Math_random()*2.0-1.0;
inc ebx ;k++
cmp ebx,[ebp-4]
jb @b
.1:
inc esi ;j++
.2:
cmp esi,[ebp-8]
jb .cycle_1
inc edi ;i++
.3:
mov ecx,[ebp+8] ;o
cmp edi,[ecx+NeuralNetwork.layers_length]
jb .cycle_0
pop edi esi ebx
mov esp,ebp
pop ebp
ret 4
;расчет входных и выходных нейронов
;+ 8 NeuralNetwork* o ;+ 8 NeuralNetwork* o
;+12 double* inputs ;+12 double* inputs
align 16 align 16
@ -621,7 +689,7 @@ NNP_GetMemData:
mov ebp,esp mov ebp,esp
add esp,-12 add esp,-12
push ebx esi edi push ebx esi edi
cmp dword[ebp+12],1852797802 cmp dword[ebp+12],NNP_FF_JSON
jne .end_f jne .end_f
mov esi,[ebp+16] mov esi,[ebp+16]
mov byte[esi],0 mov byte[esi],0
@ -665,14 +733,15 @@ align 4
add esi,eax add esi,eax
stdcall [_strcat], esi,txt_nl_t_Qc_sizeQ stdcall [_strcat], esi,txt_nl_t_Qc_sizeQ
add esp,8 add esp,8
lea ebx,[edi+4*edi] mov ebx,edi
imul ebx,sizeof.Layer
push 1 push 1
push 0 push 0
mov eax,[ebp+8] mov edx,[ebp+8]
mov edx,[eax+8] mov edx,[edx+NeuralNetwork.layers]
xor eax,eax xor eax,eax
add esp,-8 add esp,-8
mov ecx,[edx+4*ebx] mov ecx,[edx+ebx+Layer.c_size]
mov dword[ebp-12],ecx mov dword[ebp-12],ecx
mov dword[ebp-8],eax mov dword[ebp-8],eax
fild qword[ebp-12] fild qword[ebp-12]
@ -685,11 +754,11 @@ align 4
add esp,8 add esp,8
push 1 push 1
push 0 push 0
mov edx,[ebp+8] mov ecx,[ebp+8]
mov ecx,[edx+8] mov ecx,[ecx+NeuralNetwork.layers]
xor edx,edx xor edx,edx
add esp,-8 add esp,-8
mov eax,[ecx+4*ebx+4] mov eax,[ecx+ebx+Layer.n_size]
mov dword[ebp-12],eax mov dword[ebp-12],eax
mov dword[ebp-8],edx mov dword[ebp-8],edx
fild qword[ebp-12] fild qword[ebp-12]
@ -713,10 +782,11 @@ align 4
.235: .235:
push 1 push 1
push PRECISION push PRECISION
lea eax,[edi+4*edi] mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8] mov edx,[ebp+8]
mov ecx,[edx+8] mov ecx,[edx+NeuralNetwork.layers]
mov eax,[ecx+4*eax+8] mov eax,[ecx+eax+Layer.neurons]
push dword[eax+8*ebx+4] push dword[eax+8*ebx+4]
push dword[eax+8*ebx] push dword[eax+8*ebx]
call @@DoubleToStr$qduso call @@DoubleToStr$qduso
@ -746,10 +816,11 @@ align 4
.239: .239:
push 1 push 1
push PRECISION push PRECISION
lea eax,[edi+4*edi] mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8] mov edx,[ebp+8]
mov ecx,[edx+8] add eax,[edx+NeuralNetwork.layers]
mov eax,[ecx+4*eax+12] mov eax,[eax+Layer.biases]
push dword[eax+8*ebx+4] push dword[eax+8*ebx+4]
push dword[eax+8*ebx] push dword[eax+8*ebx]
call @@DoubleToStr$qduso call @@DoubleToStr$qduso
@ -758,17 +829,19 @@ align 4
add esp,8 add esp,8
inc ebx inc ebx
.238: .238:
lea ecx,[edi+4*edi] mov ecx,edi
imul ecx,sizeof.Layer
mov eax,[ebp+8] mov eax,[ebp+8]
mov edx,[eax+8] add ecx,[eax+NeuralNetwork.layers]
cmp ebx,[edx+4*ecx] cmp ebx,[ecx+Layer.c_size]
jb .cycle_2 jb .cycle_2
stdcall [_strcat], esi,txt_sqbr_zap_t_QweightsQ stdcall [_strcat], esi,txt_sqbr_zap_t_QweightsQ
add esp,8 add esp,8
mov eax,[ebp+8] mov eax,[ebp+8]
lea ecx,[edi+4*edi] mov ecx,edi
mov edx,[eax+8] imul ecx,sizeof.Layer
cmp dword[edx+4*ecx+4],0 add ecx,[eax+NeuralNetwork.layers]
cmp dword[ecx+Layer.n_size],0
je .241 je .241
xor ebx,ebx xor ebx,ebx
jmp .243 jmp .243
@ -791,10 +864,11 @@ align 4
.247: .247:
push 1 push 1
push PRECISION push PRECISION
lea edx,[edi+4*edi] mov edx,edi
mov ecx,[ebp+8] imul edx,sizeof.Layer
mov eax,[ecx+8] mov eax,[ebp+8]
mov edx,[eax+4*edx+16] add edx,[eax+NeuralNetwork.layers]
mov edx,[edx+Layer.weights]
mov ecx,[edx+4*ebx] mov ecx,[edx+4*ebx]
mov eax,[ebp-4] mov eax,[ebp-4]
push dword[ecx+8*eax+4] push dword[ecx+8*eax+4]
@ -811,20 +885,22 @@ align 4
add esp,8 add esp,8
inc dword[ebp-4] inc dword[ebp-4]
.246: .246:
lea ecx,[edi+4*edi] mov ecx,edi
imul ecx,sizeof.Layer
mov eax,[ebp+8] mov eax,[ebp+8]
mov edx,[eax+8] add ecx,[eax+NeuralNetwork.layers]
mov ecx,[edx+4*ecx+4] mov ecx,[ecx+Layer.n_size]
cmp ecx,[ebp-4] cmp ecx,[ebp-4]
ja .245 ja .245
stdcall [_strcat], esi,txt_sqbr stdcall [_strcat], esi,txt_sqbr
add esp,8 add esp,8
inc ebx inc ebx
.243: .243:
lea eax,[edi+4*edi] mov eax,edi
mov edx,[ebp+8] imul eax,sizeof.Layer
mov ecx,[edx+8] mov ecx,[ebp+8]
cmp ebx,[ecx+4*eax] add eax,[ecx+NeuralNetwork.layers]
cmp ebx,[eax+Layer.c_size]
jb .242 jb .242
.241: .241:
stdcall [_strcat], esi,txt_sqbr_fbr_zap stdcall [_strcat], esi,txt_sqbr_fbr_zap
@ -852,27 +928,26 @@ NNP_GetMaxLLen:
cmp dword[ebx+NeuralNetwork.layers_length],1 cmp dword[ebx+NeuralNetwork.layers_length],1
jge .1 jge .1
xor eax,eax xor eax,eax
jmp .5 jmp .end_f
.1: .1:
mov edx,[ebx+NeuralNetwork.layers] mov edx,[ebx+NeuralNetwork.layers]
mov eax,[ebx+NeuralNetwork.layers] lea eax,[edx+sizeof.Layer]
add eax,sizeof.Layer
mov ecx,[edx] mov ecx,[edx]
mov edx,1 mov edx,1 ;i=1
jmp .4 jmp .3
.2: .cycle_0: ;for (i=1; i < o->layers_length; i++)
mov esi,[eax] mov esi,[eax]
cmp esi,ecx cmp esi,ecx
jbe .3 jbe .2
mov ecx,esi mov ecx,esi
.3: .2:
inc edx inc edx
add eax,sizeof.Layer add eax,sizeof.Layer
.4: .3:
cmp edx,[ebx+NeuralNetwork.layers_length] cmp edx,[ebx+NeuralNetwork.layers_length]
jl .2 jl .cycle_0
mov eax,ecx mov eax,ecx
.5: .end_f:
pop esi ebx ebp pop esi ebx ebp
ret 4 ret 4
@ -934,18 +1009,18 @@ NNP_SetMemData:
mov edx,[eax+12] mov edx,[eax+12]
cmp edx,[ebp-4] cmp edx,[ebp-4]
je .203 je .203
mov eax,4 mov eax,txt_err_layers_neq
jmp .193 jmp .193
.203: .203:
xor edi,edi xor edi,edi ;i=0
jmp .205 jmp .205
.204: .204: ;for(i=0;i<o->layers_length;i++)
stdcall @@strstr$qpxct1, esi,txt_c_size stdcall @@strstr$qpxct1, esi,txt_c_size
add esp,8 add esp,8
mov esi,eax mov esi,eax
test esi,esi test esi,esi
jne .206 jne .206
mov eax,5 mov eax,txt_err_c_size
jmp .193 jmp .193
.206: .206:
stdcall @@strchr$qpxci, esi,':' stdcall @@strchr$qpxci, esi,':'
@ -997,46 +1072,39 @@ NNP_SetMemData:
.211: .211:
mov byte[esi],0 mov byte[esi],0
inc esi inc esi
push ebx stdcall @@StrToInt$qpc,ebx
call @@StrToInt$qpc
pop ecx pop ecx
mov dword[ebp-8],eax mov dword[ebp-8],eax
lea eax,[edi+4*edi] mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8] mov edx,[ebp+8]
mov ecx,[edx+8] add eax,[edx+NeuralNetwork.layers]
mov edx,[ecx+4*eax] mov edx,[eax+Layer.c_size]
cmp edx,[ebp-4] cmp edx,[ebp-4]
jne .213 jne .213
mov ecx,[ebp+8] mov edx,[eax+Layer.n_size]
mov edx,[ecx+8] cmp edx,[ebp-8]
mov eax,[edx+4*eax+4]
cmp eax,[ebp-8]
je .214 je .214
.213: .213:
mov ecx,[ebp+8] mov ecx,[ebp+8]
push ecx stdcall NNP_GetMaxLLen,ecx
call NNP_GetMaxLLen
mov ecx,edi mov ecx,edi
imul ecx,sizeof.Layer
mov ebx,eax mov ebx,eax
shl ecx,2
mov eax,[ebp+8] mov eax,[ebp+8]
mov edx,[eax+8] mov edx,[eax+NeuralNetwork.layers]
lea ecx,[ecx+4*ecx]
add edx,ecx add edx,ecx
push edx stdcall Layer_Destroy,edx
call Layer_Destroy
mov eax,[ebp-8] mov eax,[ebp-8]
push eax push eax
mov edx,[ebp-4] mov edx,[ebp-4]
push edx push edx
mov edx,edi mov edx,edi
shl edx,2 imul edx,sizeof.Layer
mov ecx,[ebp+8] mov ecx,[ebp+8]
mov eax,[ecx+8] mov eax,[ecx+NeuralNetwork.layers]
lea edx,[edx+4*edx]
add eax,edx add eax,edx
push eax stdcall Layer_Create,eax
call Layer_Create
cmp ebx,[ebp-4] ;if(n>s || k>s) cmp ebx,[ebp-4] ;if(n>s || k>s)
jb .215 jb .215
cmp ebx,[ebp-8] cmp ebx,[ebp-8]
@ -1081,7 +1149,7 @@ NNP_SetMemData:
mov ebx,eax mov ebx,eax
test ebx,ebx test ebx,ebx
jne .217 jne .217
mov eax,12 mov eax,txt_err_sqbrl_b1
jmp .193 jmp .193
.217: .217:
inc ebx inc ebx
@ -1089,11 +1157,8 @@ NNP_SetMemData:
mov dword[ebp-8],edx mov dword[ebp-8],edx
jmp .219 jmp .219
.218: .218:
mov esi,[ebp+8]
dec edx dec edx
cmp eax,edx cmp eax,edx
lea ecx,[edi+4*edi]
mov esi,[esi+8]
jae .220 jae .220
stdcall @@strchr$qpxci, ebx,',' stdcall @@strchr$qpxci, ebx,','
add esp,8 add esp,8
@ -1110,22 +1175,23 @@ NNP_SetMemData:
jmp .193 jmp .193
.222: .222:
mov byte[esi],0 mov byte[esi],0
push ebx stdcall @@StrToDouble$qpc,ebx
call @@StrToDouble$qpc
pop ecx pop ecx
lea edx,[edi+4*edi] mov edx,edi
imul edx,sizeof.Layer
mov ecx,[ebp+8] mov ecx,[ebp+8]
lea ebx,[esi+1] lea ebx,[esi+1]
mov eax,[ecx+8] mov eax,[ecx+NeuralNetwork.layers]
mov ecx,[ebp-8] mov ecx,[ebp-8]
mov edx,[eax+4*edx+12] mov edx,[eax+edx+Layer.biases]
fstp qword[edx+8*ecx] fstp qword[edx+8*ecx]
inc dword[ebp-8] inc dword[ebp-8]
.219: .219:
lea edx,[edi+4*edi] mov edx,edi
imul edx,sizeof.Layer
mov ecx,[ebp+8] mov ecx,[ebp+8]
mov ecx,[ecx+8] add edx,[ecx+NeuralNetwork.layers]
mov edx,[ecx+4*edx] mov edx,[edx+Layer.c_size]
mov eax,[ebp-8] mov eax,[ebp-8]
cmp edx,eax cmp edx,eax
ja .218 ja .218
@ -1143,32 +1209,41 @@ NNP_SetMemData:
mov esi,eax mov esi,eax
test esi,esi test esi,esi
jne .225 jne .225
mov eax,15 mov eax,txt_err_sqbrl_w1
jmp .193 jmp .193
.225: .225:
inc esi inc esi
xor edx,edx xor edx,edx
mov dword[ebp-8],edx mov dword[ebp-8],edx ;k=0
jmp .227 jmp .227
.226: .226: ;for(k=0;k<o->layers[i].c_size;k++)
mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8]
add eax,[edx+NeuralNetwork.layers]
mov eax,[eax+Layer.n_size]
or eax,eax
jnz .end_null_we
inc dword[ebp-8] ;k++
jmp .227 ;if 'weights' is null array
.end_null_we:
stdcall @@strchr$qpxci, esi,'[' stdcall @@strchr$qpxci, esi,'['
add esp,8 add esp,8
mov ebx,eax mov ebx,eax
test ebx,ebx test ebx,ebx
jne .228 jne .228
mov eax,16 mov eax,txt_err_sqbrl_w2
jmp .193 jmp .193
.228: .228:
inc ebx inc ebx
xor edx,edx xor edx,edx
mov dword[ebp-12],edx mov dword[ebp-12],edx ;j=0
jmp .230 jmp .230
.229: .229: ;for(j=0;j<o->layers[i].n_size;j++)
mov esi,[ebp+8]
dec edx dec edx
cmp eax,edx cmp eax,edx ;eax = j, edx = n_size-1
lea ecx,[edi+4*edi]
mov esi,[esi+8]
jae .231 jae .231
stdcall @@strchr$qpxci, ebx,',' stdcall @@strchr$qpxci, ebx,','
add esp,8 add esp,8
@ -1181,44 +1256,46 @@ NNP_SetMemData:
.232: .232:
test esi,esi test esi,esi
jne .233 jne .233
mov eax,17 mov eax,txt_err_sqbrr_w2
jmp .193 jmp .193
.233: .233:
mov byte[esi],0 mov byte[esi],0
push ebx stdcall @@StrToDouble$qpc,ebx
call @@StrToDouble$qpc
pop ecx pop ecx
lea edx,[edi+4*edi] mov edx,edi
imul edx,sizeof.Layer
mov ecx,[ebp+8] mov ecx,[ebp+8]
lea ebx,[esi+1] lea ebx,[esi+1]
mov eax,[ecx+8] mov eax,[ecx+NeuralNetwork.layers]
mov ecx,[ebp-8] mov ecx,[ebp-8]
mov edx,[eax+4*edx+16] mov edx,[eax+edx+Layer.weights]
mov eax,[edx+4*ecx] mov eax,[edx+4*ecx]
mov edx,[ebp-12] mov edx,[ebp-12]
fstp qword[eax+8*edx] fstp qword[eax+8*edx]
inc dword[ebp-12] inc dword[ebp-12]
.230: .230:
lea edx,[edi+4*edi] mov edx,edi
imul edx,sizeof.Layer
mov ecx,[ebp+8] mov ecx,[ebp+8]
mov ecx,[ecx+8] add edx,[ecx+NeuralNetwork.layers]
mov edx,[ecx+4*edx+4] mov edx,[edx+Layer.n_size]
mov eax,[ebp-12] mov eax,[ebp-12]
cmp edx,eax cmp edx,eax
ja .229 ja .229
mov esi,ebx mov esi,ebx
inc dword[ebp-8] inc dword[ebp-8]
.227: .227:
lea eax,[edi+4*edi] mov eax,edi
imul eax,sizeof.Layer
mov edx,[ebp+8] mov edx,[ebp+8]
mov ecx,[edx+8] add eax,[edx+NeuralNetwork.layers]
mov eax,[ecx+4*eax] mov eax,[eax+Layer.c_size]
cmp eax,[ebp-8] cmp eax,[ebp-8]
ja .226 ja .226
inc edi inc edi
.205: .205:
mov edx,[ebp+8] mov edx,[ebp+8]
cmp edi,[edx+12] cmp edi,[edx+NeuralNetwork.layers_length]
jb .204 jb .204
xor eax,eax xor eax,eax
jmp .193 jmp .193
@ -1306,6 +1383,7 @@ align 16
EXPORTS: EXPORTS:
dd sz_lib_init, lib_init dd sz_lib_init, lib_init
dd sz_create, NNP_Create dd sz_create, NNP_Create
dd sz_reset, NNP_Reset
dd sz_feedforward, NNP_FeedForward dd sz_feedforward, NNP_FeedForward
dd sz_backpropagation, NNP_BackPropagation dd sz_backpropagation, NNP_BackPropagation
dd sz_getmemdata, NNP_GetMemData dd sz_getmemdata, NNP_GetMemData
@ -1314,6 +1392,7 @@ EXPORTS:
dd 0,0 dd 0,0
sz_lib_init db 'lib_init',0 sz_lib_init db 'lib_init',0
sz_create db 'NNP_Create',0 sz_create db 'NNP_Create',0
sz_reset db 'NNP_Reset',0
sz_feedforward db 'NNP_FeedForward',0 sz_feedforward db 'NNP_FeedForward',0
sz_backpropagation db 'NNP_BackPropagation',0 sz_backpropagation db 'NNP_BackPropagation',0
sz_getmemdata db 'NNP_GetMemData',0 sz_getmemdata db 'NNP_GetMemData',0