tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.22k stars 1.09k forks source link

variational_posteriors.log_prob error for run_smc_ in SMC Demo file #1652

Open 55Santoz opened 1 year ago

55Santoz commented 1 year ago

Hello, I ran SMC Demo and when I ran "runsmc()", the error below occured

""" 94 95 def _tempered_target_log_prob(args): --> 96 priorlogprob = tf.identity(prior_log_prob_fn(args), 97 name='prior_log_prob') 98 loglike = tf.identity(likelihood_log_prob_fn(*args),

TypeError: in user code:

File "<ipython-input-61-86b08bf263c9>", line 3, in run_smc_  *
    (
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/experimental/mcmc/sample_sequential_monte_carlo.py", line 387, in sample_sequential_monte_carlo  **
    pkr = kernel.bootstrap_results(current_state)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/mcmc/transformed_kernel.py", line 493, in bootstrap_results
    transformed_init_state))
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/mcmc/hmc.py", line 561, in bootstrap_results
    kernel_results = self._impl.bootstrap_results(init_state)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/mcmc/metropolis_hastings.py", line 273, in bootstrap_results
    pkr = self.inner_kernel.bootstrap_results(init_state)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/mcmc/hmc.py", line 775, in bootstrap_results
    ] = mcmc_util.maybe_call_fn_and_grads(self.target_log_prob_fn, init_state)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/mcmc/internal/util.py", line 297, in maybe_call_fn_and_grads
    result, grads = _value_and_gradients(fn, fn_arg_list, result, grads)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/mcmc/internal/util.py", line 265, in _value_and_gradients
    return tfp_math_value_and_gradients(fn, fn_arg_list)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/math/gradient.py", line 117, in value_and_gradient
    **kwargs)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/math/gradient.py", line 380, in _value_and_grad_impl
    output_gradients)
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/math/gradient.py", line 330, in _gradient_old
    y, aux = f()
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/math/gradient.py", line 378, in <lambda>
    y, dydx, aux = grad_fn(lambda: f(*args, **kwargs) if _has_args(f) else f(),
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/math/gradient.py", line 376, in <lambda>
    if _has_args(real_f) else real_f(), ())
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/mcmc/transformed_kernel.py", line 123, in transformed_log_prob_fn
    tlp = log_prob_fn(*fn(state_parts))
File "/usr/local/lib/python3.7/dist-packages/tensorflow_probability/python/experimental/mcmc/sample_sequential_monte_carlo.py", line 96, in _tempered_target_log_prob
    priorlogprob = tf.identity(prior_log_prob_fn(*args),

TypeError: log_prob() takes from 2 to 3 positional arguments but 5 were given

"""

Any ideas about the error and how to fix it?

ADITYADAS1999 commented 1 year ago

hi 55Santoz try to add this one I run successfully with this one.

@tf.function(experimental_compile=True) def run_smc(): ( n_stage, final_state, final_kernel_results ) = sample_sequential_monte_carlo_chain( prior_log_prob_fn, likelihood_log_prob_fn, init_state, make_kernel_fn=_make_transform_hmc_kernel_fn, tuning_fn=simple_heuristic_tuning_hmc, max_num_steps=50 ) return n_stage, final_state, final_kernel_results

n_stage, final_state, final_kernel_results = run_smc()

newcode