First try to solve polynomial equations y=3x^2+2x-5 using Tensorflow
Output with 100000 looptimes:
A: [ 2.99184537] B: [ 2.0156281] C: [-5.00763798] D: [ 2.00114322] loss: 4.62821e-07
from __future__ import print_function
import tensorflow as tf
sess = tf.Session();
#Model ParametersA = tf.Variable([1.], dtype=tf.float32)
B = tf.Variable([1.], dtype=tf.float32)
C = tf.Variable([-1.], dtype=tf.float32)
D = tf.Variable([1.], dtype=tf.float32)
#Model Input and Outputx = tf.placeholder(tf.float32)
y = tf.placeholder(tf.float32)
unknown_model = A * x ** D + B * x + C
#Lossloss = tf.reduce_sum(tf.square(unknown_model - y))
#Optimizeroptimizer = tf.train.AdamOptimizer(0.01)
train = optimizer.minimize(loss)
#Training Datax_train = [1,2,3,4]
y_train = [0,11,28,51]
#Training Loopinit = tf.global_variables_initializer()
sess.run(init)
for i in range(100000):
sess.run(train, {x:x_train, y:y_train})
#evaluate training accuracycurr_A, curr_B, curr_C, curr_D, curr_loss = sess.run([A, B, C, D, loss], {x: x_train, y: y_train})
print("A: %s B: %s C: %s D: %s loss: %s"%(curr_A, curr_B, curr_C, curr_D, curr_loss))