messo codice che segna i punti invece delle rette
This commit is contained in:
68
layer_singolo_addestrato.c
Normal file
68
layer_singolo_addestrato.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <stdio.h>
|
||||
#include "percettrone.h"
|
||||
#include "grafico.h"
|
||||
|
||||
int MAX_CICLI = 10000;
|
||||
/*
|
||||
il tipo indica quali punti vogliamo disegnare nel grafico:
|
||||
0: AND
|
||||
1: OR
|
||||
2: XOR
|
||||
3: NAND
|
||||
4: NOR
|
||||
5: XNOR
|
||||
*/
|
||||
int tipo = 1;
|
||||
|
||||
// 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, 800, 600, 0, 0);
|
||||
cls(tipo, 0);
|
||||
|
||||
Percettrone p;
|
||||
p.w1 = 0.042967;
|
||||
p.w2 = 0.029020;
|
||||
p.bias = -0.019373;
|
||||
|
||||
int colore_rosso = makecol(255, 0, 0);
|
||||
int colore_verde = makecol(0, 255, 0);
|
||||
|
||||
for (int i = 0; i < MAX_CICLI; i++)
|
||||
{
|
||||
//printf("\nCiclo: %d\n", i);
|
||||
|
||||
Punto input;
|
||||
input.x = randomico_positivo();
|
||||
input.y = randomico_positivo();
|
||||
|
||||
double y = funzione_sigmoide(p,input.x, input.y);
|
||||
|
||||
int previsione = -1;
|
||||
|
||||
if (y >= 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(100);
|
||||
readkey();
|
||||
}
|
||||
Reference in New Issue
Block a user