Nasamos

Basic Neural Network AGK Tier 1

Jul 15th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. SetWindowSize(1024, 768, 0)
  2. global Sum as float
  3. Sum = 0
  4. global Error as float
  5. Error = 0
  6. global Actual_Result as float
  7. Actual_Result = 0
  8. global Desired_Result as float
  9. Desired_Result = 1
  10. global Learning_Rate as float
  11. Learning_Rate = 0.1
  12. global Trials as integer
  13. Trials = 10
  14.  
  15.  
  16. global Inputs as float[4]
  17.  
  18. Inputs[1] = 0
  19. Inputs[2] = 1
  20. Inputs[3] = 0
  21. Inputs[4] = 0
  22.  
  23. global Weights as float[4]
  24.  
  25. Weights[1] = 0
  26. Weights[2] = 0
  27. Weights[3] = 0
  28. Weights[4] = 0
  29.  
  30. global Results as float[4]
  31.  
  32. Results[1] = 0
  33. Results[2] = 0
  34. Results[3] = 0
  35. Results[4] = 0
  36.  
  37. function NeuralNetwork()
  38. Sum = 0
  39. for x = 1 to 4
  40. Results[x] = 0
  41. Results[x] = Inputs[x] * Weights[x]
  42. Sum = Results[x] + Sum
  43. next x
  44. endfunction
  45.  
  46. function Evaluate_NeuralNetwork()
  47. for i = 1 to 4
  48. Actual_Result = Results[i] + Actual_Result
  49. next i
  50. Error = Desired_Result - Actual_Result
  51. endfunction
  52.  
  53. function Learn_NeuralNetwork()
  54. for j = 1 to 4
  55. if Inputs[j] > 0
  56. Weights[j] = Weights[j] + Learning_Rate
  57. endif
  58. next j
  59. endfunction
  60.  
  61. function Train_NeuralNetwork()
  62. while Trials > 0
  63. NeuralNetwork()
  64. Learn_NeuralNetwork()
  65. Trials = Trials - 1
  66. endwhile
  67.  
  68. while Trials = 0
  69. NeuralNetwork()
  70. Evaluate_NeuralNetwork()
  71. Trials = Trials - 1
  72. endwhile
  73. endfunction
  74.  
  75. do
  76. Train_NeuralNetwork()
  77. printC("Neural network output: ")
  78. print(Sum)
  79. printC("Error: ")
  80. print(Error)
  81. print("")
  82. Print("Inputs: ")
  83. for i = 1 to 4
  84. Printc(i)
  85. printc(": ")
  86. Print(Inputs[i])
  87. next i
  88.  
  89. Print("")
  90. Print("Weights: ")
  91. for i = 1 to 4
  92. Printc(i)
  93. printc(": ")
  94. print(Weights[i])
  95. next i
  96.  
  97. Print("")
  98. Print("Results: ")
  99. for i = 1 to 4
  100. Printc(i)
  101. printc(": ")
  102. print(Results[i])
  103. next i
  104.  
  105. Print("")
  106. Print("Actual Result: ")
  107. Printc("1: ")
  108. Print(Actual_Result)
  109.  
  110. Print("")
  111. Print("Desired Result: ")
  112. Printc("1: ")
  113. Print(Desired_Result)
  114. sync()
  115. loop
Advertisement
Add Comment
Please, Sign In to add comment