Advertisement
Guest User

Perceptron

a guest
Oct 14th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2.  
  3.  
  4. public class Perceptron {
  5.  
  6. public static final int data[][][] = { { {-1, 49, 21, 168}, {0, 0}},
  7. { {-1,50, 168, 82}, {0, 1}},
  8. { {-1,168, 74, 50}, {1, 0}},
  9. { {-1,21, 108, 189}, {0, 0}},
  10. { {-1,21, 144, 189}, {0, 0}},
  11. { {-1,168, 92, 50}, {1, 0}},
  12. { {-1,102, 128, 50}, {0, 1}},
  13. { {-1,50, 168, 117}, {0, 1}},
  14. { {-1,168, 50, 50}, {1, 0}},
  15. { {-1,35, 112, 140}, {0, 0}},
  16. { {-1,140, 224, 255},{0, 0}},
  17. { {-1,121, 168, 50}, {0, 1}},
  18. { {-1,212, 49, 49}, {1, 0}},
  19. { {-1,133, 7, 7}, {1, 0}} };
  20.  
  21. static double pesos[] = { Math.random(), Math.random(), Math.random() };
  22. static Perceptron driver = new Perceptron();
  23. static Rede neuronio[] = new Rede[data[0][1].length];
  24. static boolean flag = true;
  25. static int epoca = 0;
  26. static double erro = 0;
  27. static double pesoAtualizado[] = null;
  28.  
  29. public static void main(String[] args) {
  30.  
  31.  
  32. do{
  33. treinamento();
  34. epoca++;
  35. }while(flag);
  36. System.out.println(epoca);
  37. }
  38. public static void treinamento() {
  39. erro = 0;
  40. flag = false;
  41. for(int i = 0 ; i < data.length;i++) {
  42. for(int j = 0; j < neuronio.length;j++) {
  43. double SomaDosPesos = neuronio[j].PesoSoma(data[i][0], pesos[j]);
  44. int resultado = neuronio[j].funcdegrau(SomaDosPesos);
  45. erro = data[i][1][j] - resultado;
  46. if(erro != 0) {
  47. flag = true;
  48. }
  49. pesoAtualizado = neuronio[i].atualiza(data[i][0], pesos[j], erro);
  50. pesos = pesoAtualizado;
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement