-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFitting_example.py
More file actions
31 lines (25 loc) · 836 Bytes
/
Copy pathFitting_example.py
File metadata and controls
31 lines (25 loc) · 836 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
# Bulid a sample of fitting graph
# almost all data's type in tensorflow is float32
from __future__ import print_function
import tensorflow as tf
import numpy as np
## Set up the data and structure
# Create data
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data*0.1 + 0.3
# Create tensorflow structure start
Weights = tf.Varible(tf.random_uniform([1], -1.0, 1.0))
biases = tf.Varible(tf.zeros([1]))
y = Weights * x_data + biases
learning_rate = 0.1
loss = tf.reduce_mean(tf.square(y-y_data))
optimizr = tf.train.GradientDescentOptimizer(learning_rate)
train = optimizer.minimize(loss)
## Set up the computational structure
inti = tf.initialize_all_variables()
sess = tf.Session
see.run(init)
for step in range(200):
see.run(train)
if step % 20 == 0:
print(step, sess.run(Weights), sess.run(biases))