network.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from matplotlib import pyplot as plt
  2. WEIGTHS = [
  3. [ # L1
  4. [0.7095146, -0.4351325, 0.38553882, 0.84955347, -0.8693629, 0.1586302, -0.16126093, 0.09219088],
  5. [-0.41895103, 1.0214638, -1.0607314, 0.32464203, 0.8418823, 0.01737848, 0.5317601, -0.624525],
  6. [-0.08075078, 0.14494987, 0.01327306, 0.8879888, 0.60206324, 0.75329006, 0.34316933, -0.61903083],
  7. [-0.5218736, -0.78134096, -0.28972188, 0.00756884, -0.78290594, -0.57819647, -0.7074082, -0.87057704],
  8. ],
  9. [ # L2
  10. [0.36770403, -0.17659009, -0.04314173, -0.46864474, -0.37941265, -0.78606385, 0.11138931, 0.23097174],
  11. [-0.78046024, 0.13901198, 0.14361085, 0.36618456, 0.45330787, 0.24032554, 0.48950365, 0.30290592],
  12. [0.3979908, -0.45248222, 0.6259473, -0.45595396, -0.12066315, -0.4472755, 0.12998834, -0.596446],
  13. [0.5494289, -0.7894139, 0.3571782, -0.39789405, 0.5636705, -0.24661142, 0.4947537, -0.40108407],
  14. [-0.13859335, -0.81092286, -0.38011226, 0.73964316, 0.68990386, -0.2698564, 0.516593, 0.12246455],
  15. [0.40053025, -0.521815, 0.01378736, -0.30294785, 0.6543718, -0.8365823, 0.82281274, -0.47260976],
  16. [0.08249452, 0.30632392, 0.05794358, 0.2482118, 0.86367106, -0.13674814, 0.04789656, -0.55030185],
  17. [-0.32528356, -0.3143816, 0.09667788, -0.2127953, -0.5707757, -0.39799848, 0.30206403, 0.44481543]
  18. ],
  19. [ # L3
  20. [0.5724262, 0.30391088],
  21. [0.5853241, -0.92324615],
  22. [0.3748752, 0.8088594],
  23. [-0.892384, -1.0522624],
  24. [-1.0270239, 0.07374455],
  25. [0.2170913, -0.550893],
  26. [-0.07271451, 0.8194236],
  27. [0.14661156, -0.62796086]
  28. ]
  29. ]
  30. BIAS = [
  31. # L1
  32. [0.01425434, -0.06219335, -0.0201127, -0.04791382, -0.04360008, -0.05311861, -0.01731363, -0.00014839],
  33. # L2
  34. [0.03480967, 0.06208326, -0.01576317, -0.00037753, -0.03940378, 0.05157978, -0.02775403, 0.04540931],
  35. # L3
  36. [0.03787775, -0.03655371],
  37. ]
  38. def relu(x):
  39. return x if x > 0 else 0
  40. def sigm(x):
  41. ex = 2.7182818 ** x
  42. return ex / (ex + 1)
  43. def linr(x):
  44. return x
  45. def process(value):
  46. if value > 3 or value < 0:
  47. raise ValueError("Value not in between 0 and 3")
  48. onehot_mat = [
  49. [0, 0, 0, 1],
  50. [0, 0, 1, 0],
  51. [0, 1, 0, 0],
  52. [1, 0, 0, 0],
  53. ]
  54. L0 = onehot_mat[value]
  55. L1 = [linr(sum([L0[j] * WEIGTHS[0][j][i] for j in range(len(L0))]) + BIAS[0][i]) for i in range(8)]
  56. L2 = [linr(sum([L1[j] * WEIGTHS[1][j][i] for j in range(len(L1))]) + BIAS[1][i]) for i in range(8)]
  57. L3 = [sigm(sum([L2[j] * WEIGTHS[2][j][i] for j in range(len(L2))]) + BIAS[2][i]) for i in range(2)]
  58. return L3
  59. if __name__ == '__main__':
  60. plt.plot(*process(0), 'x')
  61. plt.plot(*process(1), 'x')
  62. plt.plot(*process(2), 'x')
  63. plt.plot(*process(3), 'x')
  64. plt.xlabel('Real')
  65. plt.ylabel('Imaginary')
  66. plt.xlim([0, 1])
  67. plt.ylim([0, 1])
  68. plt.grid()
  69. plt.show()