#include #include "percettrone.h" #include "grafico.h" int MAX_TRY = 500000; /* il tipo indica quali punti vogliamo disegnare nel grafico: 0: AND 1: OR 2: XOR 3: NAND 4: NOR 5: XNOR */ int tipo = 2; // Soglia sigmoide double soglia_funzione_attivazione = 0.5; void sleep_ms(int); void main() { srand(time(NULL)); allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1920, 1080, 0, 0); cls(tipo, 1); int colore_rosso = makecol(255, 0, 0); int colore_verde = makecol(0, 255, 0); Percettrone p_ext_1; Percettrone p_ext_2; Percettrone pout; //AND /* p_ext_1.w1 = 1.332870; p_ext_1.w2 = -0.628797; p_ext_1.bias = 0.729138; p_ext_2.w1 = 0.459249; p_ext_2.w2 = 0.394682; p_ext_2.bias = 0.833102; pout.w1 = -0.004388; pout.w2 = 0.090205; pout.bias = -0.067931; */ //XOR p_ext_1.w1 = 1.423181; p_ext_1.w2 = -1.798159; p_ext_1.bias = -1.757881; p_ext_2.w1 = -0.828619; p_ext_2.w2 = 0.410466; p_ext_2.bias = -0.087439; pout.w1 = 0.145840; pout.w2 = 0.194722; pout.bias = -0.114644; for (int i = 0; i < MAX_TRY; i++) { //printf("\nCiclo %d\n", i); Punto input; input.x = randomico_positivo(); input.y = randomico_positivo(); double y_ext_1 = funzione_sigmoide(p_ext_1, input.x, input.y); double y_ext_2 = funzione_sigmoide(p_ext_2, input.x, input.y); double yout = funzione_sigmoide(pout, y_ext_1, y_ext_2); int previsione = -1; if (yout >= soglia_funzione_attivazione) { previsione = 1; } else { previsione = 0; } printf("Inputs: %f:%f -> previsione: %d\n", input.x, input.y, previsione); if (previsione == 1) traccia_inputs(input, colore_verde); else traccia_inputs(input, colore_rosso); } sleep_ms(10); readkey(); }