from __future__ import print_function
import tensorflow as tf
import numpy as np
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

#
# t_x = np.floor(10 * np.random.random([5]),dtype=np.float32)
# print(t_x)
#
# t_y = t_x * 3.0 + 8.0
# print(t_y)
#
# node1 = tf.constant(3.0, dtype=tf.float32)
# node2 = tf.constant(4.0) # also tf.float32 implicitly
# print(node1, node2)
#
sess = tf.Session()
# print(sess.run([node1, node2]))
#
#
# node3 = tf.add(node1, node2)
# print("node3:", node3)
# print("sess.run(node3):", sess.run(node3))

# a = tf.placeholder(tf.float32)
# b = tf.placeholder(tf.float32)
# adder_node = a + b
# print(sess.run(adder_node, {a:3, b:4.5}))
# print(sess.run(adder_node, {a:[1,3], b: [2,4]}))
#
# add_and_triple = adder_node * 3
# print(sess.run(add_and_triple, {a: 3, b:4.5}))

# W = tf.Variable([.3], dtype=tf.float32)
# b = tf.Variable([-.3], dtype=tf.float32)
# x = tf.placeholder(tf.float32)
# linear_model = W*x + b
#
# init = tf.global_variables_initializer()
# sess.run(init)
#
# print(sess.run(linear_model, {x: [1,2,3,4]}))
#
# y = tf.placeholder(tf.float32)
# square_deltas = tf.square(linear_model - y)
# loss = tf.reduce_sum(square_deltas)
# print(sess.run(loss,{x: [1,2,3,4], y:[0,-1,-2,-3]}))
#
# fixW = tf.assign(W, [-1.0])
# fixb = tf.assign(b, [1.])
# sess.run([fixW, fixb])
#
# print(sess.run(loss,{x: [1,2,3,4], y:[0,-1,-2,-3]}))
#
#
# optimizer = tf.train.GradientDescentOptimizer(0.01)
# train = optimizer.minimize(loss)
#
# sess.run(init) # reset values to incorrect defaults
# for i in range(1000):
#     sess.run(train, {x:[1,2,3,4], y:[0,-1,-2,-3]})
#
# print(sess.run([W,b]))


"""initialize parameters"""
W = tf.Variable([0.3], dtype = tf.float32)
b = tf.Variable([-0.3], dtype = tf.float32)
x = tf.placeholder(tf.float32)

linear_model = W*x + b

y = tf.placeholder(tf.float32)

loss = tf.reduce_sum(tf.square(linear_model - y))
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)

trainingX = [1.0,2.0,3.0,4.0]
trainingY = [0.0,-1.0,-2.0,-3.0]
# training loop
init = tf.global_variables_initializer()
sess.run(init) # reset values to wrong
for i in range(1000):
    sess.run(train, {x: trainingX, y: trainingY})

print(sess.run([W,b]))
print(sess.run(loss,{ x: trainingX, y: trainingY}))

"""Multi parameter















"""end of file"""
