# Tensorflow : Sequence when writing tensorflow

1. Write input matrix 

  • It is basically x and y matrix (x = [1,2,3], y=[4,5,6])

2. Write placeholder 

  • Placeholder would be filled by matrix, so we gotta make x and y placeholder
  • x = tf.placeholder(tf.float32) <- make float type placeholder to get a value from matrix x

3. Write variables

  • Variables would be filled basically by random seed
  • So, we gotta make variables for weight(w) and b(bias)

4. Write hypothesis

  • It is differed from case by case
  • For example: hypothesis would be "x1*w1 + x2*w2 + .... + b"

5. Write cost function

  • Use 'tf.reduce_mean' function with calculation for cost function
  • It would be: cost = tf.reduce_mean(hypothesis - y)

6. Write optimizer

  • This sequence is written for learning rate 
  • Learning rate is important to get a minimum cost value with a short time
  • Use tf.train.GradientDescentOptimizer with learning rate
  • For example: optimizer = tf.train.GradientDescentOptimizer(learning_rate=x)
  • x is differed from case by case

7. Write training set

  • Users can minimize cost value with learning rate using this function
  • For example: train = optimizer.minimize(cost)

8. Initialize Session

  • Users should initialize Session while using Tensorflow
  • Simply use 'sess = tf.Session()'

9. Initialize Variables

  • Variables should be initialized before they are used
  • Initialization must be run by sess.run()
  • For example: sess.run(tf.global.variables_initializer())

10. Calculation

  • Generally, Calculating in Tensorflow is run by recursive function
  • for step in range('how many times user want'):
  • Using 'cost value', 'hypothesis value' and 'train value'
    • Users should substitute these values using sess.run also
    • In python, users can substitue multiple placeholders one time
    • For example: sess.run([cost, hypothesis, train], feed_dict={x1: matrix_x1, x2: matrix_x2 ... y: matrix_y})

댓글