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

@@ -82,9 +82,9 @@ void main()
// Contatore per fermare il percettrone, se vale 4 significa che ha indovinato tutte e 4 le combinazioni
int corrette = 0;
//Retta *rette_p_ext_1 = (Retta *)malloc(sizeof(Retta));
//Retta *rette_p_ext_2 = (Retta *)malloc(sizeof(Retta));
Retta *rette_layer_uno = (Retta *)malloc(sizeof(Retta));
Retta *rette_p_ext_1 = (Retta *)malloc(sizeof(Retta));
Retta *rette_p_ext_2 = (Retta *)malloc(sizeof(Retta));
//Retta *rette_layer_uno = (Retta *)malloc(sizeof(Retta));
Retta *rette_pout = (Retta *)malloc(sizeof(Retta));
// Soglia sigmoide
@@ -100,9 +100,9 @@ void main()
for (int z = 0; z < i; z++)
{
cls(tipo, 1);
//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_layer_uno[z].m, rette_layer_uno[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_layer_uno[z].m, rette_layer_uno[z].q, colore_rosso);
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 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
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].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].q = -(p_ext_2.bias / p_ext_2.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_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_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);
// 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].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].m =
rette_layer_uno[i].q = -(p_ext_1.bias / p_ext_1.w2); */
if (corrette != 4)
{
/* 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_layer_uno = (Retta *)realloc(rette_layer_uno, 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_layer_uno = (Retta *)realloc(rette_layer_uno, sizeof(Retta) * (i + 2));
rette_pout = (Retta *)realloc(rette_pout, sizeof(Retta) * (i + 2));
}
}