kolibrios-fun/programs/develop/libraries/nnp/about.htm
IgorA 2ee9123f08 update library 'nnp.obj'
git-svn-id: svn://kolibrios.org@9821 a494cfbc-eb01-0410-851d-a64ba20cac60
2022-05-28 12:21:03 +00:00

182 lines
7.0 KiB
HTML

<html>
<head>
<title>áèáëèîòåêà äëÿ ðàáîòû ñ íåéðîñåòüþ (neural network perceptron)</title>
<meta charset="WINDOWS-1251">
<style>
body
{
font-size: 15px;
font-family: "Bookman Old Style";
color: black;
text-align: justify;
}
h1 { color: green; font-size: 23px; }
h2 { color: green; font-size: 21px; }
h3 { color: green; font-size: 19px; }
h4 { color: #803f00; font-size: 17px; }
i { color: #0099cc; }
b { color: #0099cc; }
p {
text-indent: 1em;
margin-top: 3px;
margin-bottom: 2px;
margin-left: 0px;
margin-right: 0px;
}
ol, ul, dl{
margin-top: 3px;
margin-bottom: 2px;
}
pre
{
padding: 2px;
padding-left: 20px;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 0px;
margin-right: 0px;
font-family: "Courier New";
font-size: 15px;
color: #004000;
background-color: #ffd0ff;
}
table { font-size: 15px; }
</style>
</head>
<body>
<h1>Îãëàâëåíèå</h1>
<ul>
<li>Âñòóïëåíèå</li>
<li><a href="#fun">Ôóíêöèè</a><br>
<ul>
<li><a href="#f_init">lib_init</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_backp">NNP_BackPropagation</a></li>
<li><a href="#f_getmd">NNP_GetMemData</a></li>
<li><a href="#f_setmd">NNP_SetMemData</a></li>
<li><a href="#f_destroy">NNP_Destroy</a></li>
</ul>
</li>
<li><a href="#const">Êîíñòàíòû</a></li>
<li><a href="#tabl_e">Òàáëèöà ýêñïîðòà</a></li>
<li><a href="#ex1">Ïðèìåð</a></li>
<li><a href="#hist">Èñòîðèÿ</a></li>
</ul>
<h1>Âñòóïëåíèå</h1>
<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>
<p>Ïîñëåäíåå îáíîâëåíèå áèáëèîòåêè 28.05.22.</p>
<h1><a name="fun">Ôóíêöèè</a></h1>
<p>Âñå ôóíêöèè (êðîìå lib_init) 1-ì ïàðàìåòðîì ïðèíèìàþò óêàçàòåëü íà ñòðóêòóðó NeuralNetwork.
Îïèñàíèå ñòðóêòóðû NeuralNetwork:</p>
<pre>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</pre>
<h4><a name="f_init">lib_init</a></h4>
<p>Ýòà ôóíêöèÿ ïîëó÷àåò óêàçàòåëè íà ôóíêöèè ðàáîòû ñ ïàìÿòüþ, âûçûâàòñÿ äîëæíà ïðè çàãðóçêå áèáëèîòåêè. Ìîæåòå èñïîëüçîâàòü ìàêðîñ <b>@use_library</b>, äëÿ åå àâòîìàòè÷åñêîé íàñòðîéêè.</p>
<h4><a name="f_create">NNP_Create</a></h4>
<p>Ñîçäàåò ñëîè íåéðîñåòè è çàïîëíÿåò âåñà ñëó÷àéíûìè çíà÷åíèÿìè îò -1 äî 1. Ïðèìåð:</p>
<pre>NNLOPT_LEN equ 7
nnlopt dd 2,8,8,8,8,8,3
...
stdcall [NNP_Create], nnp_0, 0.01, 0, 0, nnlopt, NNLOPT_LEN</pre>
<p>ãäå nnp_0 - ñòðóêòóðà íåéðîñåòè.</p>
<p>0.01 - ñêîðîñòü îáó÷åíèÿ.</p>
<p>0 - àäðåñ ôóíêöèè àêòèâàöèè, åñëè 0 òî áåðåòñÿ ñòàíäàðòíàÿ ôóíêöèÿ âíóòðè áèáëèîòåêè.</p>
<p>0 - àäðåñ ôóíêöèè ñâ¸ðòêè, åñëè 0 òî áåðåòñÿ ñòàíäàðòíàÿ ôóíêöèÿ âíóòðè áèáëèîòåêè.</p>
<p>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>
<p>Ôóíêöèÿ ðàñ÷åòà çíà÷åíèé âûõîäíûõ íåéðîíîâ. Íà âõîä ïîäàþòüñÿ çíà÷åíèÿ âõîäíûõ íåéðîíîâ. Íà âûõîäå âîçâðàùàåòñÿ óêàçàòåëü íà ñëîé âûõîäíûõ íåéðîíîâ.</p>
<pre>n_input dq ?,?,?
...
stdcall [NNP_FeedForward], nnp_0,n_input</pre>
<p>ãäå nnp_0 - ñòðóêòóðà íåéðîñåòè, n_input - óêàçàòåëü íà äàííûå âõîäíûõ íåéðîíîâ.</p>
<h4><a name="f_backp">NNP_BackPropagation</a></h4>
<p>Ôóíêöèÿ äëÿ îáó÷åíèÿ ñåòè. Ïðèìåð:</p>
<pre>n_targ dq ?,?,?
...
stdcall [NNP_BackPropagation], nnp_0, n_targ</pre>
<p>ãäå nnp_0 - ñòðóêòóðà íåéðîñåòè, n_targ - óêàçàòåëü íà äàííûå äëÿ îáó÷åíèÿ ñåòè.</p>
<h4><a name="f_getmd">NNP_GetMemData</a></h4>
<p>Áåðåò äàííûå íåéðîñåòè è çàïèñûâàåò èõ â óêàçàííîå ìåñòî â ïàìÿòè. Ïðèìåð:</p>
<pre>f_data dd ?
...
stdcall [NNP_GetMemData], nnp_0, NNP_FF_JSON, [f_data]</pre>
<p>ãäå nnp_0 - ñòðóêòóðà íåéðîñåòè, f_data - óêàçàòåëü íà äàííûå äëÿ çàïèñè ïàðàìåòðîâ ñåòè.</p>
<h4><a name="f_setmd">NNP_SetMemData</a></h4>
<p>Áåðåò äàííûå èç óêàçàííîãî ìåñòà ïàìÿòè è çàïèñûâàåò èõ â íåéðîñåòü.  ñëó÷àå óñïåõà â ðåãèñòðå eax âîçâðàùàåòñÿ 0, èíà÷å óêàçàòåëü íà ñòðîêó ñ òåêñòîì îøèáêè. Ïðèìåð:</p>
<pre>f_data dd ?
...
stdcall [NNP_SetMemData], nnp_0, NNP_FF_JSON, [f_data]</pre>
<p>ãäå nnp_0 - ñòðóêòóðà íåéðîñåòè, f_data - óêàçàòåëü íà äàííûå ñ ïàðàìåòðàìè ñåòè.</p>
<h4><a name="f_delete">NNP_Destroy</a></h4>
<p>Îñâîáîæäàåò ïàìÿòü çàíÿòóþ íåéðîñåòüþ.</p>
<h1><a name="const">Êîíñòàíòû</a></h1>
<h4>NNP_FF_BIN equ 0x6e6962</h4>
<p>Êîíñòàíòà äëÿ ôóíêöèé NNP_GetMemData è NNP_SetMemData. Óêàçûâàåò áèíàðíûé ôîðìàò ââîäà è âûâîäà äàííûõ.</p>
<h4>NNP_FF_JSON equ 0x6e6f736a</h4>
<p>Êîíñòàíòà äëÿ ôóíêöèé NNP_GetMemData è NNP_SetMemData. Óêàçûâàåò òåêñòîâûé (JSON) ôîðìàò ââîäà è âûâîäà äàííûõ.</p>
<h1><a name="tabl_e">Òàáëèöà ýêñïîðòà</a></h1>
<p>Ïðèìåð òàáëèöû ýêñïîðòà, ðàñ÷èòàííîé íà èñïîëüçîâàíèå ìàêðîñà <b>@use_library_mem</b>:</p>
<pre>align 4
import_nnp_lib:
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_lib_init db 'lib_init',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
</pre>
<h1><a name="ex1">Ïðèìåð</a></h1>
<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>
</html>