diff --git a/grafico.h b/grafico.h index a480725..fe7c939 100644 --- a/grafico.h +++ b/grafico.h @@ -94,8 +94,8 @@ void disegna_legenda(int multi_layer) { textout_ex(screen, font, "Percettrone", 0 + 10, 0 + 10, colore_rosso, -1); else { 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 out", 0 + 10, 0 + 30, colore_blu, -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); } } diff --git a/layer_multi b/layer_multi new file mode 100755 index 0000000..ec24189 Binary files /dev/null and b/layer_multi differ diff --git a/layer_multi.c b/layer_multi.c index f04a139..24ec522 100644 --- a/layer_multi.c +++ b/layer_multi.c @@ -82,12 +82,11 @@ 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_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)); - int size_iniziale = sizeof(rette_p_ext_1); - // Soglia sigmoide double soglia_funzione_attivazione = 0.5; @@ -101,8 +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_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,17 +170,23 @@ 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 * 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_pout[i].m = -(pout.w1 * x[j][0]) / 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))); + 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_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)); } } diff --git a/layer_singolo b/layer_singolo new file mode 100755 index 0000000..5acb08f Binary files /dev/null and b/layer_singolo differ diff --git a/layer_singolo.c b/layer_singolo.c index c2ec22a..43cef75 100644 --- a/layer_singolo.c +++ b/layer_singolo.c @@ -12,7 +12,7 @@ int MAX_EPOCHE = 10000; 4: NOR 5: XNOR */ -int tipo = 3; +int tipo = 4; void stampa_risultati(Percettrone); void sleep_ms(int);