Advertisement
Sitisom

нейро_гавно

Dec 27th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import numpy as np
  2.  
  3. x = np.array([
  4. [
  5. 0, 0, 0, 0, 0,
  6. 0, 0, 1, 0, 0,
  7. 0, 1, 0, 1, 0,
  8. 1, 1, 1, 1, 1,
  9. 0, 0, 0, 0, 0,
  10. ],
  11. [
  12. 0, 0, 0, 0, 0,
  13. 0, 1, 1, 1, 0,
  14. 0, 1, 0, 1, 0,
  15. 0, 1, 1, 1, 0,
  16. 0, 0, 0, 0, 0,
  17. ],
  18. [
  19. 0, 0, 0, 0, 0,
  20. 0, 0, 1, 0, 0,
  21. 0, 1, 0, 1, 0,
  22. 0, 0, 1, 0, 0,
  23. 0, 0, 0, 0, 0,
  24. ],
  25. [
  26. 0, 0, 1, 0, 0,
  27. 0, 1, 0, 1, 0,
  28. 1, 0, 0, 0, 1,
  29. 0, 1, 0, 1, 0,
  30. 0, 0, 1, 0, 0,
  31. ]
  32. ])
  33.  
  34. y = np.array([
  35. np.array([[1, 0, 0, 0]]).T,
  36. np.array([[0, 1, 0, 0]]).T,
  37. np.array([[0, 0, 1, 0]]).T,
  38. np.array([[0, 0, 0, 1]]).T
  39. ])
  40.  
  41.  
  42. def sigmoid(x):
  43. return 1 / (1 + np.exp(-x))
  44.  
  45.  
  46. def study(tr_stroka):
  47. sin_ves = 2 * np.random.random((25, 1)) - 1
  48.  
  49. for i in range(10000):
  50. x1 = x
  51. y1 = sigmoid(np.dot(x1, sin_ves))
  52. error = tr_stroka - y1
  53. raspr = np.dot(x1.T, error * y1 * (1 - y1))
  54. sin_ves += raspr
  55. return sin_ves
  56.  
  57.  
  58. sin_ves = np.array([
  59. 2 * np.random.random((25, 1)) - 1,
  60. 2 * np.random.random((25, 1)) - 1,
  61. 2 * np.random.random((25, 1)) - 1,
  62. 2 * np.random.random((25, 1)) - 1
  63. ])
  64.  
  65. for i in range(4):
  66. sin_ves[i] = study(y[i])
  67.  
  68.  
  69. def check(x0):
  70. chance = 0
  71.  
  72. y0 = -1
  73. for i in range(4):
  74. proz = sigmoid(np.dot(x0, sin_ves[i]))
  75. if proz > chance:
  76. chance = proz
  77. y0 = i
  78. return y0
  79.  
  80.  
  81. new_x = np.array([
  82. [
  83. 0, 0, 0, 0, 0,
  84. 0, 0, 1, 0, 0,
  85. 0, 1, 0, 1, 0,
  86. 0, 0, 1, 1, 0,
  87. 0, 0, 0, 0, 0,
  88. ],
  89. [
  90. 0, 0, 0, 0, 0,
  91. 0, 1, 1, 1, 0,
  92. 0, 1, 0, 1, 0,
  93. 0, 1, 1, 1, 0,
  94. 0, 0, 0, 0, 0,
  95. ],
  96. [
  97. 0, 0, 1, 0, 0,
  98. 0, 1, 0, 1, 0,
  99. 1, 1, 0, 0, 1,
  100. 0, 1, 0, 1, 0,
  101. 0, 0, 1, 0, 0,
  102. ],
  103. [
  104. 0, 0, 0, 0, 0,
  105. 0, 0, 1, 0, 0,
  106. 0, 1, 0, 1, 1,
  107. 1, 1, 1, 1, 1,
  108. 0, 0, 0, 0, 0,
  109. ]
  110. ])
  111.  
  112.  
  113. def symbol(a):
  114. if a == 0:
  115. return '∆'
  116. if a == 1:
  117. return '□'
  118. if a == 2:
  119. return '0'
  120. if a == 3:
  121. return '◊'
  122.  
  123.  
  124. for i in range(4):
  125. print(i, 'RESULT=', symbol(check(new_x[i])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement