ritorno a rette percettroni aggiustamento formule retta

This commit is contained in:
2025-01-25 18:45:01 +01:00
parent 9c1205a371
commit 99d3b2f831
5 changed files with 22 additions and 19 deletions

View File

@@ -94,8 +94,8 @@ void disegna_legenda(int multi_layer) {
textout_ex(screen, font, "Percettrone", 0 + 10, 0 + 10, colore_rosso, -1); textout_ex(screen, font, "Percettrone", 0 + 10, 0 + 10, colore_rosso, -1);
else { else {
textout_ex(screen, font, "Percettrone 1", 0 + 10, 0 + 10, colore_rosso, -1); textout_ex(screen, font, "Percettrone 1", 0 + 10, 0 + 10, colore_rosso, -1);
//textout_ex(screen, font, "Percettrone 2", 0 + 10, 0 + 20, colore_verde, -1); textout_ex(screen, font, "Percettrone 2", 0 + 10, 0 + 20, colore_verde, -1);
textout_ex(screen, font, "Percettrone out", 0 + 10, 0 + 20, colore_blu, -1); textout_ex(screen, font, "Percettrone out", 0 + 10, 0 + 30, colore_blu, -1);
} }
} }

Binary file not shown.

View File

@@ -82,9 +82,9 @@ void main()
// Contatore per fermare il percettrone, se vale 4 significa che ha indovinato tutte e 4 le combinazioni // Contatore per fermare il percettrone, se vale 4 significa che ha indovinato tutte e 4 le combinazioni
int corrette = 0; int corrette = 0;
//Retta *rette_p_ext_1 = (Retta *)malloc(sizeof(Retta)); Retta *rette_p_ext_1 = (Retta *)malloc(sizeof(Retta));
//Retta *rette_p_ext_2 = (Retta *)malloc(sizeof(Retta)); Retta *rette_p_ext_2 = (Retta *)malloc(sizeof(Retta));
Retta *rette_layer_uno = (Retta *)malloc(sizeof(Retta)); //Retta *rette_layer_uno = (Retta *)malloc(sizeof(Retta));
Retta *rette_pout = (Retta *)malloc(sizeof(Retta)); Retta *rette_pout = (Retta *)malloc(sizeof(Retta));
// Soglia sigmoide // Soglia sigmoide
@@ -100,9 +100,9 @@ void main()
for (int z = 0; z < i; z++) for (int z = 0; z < i; z++)
{ {
cls(tipo, 1); cls(tipo, 1);
//traccia_retta(rette_p_ext_1[z].m, rette_p_ext_1[z].q, colore_rosso); traccia_retta(rette_p_ext_1[z].m, rette_p_ext_1[z].q, colore_rosso);
//traccia_retta(rette_p_ext_2[z].m, rette_p_ext_2[z].q, colore_verde); traccia_retta(rette_p_ext_2[z].m, rette_p_ext_2[z].q, colore_verde);
traccia_retta(rette_layer_uno[z].m, rette_layer_uno[z].q, colore_rosso); //traccia_retta(rette_layer_uno[z].m, rette_layer_uno[z].q, colore_rosso);
traccia_retta(rette_pout[z].m, rette_pout[z].q, colore_blu); traccia_retta(rette_pout[z].m, rette_pout[z].q, colore_blu);
//printf("Sto tracciando la retta p1 con coefficiente: %f e intercetta: %f\n", rette_p_ext_1[z].m, rette_p_ext_1[z].q); //printf("Sto tracciando la retta p1 con coefficiente: %f e intercetta: %f\n", rette_p_ext_1[z].m, rette_p_ext_1[z].q);
//printf("Sto tracciando la retta p2 con coefficiente: %f e intercetta: %f\n", rette_p_ext_2[z].m, rette_p_ext_2[z].q); //printf("Sto tracciando la retta p2 con coefficiente: %f e intercetta: %f\n", rette_p_ext_2[z].m, rette_p_ext_2[z].q);
@@ -170,23 +170,26 @@ void main()
// Prevengo la divisione per zero // Prevengo la divisione per zero
if(p_ext_1.w2 != 0 && p_ext_2.w2 != 0 && pout.w2 !=0) if(p_ext_1.w2 != 0 && p_ext_2.w2 != 0 && pout.w2 !=0)
{ {
// rette_p_ext_1[i].m = -(p_ext_1.w1 * x[j][0]) / p_ext_1.w2; rette_p_ext_1[i].m = -(p_ext_1.w1 / p_ext_1.w2);
// rette_p_ext_1[i].q = -(p_ext_1.bias / p_ext_1.w2); rette_p_ext_1[i].q = -(p_ext_1.bias / p_ext_1.w2);
// rette_p_ext_2[i].m = -(p_ext_2.w1 * x[j][0]) / p_ext_2.w2; rette_p_ext_2[i].m = -(p_ext_2.w1 / p_ext_2.w2);
// rette_p_ext_2[i].q = -(p_ext_2.bias / p_ext_2.w2); rette_p_ext_2[i].q = -(p_ext_2.bias / p_ext_2.w2);
rette_pout[i].m = -(pout.w1 * x[j][0]) / pout.w2; /* rette_pout[i].m = -(pout.w1 * x[j][0]) / pout.w2;
rette_pout[i].q = -(pout.bias / pout.w2); */
rette_pout[i].m = -(pout.w1) / pout.w2;
rette_pout[i].q = -(pout.bias / pout.w2); rette_pout[i].q = -(pout.bias / pout.w2);
// somma delle rette (m1 + m2)x + (q1 + q2) // somma delle rette (m1 + m2)x + (q1 + q2)
rette_layer_uno[i].m = rette_pout[i].m - ((-(p_ext_1.w1 * x[j][0]) / p_ext_1.w2) + (-(p_ext_2.w1 * x[j][0]) / p_ext_2.w2)); /* rette_layer_uno[i].m =
rette_layer_uno[i].q = rette_pout[i].q - ((-(p_ext_1.bias / p_ext_1.w2)) - (-(p_ext_2.bias / p_ext_2.w2))); rette_layer_uno[i].q = -(p_ext_1.bias / p_ext_1.w2); */
if (corrette != 4) if (corrette != 4)
{ {
/* rette_p_ext_1 = (Retta *)realloc(rette_p_ext_1, sizeof(Retta) * (i + 2)); rette_p_ext_1 = (Retta *)realloc(rette_p_ext_1, sizeof(Retta) * (i + 2));
rette_p_ext_2 = (Retta *)realloc(rette_p_ext_2, sizeof(Retta) * (i + 2)); */ rette_p_ext_2 = (Retta *)realloc(rette_p_ext_2, sizeof(Retta) * (i + 2));
rette_layer_uno = (Retta *)realloc(rette_layer_uno, sizeof(Retta) * (i + 2)); //rette_layer_uno = (Retta *)realloc(rette_layer_uno, sizeof(Retta) * (i + 2));
rette_pout = (Retta *)realloc(rette_pout, sizeof(Retta) * (i + 2)); rette_pout = (Retta *)realloc(rette_pout, sizeof(Retta) * (i + 2));
} }
} }

Binary file not shown.

View File

@@ -136,7 +136,7 @@ void main()
correggi_pesi(&p, gradiente_w1, gradiente_w2, gradiente_bias); correggi_pesi(&p, gradiente_w1, gradiente_w2, gradiente_bias);
} }
rette[i].m = -(p.w1 * x[j][0]) / p.w2; rette[i].m = -(p.w1 / p.w2);
rette[i].q = -(p.bias / p.w2); rette[i].q = -(p.bias / p.w2);
if (corrette != 4) if (corrette != 4)