def benchmark_text_messages_hmc(<EOL>num_results=int(<NUM_LIT>),<EOL>num_burnin_steps=int(<NUM_LIT>),<EOL>num_leapfrog_steps=<NUM_LIT:3>):
if not tf.executing_eagerly():<EOL><INDENT>tf.compat.v1.reset_default_graph()<EOL><DEDENT>count_data = tf.cast(<EOL>tf.concat(<EOL>[tfd.Poisson(rate=<NUM_LIT>).sample(<NUM_LIT>),<EOL>tfd.Poisson(rate=<NUM_LIT>).sample(<NUM_LIT>)],<EOL>axis=<NUM_LIT:0>),<EOL>dtype=tf.float32)<EOL>if tf.executing_eagerly():<EOL><INDENT>count_data = count_data.numpy()<EOL><DEDENT>else:<EOL><INDENT>with tf.compat.v1.Session():<EOL><INDENT>count_data = count_data.eval()<EOL><DEDENT><DEDENT>def unnormalized_log_posterior(lambda1, lambda2, tau):<EOL><INDENT>return text_messages_joint_log_prob(count_data, lambda1, lambda2, tau)<EOL><DEDENT>if tf.executing_eagerly():<EOL><INDENT>sample_chain = tf.function(tfp.mcmc.sample_chain)<EOL><DEDENT>else:<EOL><INDENT>sample_chain = tfp.mcmc.sample_chain<EOL><DEDENT>step_size = tf.compat.v2.Variable(<EOL>name='<STR_LIT>',<EOL>initial_value=tf.constant(<NUM_LIT>, dtype=tf.float32),<EOL>trainable=False)<EOL>def computation():<EOL><INDENT>"""<STR_LIT>"""<EOL>initial_chain_state = [<EOL>tf.constant(count_data.mean(), name='<STR_LIT>'),<EOL>tf.constant(count_data.mean(), name='<STR_LIT>'),<EOL>tf.constant(<NUM_LIT:0.5>, name='<STR_LIT>'),<EOL>]<EOL>unconstraining_bijectors = [<EOL>tfp.bijectors.Exp(),       <EOL>tfp.bijectors.Exp(),       <EOL>tfp.bijectors.Sigmoid(),   <EOL>]<EOL>_, kernel_results = sample_chain(<EOL>num_results=num_results,<EOL>num_burnin_steps=num_burnin_steps,<EOL>current_state=initial_chain_state,<EOL>kernel=tfp.mcmc.TransformedTransitionKernel(<EOL>inner_kernel=tfp.mcmc.HamiltonianMonteCarlo(<EOL>target_log_prob_fn=unnormalized_log_posterior,<EOL>num_leapfrog_steps=num_leapfrog_steps,<EOL>step_size=step_size,<EOL>step_size_update_fn=<EOL>tfp.mcmc.make_simple_step_size_update_policy(num_burnin_steps),<EOL>state_gradients_are_stopped=True),<EOL>bijector=unconstraining_bijectors))<EOL>return kernel_results.inner_results.is_accepted<EOL><DEDENT>is_accepted_tensor = computation()<EOL>if not tf.executing_eagerly():<EOL><INDENT>session = tf.compat.v1.Session()<EOL>session.run(tf.compat.v1.global_variables_initializer())<EOL>session.run(is_accepted_tensor)<EOL><DEDENT>start_time = time.time()<EOL>if tf.executing_eagerly():<EOL><INDENT>is_accepted = computation()<EOL><DEDENT>else:<EOL><INDENT>is_accepted = session.run(is_accepted_tensor)<EOL><DEDENT>wall_time = time.time() - start_time<EOL>num_accepted = np.sum(is_accepted)<EOL>acceptance_rate = np.float32(num_accepted) / np.float32(num_results)<EOL>return dict(<EOL>iters=(num_results + num_burnin_steps) * num_leapfrog_steps,<EOL>extras={'<STR_LIT>': acceptance_rate},<EOL>wall_time=wall_time)<EOL>
Runs HMC on the text-messages unnormalized posterior.