Guest User

Untitled

a guest
Apr 12th, 2017
748
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import numpy as np
  3. import tensorflow as tf
  4. from tensorflow.python.framework import ops
  5. import matplotlib.pyplot as plt
  6. %matplotlib inline
  7. ops.reset_default_graph()
  8. import tqdm
  9. sess =tf.Session()
  10.  
  11. x_ = tf.placeholder(name="input", shape=[None, 2], dtype=tf.float32)
  12. y_ = tf.placeholder(name= "output", shape=[None, 1], dtype=tf.float32)
  13.  
  14. hidden_neurons = 15
  15. w1 = tf.Variable(tf.random_uniform(shape=[2,hidden_neurons ]))
  16. b1 = tf.Variable(tf.constant(value=0.0, shape=[hidden_neurons ], dtype=tf.float32))
  17. layer1 = tf.nn.relu(tf.add(tf.matmul(x_, w1), b1))
  18.  
  19. w2 = tf.Variable(tf.random_uniform(shape=[hidden_neurons ,1]))
  20. b2 =  tf.Variable(tf.constant(value=0.0, shape=[1], dtype=tf.float32))
  21.  
  22. nn_output = tf.nn.relu(tf.add(tf.matmul(layer1, w2), b2))
  23. gd = tf.train.GradientDescentOptimizer(0.001)
  24. loss =  tf.reduce_mean(tf.square(nn_output- y_))
  25. train_step = gd.minimize(loss)
  26. init = tf.global_variables_initializer()
  27. sess.run(init)
  28. x = np.array([[0,0],[1,0],[0,1],[1,1]])
  29. y = np.array([[0],[1],[1],[0]])
  30. for _ in range(20000):
  31.     sess.run(train_step, feed_dict={x_:x, y_:y})
  32.    
  33. print(sess.run(nn_output, feed_dict={x_:x}))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×