SHARE
TWEET

Untitled

a guest Dec 12th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2.  
  3. ITERS = 1000
  4.  
  5. # pierwsza warstwa
  6. w1 = tf.Variable(tf.ones([1, 1]))
  7. b1 = tf.Variable(tf.ones([1]))
  8.  
  9. # druga warstwa
  10. w2 = tf.Variable(tf.ones([1, 2]))
  11. b2 = tf.Variable(tf.ones([2]))
  12.  
  13. # trzecia warstwa
  14. w3 = tf.Variable(tf.ones([2, 1]))
  15. b3 = tf.Variable(tf.ones([1]))
  16.  
  17. mu = 0.001  # learning speed
  18. for i in range(ITERS):
  19.     x = tf.random.uniform([16, 1], 0, math.pi * 2)  # dane wejściowe
  20.     y_hat = tf.math.sin(x)                          # dane uczące (ground truth)
  21.  
  22.     # propagacja wejścia sieci
  23.     z1 = x @ w1 + b1
  24.     y1 = tf.nn.sigmoid(z1)
  25.    
  26.     z2 = y1 @ w2 + b2
  27.     y2 = tf.nn.sigmoid(z2)
  28.    
  29.     z3 = y2 @ w3 + b3
  30.     y3 = z3
  31.    
  32.     if i%100==0:
  33.         print(loss(y_hat, y3))
  34.    
  35.     d3 = y_hat-y3  
  36.     d2 = d3 @ tf.transpose(w3)
  37.     d1 = d2 @ tf.transpose(w2)
  38.    
  39.     w1 = w1 + sum(mu*d1*d_sigmoid(z1)*x)
  40.     w2 = w2 + sum(mu*d2*d_sigmoid(z2)*y1)
  41.     w3 = w3 + sum(mu*d3*d_sigmoid(z3)*y2)
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top