sin(x) = 0 TensorFlow 수치 해

댓글 3

머신러닝

2018. 11. 25.

 

# sinxeqn_regression_01.py

import tensorflow as tf

x_train = [-2.0, -0.7, 0.4, 2.0]
y_train = [-0.7518,-0.2674, 0.05905, 0.7518]

W1 = tf.Variable(tf.random_uniform([1],-3.2, -3.0, dtype = tf.float32, name='weight1'))
W2 = tf.Variable(tf.random_uniform([1],-0.5, +0.5, dtype = tf.float32, name='weight2'))
W3 = tf.Variable(tf.random_uniform([1], 3.0, 3.2, dtype = tf.float32, name='weight3'))

hypothesis = (tf.sin(x_train) - tf.sin(W1))*(tf.sin(x_train) - tf.sin(W2))*(tf.sin(x_train) - tf.sin(W3))

cost = tf.reduce_mean(tf.square(hypothesis - y_train))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.6)
train = optimizer.minimize(cost)

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


for step in range(5001):
    sess.run(train)
    if step % 1000 == 0:
        print(step, sess.run(cost), sess.run(W1), sess.run(W2), sess.run(W3))