0

I just learnt about tensorflow. To be more familiar with the syntax, I build a toy model to perform polynomial regression.

The toy dataset that I created is

x_data = np.linspace(-1, 1, 300) + np.random.uniform(-0.05, 0.05, 300)
y_data = np.linspace(-1, 1, 300) ** 2 + np.random.uniform(-0.05, 0.05, 300)

The model that I built is

batch_size = 20
x = tf.placeholder(tf.float64, [1, batch_size])
y = tf.placeholder(tf.float64, [1, batch_size]) 
a0 = tf.Variable(np.random.rand(1))
a1 = tf.Variable(np.random.rand(1))
a2 = tf.Variable(np.random.rand(1))
a3 = tf.Variable(np.random.rand(1))
a4 = tf.Variable(np.random.rand(1))
a5 = tf.Variable(np.random.rand(1))
a6 = tf.Variable(np.random.rand(1))
op = a6 * x ** 6 + a5 * x ** 5 + a4 * x ** 4 + a3 * x ** 3 + a2 * x ** 2 + a1 * x ** 1 + a0
error = tf.reduce_sum(tf.square(op - y))

init = tf.global_variables_initializer()
optimizer = tf.train.GradientDescentOptimizer(0.0001)
train = optimizer.minimize(error)
sess = tf.Session()

steps = 100000
sess.run(init)

for i in range(steps):

    rand_int = np.random.randint(0, 300, batch_size)
    x_temp = x_data[rand_int].reshape(1, batch_size)
    y_temp = y_data[rand_int].reshape(1, batch_size)
    feed = {x: x_temp, y: y_temp}
    sess.run(train, feed)
a0, a1, a2, a3, a4, a5, a6= sess.run([a0, a1, a2, a3, a4, a5, a6])

However, after I run the model, the result that I got is:

[a0, a1, a2, a3, a4, a5, a6] = [array([ nan]), array([ nan]), array([ nan]), array([ nan]), array([ nan]), array([ nan]), array([ nan])]

Why did the model learn nothing? I've changed the learning rate to a magnitude smaller, yet the outcome is still the same.

meTchaikovsky
  • 7,478
  • 2
  • 15
  • 34
  • am not getting nans! `[array([ 0.01168764]), array([ 0.020555]), array([ 0.78541259]), array([-0.11046838]), array([ 0.56289744]), array([ 0.11454655]), array([-0.39754509])]` – skrubber Jul 24 '18 at 17:15
  • @ skrubber Do you know what can be a possible reason? – meTchaikovsky Jul 25 '18 at 00:09

0 Answers0