Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Perceptron {
- public static final int data[][][] = {{{-1, 49, 21, 168}, {0, 0}},
- { {-1,50, 168, 82}, {0, 1}},
- { {-1,168, 74, 50}, {1, 0}},
- { {-1,21, 108, 189}, {0, 0}},
- { {-1,21, 144, 189}, {0, 0}},
- { {-1,168, 92, 50}, {1, 0}},
- { {-1,102, 128, 50}, {0, 1}},
- { {-1,50, 168, 117}, {0, 1}},
- { {-1,168, 50, 50}, {1, 0}},
- { {-1,35, 112, 140}, {0, 0}},
- { {-1,140, 224, 255},{0, 0}},
- { {-1,121, 168, 50}, {0, 1}},
- { {-1,212, 49, 49}, {1, 0}},
- { {-1,133, 7, 7}, {1, 0}} };
- static double pesos[][] = { { Math.random(), Math.random(),Math.random(), Math.random()}, {Math.random(), Math.random(),Math.random(), Math.random()} };
- static Perceptron driver = new Perceptron();
- static Rede neuronio[] = new Rede[data[0][1].length];
- static boolean flag = true;
- static int epoca = 0;
- static double erro = 0;
- static double pesoAtualizado[] = null;
- public static void main(String[] args) {
- do{
- treinamento();
- epoca++;
- }while(flag);
- System.out.println(epoca);
- }
- public static void treinamento() {
- erro = 0;
- flag = false;
- for(int i = 0 ; i < data.length;i++) {
- for(int j = 0; j < neuronio.length;j++) {
- double SomaDosPesos = neuronio[j].PesoSoma(data[i][0], pesos[j]);
- int resultado = neuronio[j].funcdegrau(SomaDosPesos);
- erro = data[i][1][j] - resultado;
- if(erro != 0) {
- flag = true;
- }
- pesoAtualizado = neuronio[i].atualiza(data[i][0], pesos[j], erro);
- pesos[j] = pesoAtualizado;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement