In [1]:
import tensorflow as tf
import matplotlib.pyplot as plt
In [2]:
%matplotlib inline
In [3]:
interactive_session=tf.InteractiveSession()
In [4]:
global_steps=tf.Variable(0)
In [5]:
learning_rate=tf.train.exponential_decay(0.1,global_steps,100,0.96,staircase=False)
In [6]:
x=tf.constant([[3.0,4.0]])
In [7]:
w=tf.Variable([[1.1],[2.0]])
In [8]:
y_=tf.matmul(x,w)
In [9]:
y=tf.constant([[20.0]])
In [10]:
loss=tf.abs(tf.reduce_mean(y-y_))
In [11]:
learning_step=tf.train.GradientDescentOptimizer(learning_rate).minimize(loss,global_step=global_steps)
In [12]:
init_op=tf.initialize_all_variables()
In [13]:
interactive_session.run(init_op)
In [14]:
x_plot=[]
y_plot=[]
In [15]:
for i in range(1000):
interactive_session.run(learning_step)
realtime_learning_rate=interactive_session.run(learning_rate)
x_plot.append(i)
y_plot.append(realtime_learning_rate)
In [16]:
plt.scatter(x_plot,y_plot)
Out[16]:
In [ ]: