Files
percettroni_c/percettrone.c
2025-01-24 19:02:24 +01:00

48 lines
1.1 KiB
C

#include <stdlib.h>;
#include <stdio.h>;
#include <time.h>;
Percettrone p1 = creaPercettrone();
Percettrone p2 = creaPercettrone();
Percettrone p3 = creaPercettrone();
struct struttura_percettrone {
double w1;
double w2;
double bias;
double lre;
};
typedef struct struttura_percettrone Percettrone;
Percettrone creaPercettrone() {
srand(time(NULL));
Percettrone percettrone;
percettrone.w1 = random();
percettrone.w2 = random();
percettrone.bias = random();
percettrone.lre = 0.2;
return percettrone;
}
double random() {
// Genero numeri nell'intervallo [-1,1]
return ((double)(rand() % 101 * 0.01 * 2 ) -1);
}
void main() {
creaPercettrone();
}
/* # il return verrà confrontato col valore di soglia di attivazione
def funzione_sigmoide(self, x1, x2):
return (1 / (1 + math.exp(-((x1 * self.w1) + (x2 * self.w2) + self.bias))))
def correggi_pesi(self, gradiente_w1, gradiente_w2, gradiente_bias):
self.bias = self.bias - (gradiente_bias * self.lre)
self.w1 = self.w1 - (gradiente_w1 * self.lre)
self.w2 = self.w2 - (gradiente_w2 * self.lre) */