SHARE
TWEET

Untitled

a guest Jan 29th, 2020 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. err = np.array([])
  3. print (err)
  4.  
  5. def sigm(x):
  6.     return (1 / (np.exp(-x) + 1))
  7.    
  8. train_in = np.array ([ [1, 0, 1, 0],
  9.                                     [1, 1, 1, 1],
  10.                                     [0, 0, 0, 0],
  11.                                     [1, 1, 1, 1],
  12.                                     [0, 1, 0, 1],
  13.                                     [0, 0, 0, 1],
  14.                                     [0, 1, 0, 0],
  15.                                     [1, 0, 0, 1],
  16.                                     [1, 0, 0, 1] ])
  17.                                    
  18. train_out = np.array ([1, 1, 0, 1, 0, 0, 0, 1, 1])
  19.  
  20. np.random.seed(1)
  21. weight = 2 * np.random.random((4, 1)) - 1
  22. #print(weight)
  23.  
  24. for i in range (20000):
  25.     input = train_in
  26.     output = sigm(np.dot(input,  weight))
  27.     print("out ", output)
  28.    
  29.     for a in output.shape:
  30.     #  
  31.         err = np.add(train_out[a] - output[a])
  32.         print(err)
  33.    
  34.     d_weight = np.dot(train_in.T, err * (output * (1- output)))
  35.     print("weight ", d_weight)
  36.     weight += d_weight
  37.    
  38. #print(output)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top