I'm trying to perform exact GP regression using the TF2.0 eager mode, based on the original graph based example from https://colab.research.google.com/github/tensorflow/probability/blob/master/tensorflow_probability/examples/jupyter_notebooks/Gaussian_Process_Regression_In_TFP.ipynb
amplitude = (
np.finfo(np.float64).tiny +
tf.nn.softplus(tf.Variable(initial_value=1., name='amplitude', dtype=np.float64))
)
length_scale = (
np.finfo(np.float64).tiny +
tf.nn.softplus(tf.Variable(initial_value=1., name='length_scale', dtype=np.float64))
)
observation_noise_variance = (
np.finfo(np.float64).tiny +
tf.nn.softplus(tf.Variable(initial_value=1e-6,
name='observation_noise_variance',
dtype=np.float64))
)
kernel = tfk.ExponentiatedQuadratic(amplitude, length_scale)
gp = tfd.GaussianProcess(
kernel=kernel,
index_points=tf.expand_dims(x, 1),
observation_noise_variance=observation_noise_variance
)
neg_log_likelihood = lambda: -gp.log_prob(y)
optimizer = tf.optimizers.Adam(learning_rate=.01)
num_iters = 1000
lls_ = np.zeros(num_iters, np.float64)
for i in range(num_iters):
lls_[i] = neg_log_likelihood()
optimizer.minimize(neg_log_likelihood, var_list=[amplitude, length_scale, observation_noise_variance])
However optimization fails with:
'tensorflow.python.framework.ops.EagerTensor' object has no attribute '_in_graph_mode'
And if I move the amplitude, length_scale and observation_noise_variance each to tf.Variable, like:
amplitude = tf.Variable(initial_value=1., name='amplitude', dtype=np.float64)
amplitude_ = (
np.finfo(np.float64).tiny +
tf.nn.softplus(amplitude)
)
Optimization fails with:
ValueError: No gradients provided for any variable: ['amplitude:0', 'length_scale:0', 'observation_noise_variance:0'].
What am I doing wrong?
--
You received this message because you are subscribed to the Google Groups "TensorFlow Probability" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfprobabilit...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfprobability/88817062-29a5-4ee8-a6cf-5e89f7b5cd46%40tensorflow.org.
--
You received this message because you are subscribed to the Google Groups "TensorFlow Probability" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfprobabilit...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfprobability/43109d42-2c10-4167-b6e6-dc076f32c848%40tensorflow.org.