tf.get_default_graph()

graph = tf.Graph()

graph

tf.get_default_graph()

"""
Explanation: Graphs
End of explanation
"""


x1 = tf.Variable(3.0, name='x')
y1 = tf.Variable(4.0)

x1, y1

x1.name, y1.name

x1.graph is tf.get_default_graph()

y1.graph is tf.get_default_graph()

with graph.as_default():
    x2 = tf.Variable(4.1, name='x2')

x2.graph is tf.get_default_graph()

x2.graph is graph

f1 = 2*x1 + y1

"""
Explanation: Variables
End of explanation
"""


f1

"""
Explanation: lazy evaluation
End of explanation
"""


f2 = 2*x2 + y1

"""
Explanation: This is what happens when we operate on two variables that are from different graphs
End of explanation
"""


with tf.Session() as sess:
    x1.initializer.run()
    y1.initializer.run()
    f1_value = f1.eval()
print("f1: {}".format(f1_value))

"""
Explanation: Variable initialization

all tf.Variables need to be initalized
tf.constant need NOT to be initialized

Initialization options
Manual initialization
~~~~
x1.initializer.run()
~~~~
~~~~
sess.run(x.initializer)
~~~~
Automatic initializer with tf.global_variables_initializer()
~~~~
init = tf.global_variables_initializer()
with tf.Session() as sess:
    init.run()
~~~~
End of explanation
"""


with tf.Session() as sess:
    x1.initializer.run()
    f1_value = f1.eval()
print("f1: {}".format(f1_value))

"""
Explanation: This is what happens if you forget to initialize the variable
End of explanation
"""


init = tf.global_variables_initializer()

with tf.Session() as sess:
    init.run()
    f1_value_with_global_variables_initializer = f1.eval()
print("f1_value_with_global_variables_initializer: {}".format(f1_value_with_global_variables_initializer))

"""
Explanation: Using tf.global_variables_initializer()
End of explanation
"""


w = tf.constant(3)
x = w + 2
y = x + 5
z = x * 3

x

with tf.Session() as sess:
    print(y.eval())
    print(z.eval())

x

"""
Explanation: Life cycle of a node value
End of explanation
"""


with tf.Session() as sess:
    y_val, z_val = sess.run([y,z])
    print(y_val)
    print(z_val)

"""
Explanation: A more efficient evaluation of the TensorFlow Graph
End of explanation
"""


