E.g. early stopping for iterative training with stochastic gradient descent (SGD)
Tensorflow very basics
MNIST logistic regression example
importtensorflowastfx_var=tf.Variable(2.0,'x')# Variables with initialied values
y_var=tf.Variable(3.0,'y')# typically used for learnable parameteters of models.
z_var=tf.mul(x_var,y_var)# Variable representing result of the operation
a_var=tf.placeholder("float")# Similar as variable but representing values feed as input.
b_var=tf.placeholder("float")# See feed_dict below how the input values can be changed.
c_var=tf.add(a_var,b_var)# Operation works on top of both Variables and Placeholders.
d_var=tf.add(x_var,a_var)init=tf.initialize_all_variables()withtf.Session()assess:sess.run(init)# Set the variables to its initial value
print(sess.run(x_var),'Default value x')print(sess.run(y_var),'Default value y')print(sess.run(z_var),'Computed value z')print(sess.run(c_var,feed_dict={a_var:-5.0,b_var:2.0}),'Computed value c1')print(sess.run(c_var,feed_dict={a_var:-3.0,b_var:2.0}),'Computed value c2')print(sess.run(x_var,feed_dict={a_var:-5.0}),'Computed value x')
# Writing variables to files instead of printing to stdout
json.dump(sess.run(mylist_variable).tolist(),open('mylist.log','w'))