Issue
I'm following book on Tensorflow by Chris Mattman.
Here is the code:
import tensorflow as tf
tf.disable_v1_behavior()
def model(X, w):
terms = []
for i in range(num_coeffs): #num_coeffs = 6
term = tf.multiply(w[i], tf.pow(X, i))
terms.append(term)
return tf.add_n(terms)
w = tf.Variable([0.]*num_coeffs, name="parameters")
y_model = model(X, w) #X = tf.placeholder(tf.float32)
How do we multiply 0. by some value in the variable and get anything different from 0? It is to be polynomial regression model.
Solution
The parameter [0.]*num_coefs
is the initial value of the tensorflow variable represented by w
. Of course, when all coefficients are zero, the result of multiplying by those coefficients is zero.
Th point of performing optimization with respect to some distance or loss metric (e.g. minimizing mean squared error) is that the variable will be updated to nonzero values that optimize the metric subject to the input and output data. Your code does not yet include an optimizer, so the variable won't be updated. Adding an optimizer will lead to the variable being updated to a nonzero vector, following some strategy depending on the selected optimizer.
Answered By - nanofarad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.