-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.py
More file actions
45 lines (28 loc) · 881 Bytes
/
Copy pathtest1.py
File metadata and controls
45 lines (28 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#usr/bin/python3.5
#author=BuleCat
import tensorflow as tf
import numpy as np
x = tf.placeholder("float",shape=[None,1])
W = tf.Variable(tf.zeros([1,1]))
b = tf.Variable(tf.zeros([1]))
y = tf.matmul(x,W) +b
y_ = tf.placeholder("float",[None,1])
cost = tf.reduce_sum(tf.pow((y_-y),2))
train_step = tf.train.GradientDescentOptimizer(0.001).minimize(cost)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
All_x = np.empty(shape=[1,1])
All_y = np.empty(shape=[1,1])
for i in range(1000):
x_s = np.random.rand(1,1)
y_s = np.dot([[0.33]],np.random.rand(1,1)) + 0.33
feed = {x: x_s, y_: y_s}
sess.run(train_step,feed_dict=feed)
print("After %d iteration:"%i)
print("W : %f"%sess.run(W))
print("b : %f"%sess.run(b))
All_x = np.concatenate((All_x,x_s))
All_y = np.concatenate((All_y,y_s))
print(All_x)
print(All_y)