modifica formula multilayer mettendo i pesi di pout nel calcolo del gradiente e cambiando il segno del calcolo dell'errore
This commit is contained in:
@@ -13,7 +13,7 @@ int MAX_EPOCHE = 10000;
|
||||
4: NOR
|
||||
5: XNOR
|
||||
*/
|
||||
int tipo = 0;
|
||||
int tipo = 2;
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -77,7 +77,8 @@ void main()
|
||||
Percettrone pout = crea_percettrone();
|
||||
int colore_blu = makecol(0, 0, 255);
|
||||
|
||||
p_ext_1.w1 = 1.332870;
|
||||
//XOR
|
||||
/* p_ext_1.w1 = 1.332870;
|
||||
p_ext_1.w2 = -0.628797;
|
||||
p_ext_1.bias = 0.729138;
|
||||
|
||||
@@ -87,7 +88,7 @@ void main()
|
||||
|
||||
pout.w1 = -0.004388;
|
||||
pout.w2 = 0.090205;
|
||||
pout.bias = -0.067931;
|
||||
pout.bias = -0.067931; */
|
||||
|
||||
// Contatore per fermare il percettrone, se vale 4 significa che ha indovinato tutte e 4 le combinazioni
|
||||
int corrette = 0;
|
||||
@@ -135,7 +136,8 @@ void main()
|
||||
double y_ext_2 = funzione_sigmoide(p_ext_2, x[j][0], x[j][1]);
|
||||
double yout = funzione_sigmoide(pout, y_ext_1, y_ext_2);
|
||||
|
||||
double errore = -(output[j] - yout);
|
||||
double errore = (output[j] - yout);
|
||||
|
||||
int previsione = -1;
|
||||
|
||||
if (yout >= soglia_funzione_attivazione)
|
||||
@@ -158,15 +160,15 @@ void main()
|
||||
else
|
||||
{
|
||||
// Gradienti percettrone 1
|
||||
double gradiente_w1 = errore * yout * (1 - yout) * y_ext_1 * (1 - y_ext_1) * x[j][0];
|
||||
double gradiente_w2 = errore * yout * (1 - yout) * y_ext_1 * (1 - y_ext_1) * x[j][1];
|
||||
double gradiente_bias = errore * yout * (1 - yout) * y_ext_1 * (1 - y_ext_1);
|
||||
double gradiente_w1 = errore * yout * (1 - yout) * y_ext_1 * (1 - y_ext_1) * x[j][0] * pout.w1;
|
||||
double gradiente_w2 = errore * yout * (1 - yout) * y_ext_1 * (1 - y_ext_1) * x[j][1] * pout.w1;
|
||||
double gradiente_bias = errore * yout * (1 - yout) * y_ext_1 * (1 - y_ext_1) * pout.w1;
|
||||
correggi_pesi(&p_ext_1, gradiente_w1, gradiente_w2, gradiente_bias);
|
||||
|
||||
// Gradienti percettrone 2
|
||||
gradiente_w1 = errore * yout * (1 - yout) * y_ext_2 * (1 - y_ext_2) * x[j][0];
|
||||
gradiente_w2 = errore * yout * (1 - yout) * y_ext_2 * (1 - y_ext_2) * x[j][1];
|
||||
gradiente_bias = errore * yout * (1 - yout) * y_ext_2 * (1 - y_ext_2);
|
||||
gradiente_w1 = errore * yout * (1 - yout) * y_ext_2 * (1 - y_ext_2) * x[j][0] * pout.w2;
|
||||
gradiente_w2 = errore * yout * (1 - yout) * y_ext_2 * (1 - y_ext_2) * x[j][1] * pout.w2;
|
||||
gradiente_bias = errore * yout * (1 - yout) * y_ext_2 * (1 - y_ext_2) * pout.w2;
|
||||
correggi_pesi(&p_ext_2, gradiente_w1, gradiente_w2, gradiente_bias);
|
||||
|
||||
// Gradienti percettrone out
|
||||
|
||||
Reference in New Issue
Block a user