import numpy as py
import tensorflow as tf
import matplotlib as plt

"""
Explanation: Steven's Note Book on Tensorflow
Tensorflow 本着建模和计算分开的原则:
1. Building the computational graph.
2. Running the computational graph.
下面先说说建立模型（graph）的过程
一般要include的库们
End of explanation
"""


W = tf.Variable([.3], dtype=tf.float32)
b = tf.Variable([-.3], dtype=tf.float32)
x = tf.placeholder(tf.float32)
linear_model = W * x + b

"""
Explanation: Variable: 一般是要被train的东西，初始化后就等着被程序更新
End of explanation
"""


a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a + b  # + provides a shortcut for tf.add(a, b)

"""
Explanation: Place Holder: 一般放实时进入的数据，以用来train model
End of explanation
"""


node1 = tf.constant(3.0, dtype=tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly

"""
Explanation: 除了variable和placeholder以外，还需要各种各样的node （常数，运算等）
constant Node:
End of explanation
"""


node3 = tf.add(node1, node2)
node4 = a + b

"""
Explanation: add Node:
End of explanation
"""


sess = tf.Session()
print(sess.run([node1, node2]))

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}))

"""
Explanation: 一切的grpth完成后，需要用session来执行graph以启动正式的运算
End of explanation
"""


init = tf.global_variables_initializer()
sess.run(init)

print(sess.run(linear_model, {x: [1, 2, 3, 4]}))

"""
Explanation: 对于定义的variable，需要进行初始化操作
End of explanation
"""


