11tumia hisabati
22
3+ // Mbinu za Kupanga
4+ //orodhesha(kwanza, mwisho, umbali), huunda orodha ya nambari na umbali uliowekwa kati yao.
5+ fanya orodhesha = unda (kwanza , mwisho , umbali ){
6+ fanya orodha = [kwanza ];
7+ fanya i = kwanza + umbali ;
8+ wakati (i < mwisho ){
9+ orodha .sukuma (i );
10+ i += umbali ;
11+ }
12+ rudisha orodha ;
13+ }
14+
315// Kuanzisha uzani bila mpangilio
416fanya mizani = [
517 hisabati .random () * 2 - 1 ,
@@ -18,6 +30,7 @@ fanya sigmoid = unda(vekta) {
1830
1931// Derivative ya undo la sigmoid
2032fanya sigmoidDerivative = unda (vekta ) {
33+ andika ("vekta: " ,vekta )
2134 fanya tokeo = [];
2235 kwa v ktk vekta {
2336 tokeo .sukuma (v * (1 - v ));
@@ -26,9 +39,9 @@ fanya sigmoidDerivative = unda(vekta) {
2639 rudisha tokeo ;
2740}
2841
29- fanya kuzidishaTumboVekta = unda (tumbo , vekta ) {
42+ fanya kuzidishaMatrikiVekta = unda (matriki , vekta ) {
3043 fanya tokeo = [];
31- kwa row ktk tumbo {
44+ kwa row ktk matriki {
3245 fanya jamii = 0 ;
3346 kwa j , kipengee ktk row {
3447 jamii += kipengee * vekta [j ];
@@ -54,53 +67,87 @@ fanya zidishaKwaNukta = unda(safu1, safu2) {
5467
5568// Songa mbele kupitia mtandao wa neva
5669fanya waza = unda (pembejeo , mizani ) {
57- fanya jumlaYaUzani = sigmoid (kuzidishaTumboVekta (pembejeo , mizani ));
70+ fanya jumlaYaUzani = sigmoid (kuzidishaMatrikiVekta (pembejeo , mizani ));
5871 rudisha jumlaYaUzani ;
5972}
6073
74+ fanya badiliMatriki = unda (matrix ) {
75+ // Pata idadi ya safu mlalo na safu wima katika matrix asili
76+ fanya nambari_ya_safu_mlalo = matrix .idadi ();
77+ fanya nambari_ya_safu_wima = matrix [0 ].idadi ();
78+
79+ // Unda matrix mpya na safu mlalo na safu wima zilizobadilishwa
80+ fanya matrikiIliyobadili = [];
81+
82+ // Pita ndani ya safu wima
83+ kwa safu_wima_ya , safuW ktk orodhesha (0 , nambari_ya_safu_wima , 1 ){
84+ // Anzisha safu mlalo mpya kwa matriki iliyopitishwa
85+ fanya transposed_safu_mlalo = [];
86+
87+ // Pita ndani ya safu mlalo
88+ kwa safu_mlalo_ya , safu ktk orodhesha (0 , nambari_ya_safu_mlalo , 1 ){
89+ // Sukuma kipengele kwenye safu wima ya sasa na safu mlalo hadi safu iliyopitishwa
90+ transposed_safu_mlalo .sukuma (matrix [safu_mlalo_ya ][safu_wima_ya ]);
91+ }
92+
93+ // Sukuma safu mlalo iliyopitishwa kwenye matriki lililopitishwa
94+ matrikiIliyobadili .sukuma (transposed_safu_mlalo );
95+ }
96+
97+ rudisha matrikiIliyobadili ;
98+ }
99+
61100// Funza mtandao wa neva
62101fanya funza = unda (mizani , mafunzoPembejeo , matokeoYaMafunzo , marudioYaMafunzo ) {
63102 fanya kurudia = 0
64103
65- andika ('mafunzoPembejeo : ');
104+ andika ('\ nmafunzoPembejeo : ');
66105 andika (mafunzoPembejeo );
67106
68- andika ('matokeoYaMafunzo : ');
107+ andika ('\ nmatokeoYaMafunzo : ');
69108 andika (matokeoYaMafunzo );
70109
71110
111+ fanya orodha = orodhesha (0 , marudioYaMafunzo , 1 )
112+ // andika("orodha: ",orodha)
72113
73- wakati ( kurudia < marudioYaMafunzo ) {
74- andika ('kurudia : ');
75- andika (kurudia );
114+ kwa i ktk orodha {
115+ andika ('\ n \ nkurudia : ');
116+ andika (i );
76117 // Pitisha mafunzo yaliyowekwa kupitia mtandao wa neva
77118 fanya pato = waza (mafunzoPembejeo , mizani );
78119
79- andika ('pato : ');
120+ andika ('\ npato : ');
80121 andika (pato );
81- // Kuhesabu kiwango cha makosa
122+
123+ // Kuhesabu kiwango cha upungufu
82124 fanya upungufu = [];
83125 kwa i , kipengee ktk matokeoYaMafunzo {
84126 upungufu .sukuma (kipengee - pato [i ]);
85127 }
86128
87- fanya sigmoidDerivative = sigmoidDerivative (pato )
88-
89- andika ('upungufu : ');
129+ andika ('\nupungufu : ');
90130 andika (upungufu );
91131
92- andika ('sigmoidDerivative tokeo : ');
93- andika (sigmoidDerivative );
132+ fanya sigmoidDerivative_ya_pato = sigmoidDerivative (pato )
94133
95- fanya zidishaKwaNukta = zidishaKwaNukta (upungufu , sigmoidDerivative );
134+ andika ('\nsigmoidDerivative tokeo : ');
135+ andika (sigmoidDerivative_ya_pato );
96136
97- andika ('zidishaKwaNukta tokeo : ');
98- andika (zidishaKwaNukta );
137+ fanya zidishaKwaNukta_tokeo = zidishaKwaNukta (upungufu , sigmoidDerivative_ya_pato );
99138
100- // Kuzidisha makosa kwa pembejeo na upinde rangi ya kitendakazi cha sigmoid
139+ andika ('\nzidishaKwaNukta tokeo : ');
140+ andika (zidishaKwaNukta_tokeo );
141+
142+ fanya mafunzoPembejeoYaliyobadili = badiliMatriki (mafunzoPembejeo )
143+
144+ andika ('\nmafunzo pembejeo yaliyobadili : ');
145+ andika (mafunzoPembejeoYaliyobadili );
146+
147+ // Kuzidisha upungufu kwa pembejeo na upinde rangi ya kitendakazi cha sigmoid
101148 // Uzito mdogo wa ujasiri hurekebishwa zaidi kupitia asili ya kazi
102- fanya marekebisho = kuzidishaTumboVekta (mafunzoPembejeo , zidishaKwaNukta );
103- andika ('marekebisho tokeo : ');
149+ fanya marekebisho = kuzidishaMatrikiVekta (mafunzoPembejeo , zidishaKwaNukta_tokeo );
150+ andika ('\ nmarekebisho tokeo : ');
104151 andika (marekebisho );
105152
106153
@@ -109,16 +156,16 @@ fanya funza = unda(mizani, mafunzoPembejeo, matokeoYaMafunzo, marudioYaMafunzo)
109156 mizani [i ] = mizani [i ] + marekebisho [i ];
110157 }
111158
112- andika ('mizani mpya : ');
159+ andika ('\ nmizani mpya : ');
113160 andika (mizani );
114161 kurudia ++
115162 }
163+
116164 rudisha mizani ;
117165}
118166
119167
120-
121- andika ('Mizani ya Kuanzisha isiyo na mpangilio : ');
168+ andika ('\nMizani ya Kuanzisha isiyo na mpangilio : ');
122169andika (mizani );
123170
124171// Seti ya mafunzo
@@ -128,14 +175,14 @@ fanya matokeoYaMafunzo = [0, 1, 1, 0];
128175// Funza mtandao wa neva
129176fanya mafunzoMizani = funza (mizani , mafunzoPembejeo , matokeoYaMafunzo , 10000 );
130177
131- andika ('Mizani baada ya mafunzo :');
178+ andika ('\ nMizani baada ya mafunzo :');
132179andika (mafunzoMizani );
133180
134181// Ingizo la mtumiaji kwa hali mpya
135- fanya A = 1 ;
182+ fanya A = 0 ;
136183fanya B = 0 ;
137- fanya C = 0 ;
184+ fanya C = 1 ;
138185
139- andika ('Hali mpya : data ya pembejeo = ', A , B , C );
140- andika ('Data ya pato :');
186+ andika ('\ nHali mpya : data ya pembejeo = ', A , B , C );
187+ andika ('\ nData ya pato :');
141188andika (waza ([[A , B , C ]], mafunzoMizani ));
0 commit comments