From ed48958a5680de8509af00a0526d0603e7a68822 Mon Sep 17 00:00:00 2001 From: hsm207 Date: Mon, 6 May 2019 05:25:43 +0800 Subject: [PATCH 1/3] Fix deprecation warning to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead. --- Chapter1_Introduction/Ch1_Introduction_TFP.ipynb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb b/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb index daaa24ea..4f9b92a2 100644 --- a/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb +++ b/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb @@ -395,8 +395,8 @@ "cumulative_headcounts = tf.gather(tf.cumsum(coin_flip_data), num_trials)\n", "\n", "rv_observed_heads = tfp.distributions.Beta(\n", - " concentration1=tf.to_float(1 + cumulative_headcounts),\n", - " concentration0=tf.to_float(1 + num_trials - cumulative_headcounts))\n", + " concentration1=tf.cast(1 + cumulative_headcounts, tf.float32),\n", + " concentration0=tf.cast(1 + num_trials - cumulative_headcounts, tf.float32))\n", "\n", "probs_of_heads = tf.linspace(start=0., stop=1., num=100, name=\"linspace\")\n", "observed_probs_heads = tf.transpose(rv_observed_heads.prob(probs_of_heads[:, tf.newaxis]))" @@ -1207,8 +1207,8 @@ "source": [ "# Set the chain's start state.\n", "initial_chain_state = [\n", - " tf.to_float(tf.reduce_mean(count_data)) * tf.ones([], dtype=tf.float32, name=\"init_lambda1\"),\n", - " tf.to_float(tf.reduce_mean(count_data)) * tf.ones([], dtype=tf.float32, name=\"init_lambda2\"),\n", + " tf.cast(tf.reduce_mean(count_data)) * tf.ones([], dtype=tf.float32, name=\"init_lambda1\", tf.float32),\n", + " tf.cast(tf.reduce_mean(count_data)) * tf.ones([], dtype=tf.float32, name=\"init_lambda2\", tf.float32),\n", " 0.5 * tf.ones([], dtype=tf.float32, name=\"init_tau\"),\n", "]\n", "\n", @@ -1234,7 +1234,7 @@ "\n", " lambda_ = tf.gather(\n", " [lambda_1, lambda_2],\n", - " indices=tf.to_int32(tau * tf.to_float(tf.size(count_data)) <= tf.to_float(tf.range(tf.size(count_data)))))\n", + " indices=tf.to_int32(tau * tf.cast(tf.size(count_data), tf.float32) <= tf.cast(tf.range(tf.size(count_data)))), tf.float32)\n", " rv_observation = tfd.Poisson(rate=lambda_)\n", " \n", " return (\n", @@ -1277,7 +1277,7 @@ " state_gradients_are_stopped=True),\n", " bijector=unconstraining_bijectors))\n", "\n", - "tau_samples = tf.floor(posterior_tau * tf.to_float(tf.size(count_data)))\n", + "tau_samples = tf.floor(posterior_tau * tf.cast(tf.size(count_data)), tf.float32)\n", "\n", "# tau_samples, lambda_1_samples, lambda_2_samples contain\n", "# N samples from the corresponding posterior distribution\n", @@ -1644,4 +1644,4 @@ ] } ] -} \ No newline at end of file +} From 72ee2214fa30e217e7c18bba3bf49474d2491787 Mon Sep 17 00:00:00 2001 From: hsm207 Date: Mon, 6 May 2019 05:36:03 +0800 Subject: [PATCH 2/3] Fix typo --- Chapter1_Introduction/Ch1_Introduction_TFP.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb b/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb index 4f9b92a2..f000af4e 100644 --- a/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb +++ b/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb @@ -1234,7 +1234,7 @@ "\n", " lambda_ = tf.gather(\n", " [lambda_1, lambda_2],\n", - " indices=tf.to_int32(tau * tf.cast(tf.size(count_data), tf.float32) <= tf.cast(tf.range(tf.size(count_data)))), tf.float32)\n", + " indices=tf.to_int32(tau * tf.cast(tf.size(count_data), tf.float32) <= tf.cast(tf.range(tf.size(count_data)), tf.float32)))\n", " rv_observation = tfd.Poisson(rate=lambda_)\n", " \n", " return (\n", From 49c55d6676bf914b9761f863a74b853dfe96641d Mon Sep 17 00:00:00 2001 From: hsm207 Date: Mon, 6 May 2019 05:44:10 +0800 Subject: [PATCH 3/3] Fix typo --- Chapter1_Introduction/Ch1_Introduction_TFP.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb b/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb index f000af4e..07aede9a 100644 --- a/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb +++ b/Chapter1_Introduction/Ch1_Introduction_TFP.ipynb @@ -1207,8 +1207,8 @@ "source": [ "# Set the chain's start state.\n", "initial_chain_state = [\n", - " tf.cast(tf.reduce_mean(count_data)) * tf.ones([], dtype=tf.float32, name=\"init_lambda1\", tf.float32),\n", - " tf.cast(tf.reduce_mean(count_data)) * tf.ones([], dtype=tf.float32, name=\"init_lambda2\", tf.float32),\n", + " tf.cast(tf.reduce_mean(count_data), tf.float32) * tf.ones([], dtype=tf.float32, name=\"init_lambda1\"),\n", + " tf.cast(tf.reduce_mean(count_data), tf.float32) * tf.ones([], dtype=tf.float32, name=\"init_lambda2\", tf.float32),\n", " 0.5 * tf.ones([], dtype=tf.float32, name=\"init_tau\"),\n", "]\n", "\n",