# x2sinxeqn_regression_01.py
import tensorflow as tf
x_train = [-2.0, -0.7, 0.4, 2.0]
y_train = [-0.0059696,0.2037, 0-.05437, 0.0059696]
W1 = tf.Variable(tf.random_uniform([1],-2.0, -1.8, 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], 1.8, +2.0, dtype = tf.float32, name='weight3'))
hypothesis = (x_train-2*tf.sin(x_train) - W1 +2*tf.sin(W1))*(x_train-2*tf.sin(x_train) - W2+2*tf.sin(W2))*(x_train-2*tf.sin(x_train) - W3 +2*tf.sin(W3))
cost = tf.reduce_mean(tf.square(hypothesis - y_train))
optimizer = tf.train.GradientDescentOptimizer(learning_rate=4.0)
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))
'머신러닝' 카테고리의 다른 글
계산기에서 역수 계산법 TensorFlow 수치해석 파이선 코드 (0) | 2018.11.25 |
---|---|
x**(1/3)=0 TensorFlow 수치해 파이선 코드 (0) | 2018.11.25 |
sin(x) = 0 TensorFlow 수치 해 (0) | 2018.11.25 |
3차방정식의 근 구하기 텐서플로우 파이선 코드 (0) | 2018.11.25 |
머신러닝 TensorFlow 응용 2차 방정식의 중근 구하기 (0) | 2018.11.25 |